Nuxeo Core Developer Guide

Selenium tests

Updated: October 22, 2018 Page Information Edit on GitHub

Nuxeo is using a tool to run selenium tests on a given server, see documentation at https://github.com/nuxeo/tools-nuxeo-ftest

Selenium documentation

Helpful links: http://seleniumhq.org/documentation/

Commands reference: http://release.seleniumhq.org/selenium-core/1.0.1/reference.html

Firefox plugins

Here are some Firefox plugins that make life easier writing Selenium tests:

Structure of Nuxeo test suites

The Nuxeo test suites are located in subdirectory tests/ and named tests.html, suite1.html and suite2.html.

tests.html has been cut in two for automated testing: THINK OF UPDATING ALL FILES WHEN ADDING/REMOVING tests.

Note that the tests are currently not very "unit": some tests will require previous tests to be run to succeed.

Generic advice when writing tests

  • Have a look at selenium commands to see what is available.

  • Write small test cases, and try to make them as unit as possible. Do not forget to set a timeout at the beginning of your test (it default to 3000ms may not be enough) and to start and end the test by logging out of the nuxeo application.

  • Be specific when testing an element: a vague xpath reference may trigger a false error if the HTML page slightly changes. If you can't be specific, then page rendering should be changed to ease this process.

  • Handle ajax requests properly: if the test cannot detect correctly when the ajax call is finished, it may lead to "heisenbugs", e.g. tests alternatively failing or succeeding with no apparent reason.

 

1. when triggering an ajax call through a4j or richfaces JSF libraries, the following commands have been made available in the nuxeo suites user-extensions.js file: "watchA4jRequests" and "waitForA4jRequest". "watchA4jRequests" has to be called before any command that will trigger an ajax call, it does not take any parameters. "waitForA4jRequest" has to be called after the command that will trigger an ajax call, it takes a timeout as parameter.

Sample usage:


<tr>

<td>watchA4jRequests</td>

<td></td>

<td></td>
     </tr>

<tr>

<td>typeKeys</td>

<td>//input[@name='createUser:nxl_user:nxw_groups_suggest']</td>

<td>members</td>
     </tr>

<tr>

<td>waitForA4jRequest</td>

<td>10000</td>

<td></td>
     </tr>

WARNING: The "typeKeys" command has a bug that simulates the "ALT" key when using the "y" character (see http://jira.openqa.org/browse/SIDE-309) so you should avoid this character in suggestion keywords.

2. when triggering a remote call using jQuery or prototype Javascript libraries, the following command has been made available in the nuxeo suites user-extensions.js file: waitForJSQueries. It takes a timeout has parameter.

Sample usage:


<tr>

<td>waitForQueries</td>

<td>100000</td>

<td></td>
     </tr>

3. when triggering any other call (Javascript call with Seam remoting calls for instance), using the Selenium command "waitForCondition" with appropriate javascript testing is usually enough to test that the ajax response has been received. Commands "waitForEditable" or "waitForTextPresent" may also be helpful.

Sample usage:

<!-- wait for table to disappear -->

<tr>

<td>waitForCondition</td>

<td>selenium.browserbot.getCurrentWindow().document.getElementById('editGroup:nxl_group:nxw_members_list:2:nxw_members_listItem') == null</td>

<td>10000</td>
     </tr>

how to get an element when no id is available

(taken from http://lawrencesong.net/2008/01/selenium-element-locators/)

<a href="link url">Link Text</a> -> link=Link Text

get element with the element text :

<a href="link url">Link Text</a> -> //a[text()='Link Text']

get element with part of the element text:

<a href="link url">Link Text</a> -> //a[contains(text(), 'ink Tex')]

get element with an attribute :

<a href="link url">Link Text</a> -> //a[@href='link url']

get element with two attributes :

<input type="text" value="value"/> -> //input[@type='text' and @value='value']

sometimes this command will succed:


<td>click</td>

<td>dashboardDocumentProcessTable:j_id130</td>

<td></td>

when this one will fail:


<td>click</td>

<td>//input[@id="dashboardDocumentProcessTable:j_id130"]</td>

<td></td>

When trying to debug what's happening on the server, it may be useful to print out the rendered HTML in the page. The following command can be used:


<tr>

<td>storeEval</td>

<td>selenium.browserbot.getCurrentWindow().document.body.innerHTML</td>

<td>innerhtml</td>
  </tr>

<tr>

<td>echo</td>

<td>${innerhtml}</td>

<td></td>
  </tr>

2 months ago manonlumeau NXDOC-1650 fix about integrating changes, add mention on multiple attempts
3 years ago Ronan Daniellou 24 | ixes titles + typ
3 years ago Ronan Daniellou 23 | Fixes layout + adds Nuxeo TOC
7 years ago Antoine Taillefer 21
7 years ago Antoine Taillefer 22 | Migrated to Confluence 4.0
7 years ago Anahide Tchertchian 20
7 years ago Anahide Tchertchian 19
8 years ago Stéfane Fermigier 18
8 years ago Stéfane Fermigier 17
8 years ago Stéfane Fermigier 16
8 years ago Stéfane Fermigier 15
8 years ago Stéfane Fermigier 14
8 years ago Stéfane Fermigier 13
8 years ago Stéfane Fermigier 12
8 years ago Stéfane Fermigier 11
8 years ago Stéfane Fermigier 10
8 years ago Stéfane Fermigier 9
8 years ago Stéfane Fermigier 8
8 years ago Stéfane Fermigier 7
8 years ago Stéfane Fermigier 6
8 years ago Stéfane Fermigier 5
8 years ago Stéfane Fermigier 4
8 years ago Stéfane Fermigier 3
8 years ago Stéfane Fermigier 2
8 years ago Stéfane Fermigier 1
History: Created by Stéfane Fermigier

We'd love to hear your thoughts!

All fields required