Development Book V17: Tour Test Cases

While testing JavaScript and Python code independently is highly beneficial, it does not demonstrate the interoperability of the web client and server. We can develop tours, a different kind of test, to do this. Mini-scenarios of fascinating corporate procedures comprise tours. It outlines the steps that must be taken in that order. Next, in accordance with the scenario, the test runner starts a PhantomJs browser, points it to the appropriate URL, and mimics clicks and inputs.

The procedures listed below can be used to add a tour test case for a custom module:

                Your module
                |
                |-----static
                |       |
                |       |-----tests
                |              |
                |              |-----tours
                |                       |
                |                       |your_tours.js
                |
                |-------tests
                            |
                            |----init.py
                            |
                            |----test_calling_the_tour.js 
                |
                |--------manifest.py
                
                

1. Register for your tour to start it off.

import { _t } from 'web.core';
import { Markup } from 'web.utils';
import tour from 'web_tour.tour';
tour.register('student_tour', {
    url: "/web",
	test:true,
	});

Here are a few possibilities you may decide on for your tour.

URL: Start the tour page.

skip enabled to raise a skip button above.

wait_for: Prior to initiating the tour, wait for the delayed object.

test: This tour will only be used for testing if this setting is set to true.

2. Increase the tour's necessary step count.

[tour.stepUtils.showAppsMenuItem(), {
    trigger: '.o_app[data-menu-xmlid="student.menu_research_management_root"]',
	content: Markup(_t('Want to manage your books? It starts here.')),
	position: 'bottom',
    },
    {
	trigger: '.o_list_button_add',
	content: _t('Let\'s create your first book by clicking on create.'),
	position: 'bottom',
    },
	{
   	trigger: '.o_field_widget[name="name"]',
   	content: _t('Fill the Book name.'),
   	// When you run the test (from the developer tools) it will automatically fill in 'War and peace'.
   	run: function (actions) {
        actions.text('War and peace',this.$anchor.find("input"));
        },
   	position: 'right',
   	},
]

There may be multiple conflicts at every stop along the tour. Among the possible arguments are:

trigger: the element, selector, or jQuery you wish to activate

extra_trigger: An additional prerequisite that might be chosen to carry out the step. Similar to the trigger element, it waits, but no additional triggers are used to carry out the action.

run: The procedure to be followed on the trigger element.

edition: The step is active in both community and enterprise if you do not choose an edition.

Alternatively, "Top," "Right," "Bottom," or "Left." When an interactive tour is running, where should the tooltip be placed in relation to the target?

content It is also possible to log the content of the interactive tour tooltips to the console, which is particularly helpful for monitoring and troubleshooting automated tours.

auto: If the tour is interactive, this setting determines whether the tour manager should wait for the user to complete the task. It defaults to false.

The trigger element will only be searched in top-level modal windows if the in_modal property is set. False is the default.

timeout: The amount of milliseconds (10000) that must pass before the step is executed.

3. In a manifest, include the tour.js file.

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

4. Make your class inherit from HTTPCase and call start_tour in order to initiate a tour from a Python test.

@tagged('post_install', '-at_install','student')
class TestUi(HttpCase):

    def test_01_student_tour(self):
        self.start_tour("/web", 'student_tour', login="admin")

5. Use the following option when starting the server to execute the test case:

./odoo-bin -c odoo17.conf -i student - - test - tags=student

6. The following log will be shown if our test case was successful.

...INFO test odoo.addons.student.tests.student_tour.TestBook:
                console log: Tour student_tour succeeded
whatsapp_icon
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