Enable Dark Mode!
creating-tour-odoo-custom-module.png
By: Linto

Creating a tour in Odoo custom module

Technical

For testing the software, Odoo provides different methods such as python unit tests for testing model business logic and javascript unit tests for testing the javascript code in isolation. There is another type of testing called ‘tours’. The tours are a form of integration testing. It ensures that the javascript(web client) and python(server) are properly connected to each other and works together. We have already discussed how to use run tours in Odoo. In this blog, we will discuss how to create a custom tour and use it for testing purposes in Odoo 10.

Steps to Creating a Tours

Tours consist of a sequence of steps for performing an operation. For creating a tour, we have to specify some details. A sample is provided below.
odoo.define(your_module.tour', function (require) {
'use strict';
var tour = require("web_tour.tour");
var base = require("web_editor.base");
var options = {
    test: true,
    url: '/shop',
    wait_for: base.ready()
};
var tour_name = ‘your_tour_name’;
tour.register(tour_name, options,
    [
        {
            content: "<step content>",
            trigger: '<element>',
            run: "<action>",
        },
        /* ..put your steps here.. */
    ]
);
});
The above code is a sample for creating custom tours in Odoo.
Here the ‘options’ includes various options available with tests. 
    test: if this is set to true, then this test will be used only for testing purposes. 
    url: if an url is specified, then Odoo will open this url, before running the test.
    wait_for:  if specified, it will wait for the deferred object before running the tour.
    skip_enabled: it adds a Skip button in tips.

After specifying the options, now we have to register for the tour.
For registering a tour, Odoo requires the tour name, tour options, and the steps of the tour. Steps consist of a set of attributes. 

    content: name or title of the step
    trigger (mandatory): where to place tip. In js tests: where to click
    extra_trigger: when this becomes visible, the tip is appeared. In js tests: when to click
    timeout: max time to wait for conditions
    position: how to show tip (left, right, top, bottom), default right
    width: width in px of the tip when opened, default 270
    edition: specify to execute in “community” or in “enterprise” only. By default empty – execute at any edition.
    run: specifies what to do when the step is executed.
         'text SOMETEXT': writes some text in the trigger element
        'click'
        'drag_and_drop TO_SELECTOR'
        'auto' – auto action (click or text)
        function: (actions) { ... } – here, ‘actions’ is an instance of tour action helper.
    auto: used to skip the step in non-auto running

There are some predefined steps in Odoo. 
tour.STEPS.MENU_MORE – used to click on menu ‘More’ 
tour.STEPS.TOGGLE_APPSWITCHER – opens ‘Apps’ page(enterprise version)
tour.STEPS.WEBSITE_NEW_PAGE – clicks ‘New Page’ on the website.

Testing Using Tours

Once we have created the tours, it’s time to run them. We have already discussed running them from the user interface(for demonstration purpose) in our previous blogs. In order to use the tours for testing purpose, we can use ‘phantomjs’. While we create the test cases, we can call the javascript tour from python using the ‘phantom_js()’ method.

Example:
	@odoo.tests.common.post_install(True)
class TestSample(odoo.tests.HttpCase):
    def test_01_team_handler_tour(self):
self.phantom_js("/web",  "odoo.__DEBUG__.services['web_tour.tour'].run('tour_name')", "odoo.__DEBUG__.services['web_tour.tour'].tours.tour_name.ready",  login="admin")

The working order is as follows.
OPEN url_path(here ‘/web’ page) from python phantom_js method
WAIT ready condition (Truthy or Falsy) from python phantom_js method
OPEN url from tour’s options in a js file
WAIT wait_for (deferred object) from tour’s options in a js file
DO the first step from js tour
* WAIT when trigger becomes visible
* WAIT when extra_trigger becomes visible (if extra_trigger is presented)
* EXECUTE action (run or click on trigger)
DO NEXT step
STOP Running when:
* error happens:
* thrown via raise
* reported via console.log('error', ...)
* reported via console.error(...), etc.
* reported by tour system on timeout for initial ready condition.(Timeout value is 10 sec and it cannot be changed.)
* reported by tour system on step timeout.
'ok' is reported via console.log('ok')
* directly by code
* indirectly by tour system when all steps are done
timeout from python phantom_js method is occurred. The default is 60 sec



If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



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