Chapter 12 - Odoo 15 Development Book

Tour Test Cases

Odoo tours are a form of integration testing which can be used to check that both Python and Javascript work with each other properly.

To add a tour test case for a custom module, follow the below-mentioned steps;

  • 1. Create a tour by first registering it.
  • odoo.define('mobile_service_shop.mobile_tour', function(require) {
        	"use strict";
        	// Minimal requirements needed to create a tour
        	var core = require('web.core');
        	var tour = require('web_tour.tour');
        	// Allows you to translate tour steps
        	var _t = core._t;
        	tour.register('mobile_tour', {
            	url: "/web",
            	test: true,
            	skip_enabled : true,
        	},

    Below listed are some possible options that can be defined for a tour.

    i. url : the page from where the tour should start.

    ii. skip_enabled: add a skip button on the tip.

    iii. wait_for: wait for the deferred object before running the tour.

    iv. test: if this is set to true, then this tour will be used only for testing purposes.

    2. Add a required number of steps to the tour.

    [tour.stepUtils.showAppsMenuItem(), {
        trigger:   '.o_app[data-menu-xmlid="mobile_service_shop.mobile_service_main_menu"]',
        content: _t('Want to manage your services? It starts here.'),
        position: 'bottom',
        width: 300,
    },
    {
        trigger: '.o_list_button_add',
        extra_trigger: '.o_mobile_service',
        content: _t('Let\'s create your first service by clicking on create.'),
        position: 'bottom',
        },
        {
        	trigger: 'input[name="contact_no"]',
        	auto: true,
        	content: _t('Fill in the contact Number.'),
        	// When you run the test (from the developer tools) it will automatically fill in '1555555'.
        	run: function (actions) {
             	actions.text('155555');
        	},
        	position: 'right',
        	}
    	]);
    	});

Each step in the tour can have a set of arguments. Some possible arguments are;

  • i. trigger: selector/element/jQuery you want to trigger
  • ii. extra-trigger: option to make sure the step is on the screen.
  • iii. run: specifies what to do when the when tour runs automatically.
  • iv. edition: specify the edition in which the step needs to be run.
  • v. position: the position where the text and icon need to be displayed.
  • 3. Add tour.js file in manifest.

    'assets': {
    		'web.assets_backend': [
    			'/mobile_service_shop/static/src/js/tour.js'
    ]
             }

    4. To start a tour from the python test, make the class inherit from HTTPCase, and call start_tour:

    def test_mobile_tour(self):
       # Optional Setup
       self.start_tour("/web",      'mobile_service_shop.mobile_tour',  login="admin")

    5. To run the test case, start the server with the following option;

    ./odoo-bin -c odoo14.conf -i mobile_service_shop - - test - tags=mobile_service_shop

    6. If our test case ran successfully, the following log will be displayed

    …INFO test odoo.addons.mobile_service_shop.tests.mobile_tour.TestMobileTour:
    console log: Tour mobile_tour succeeded
whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message