How it works...

In order to create tour test cases, you need to create the UI tour first. If you want to learn more about UI tours, refer to the Improve onboarding with tours recipe in Chapter 16, Web Client Development.

In step 1, we registered a new tour with the name library_tour. This tour is exactly like the tour we created in the recipe Improve onboarding with tours in Chapter 16, Web Client Development.

Here, we have one extra property: run. In the run function, you have to write the logic to perform the operation that is normally done by the user. For example, in the fourth step of the tour, we ask the user to enter the book title.

To automate this step, we have added a run function to set the value in the title field. The run function passes the action utility as the parameter. This provides some shortcuts to perform basic actions. The most important ones are mentioned as follows:

  • actions.click(element) is used to click on the given element.
  • actions.dblclick(element) is used to double-click on the given element.
  • actions.tripleclick(element) is used to triple-click on the given element.
  • actions.text(string) is used to set the input values.
  • action.drag_and_drop(to, element) is used to drag and drop the element.
  • action.keydown(keyCodes, element) is used to trigger particular keyboard events on the element.
  • action.auto() is the default action. When you don't pass the run function in the tour step, action.auto() is performed. Auto action will mostly click on the trigger element of the tour step. The only exception here is an input element. If the trigger element is input, the tour will set the default value Test in the input. That is why we don't need to add run functions to all of the steps.

Alternatively, you can perform whole actions manually, in case default actions are not enough. In the next tour step, we want to set a value for the color picker. Note that we have used the manual action, because default values won't help here. Consequently, we have added the run method with the basic JQuery code to click on the third pill of the color picker. Here, you will find the trigger element with the this.$anchor property.

By default, registered tours are displayed to the end user to improve the onboarding experience. In order to run them as a test case, you need to run them in Headless Chrome. To do so, you need to use the HttpCase Python test case. This provides the browser_js method, which opens the URL and executes the command passed as the second parameter. You can run the tour manually, like this:

odoo.__DEBUG__.services['web_tour.tour'].run('library_tour')

In our example, we have passed the name of the tour as the argument in the browser_js method. The next parameter is used to wait for a given object to be ready before performing the first command. The last parameter in the browser_js() method is the name of the user. This username will be used to create a new test environment, and all of the test actions will be performed on behalf of this user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset