How to Set Up Your Test Automation at eXo Platform
1. What is an automated test ?
An automated test doesn’t require human intervention. Automated test execution requires computer solutions that perform actions, either in a web browser or at the operating system level.
Test automation can reduce testing efforts and increase the amount of testing performed in a limited time. Some tests can be done in minutes that would take several hours if they had been run manually.
2. How do we automate tests in eXo ?
2.1 Development languages and tools
We need the following environment to develop and run test cases:
- Maven 3
- JDK 8
- Docker
Our automation test tool framework is Selenide.
Why Selenide?
To choose the best tool, we selected criteria that we consider essential (see the table below).
Selenium | Codeception | Windmill | Sahi | Cucumber | Selenide | |
Open source | yes | yes | yes | yes with Pro version | yes | yes |
Cross-browser | yes | yes | yes | yes | yes | yes |
Development language | Java | PHP | Python | PHP | PHP | Java |
Script language | JavaScript PHP Python C# Java Ruby | PHP | JavaScript Python Ruby | JavaScript | Gherkin + Java | JavaScript PHP Python C# Java |
Regular update | high | high | low | low | medium | high |
Record playback | yes | yes | yes | yes | no | yes |
Intelligent identification of objects | no | no | no | yes | no | no |
Waiting for events (Ajax) | yes | yes | no | yes | no | yes |
Reporting | yes | yes | yes | Only Pro version | Plugin | yes |
The criteria for choosing the best automation tool are the same for Selenium and Selenide. We chose Selenide because it offers simplicity in creating test cases, as explained in this link: selenide vs selenium.
2.2 Automatic test development
The choice of test cases to be automated is based on several criteria, such as execution frequency, the development and maintenance time for the test case, and the test case execution time.
The diagram below shows the different criteria for selecting cases that will be automated.
To automate a test case, we have to go through three steps.
1. Locator declaration
“Locators” are variables defined in the “Xlocators” classes to select the HTML elements used in the test cases.
We find these classes in the“Selenium” module.
Here are some examples of locators:
By “id”
public static final SelenideElement ELEMENT_ABOUT_ME_PORTLET=$(byId(“UIExperienceProfilePortlet“));
By “className”
public static final SelenideElement ELEMENT_BUTTON_ADD_GADGET=$(byClassName(“AddIcon“));
By “Xpath”
public static final SelenideElement ELEMENT_TAB_ACCESS_AND = $(byXpath(“//*[@id=\”UITabPane\”]/ul/li[2]/a“));
There are several ways to define the locator. We should prioritize selection by “id” or “className” if it is unique. Also, we can use by “Xpath”, “value”, “type”, “name”, and so on.
2. Function development
Functions are specific actions that will be used in test cases. All the functions used in our test cases are in the “pageobject” package of each module. For example, the functions used for wiki test cases are under the “pageobject” package in the wiki module.
We must use locators that have already been declared in our functions. Below you can see the “add a user” function used extensively in our test cases.
3. Test case development
Smoke test cases are under the module associated with these tests. For example, smoke forum tests are under the forum module.
Sniff and functional test cases are under the platform module because they require dependencies to the other modules.
The test type is specified using the @Tag annotation in test classes. For example, this class contains sniff tests of the Answer function:
We use pre-defined functions in our test cases to execute the desired scenario.
3) How do we run automated tests?
3.1. Run with IDE and local browser
We can run the test case through the IDE (Intellij) by adding the necessary parameters in “VM_options(-ea -Dwebdriver.chrome.driver=<path-to-chrome-driver> -Dselenide.baseUrl=<exoplatform-instance-url>)”. The test will be run on your local browser.
3.2. Run with Maven and local browser
We can run tests using this Maven command:
mvn clean verify -Prun-its,chrome \
-Dselenide.baseUrl=<exoplatform-instance-url> \
-Dselenium.webdriver.chrome.driver.path=<path-to-chrome-driver>
3.3. Run with Docker, Maven and Selenium Grid
Tests can be run on Docker images of Selenium Grid and Chrome.
First, we must start containers using this command:
docker-compose -f core/src/main/resources/stack/docker-compose-50-hsqldb.yml -p qa_ui up
Then, we run tests on the chrome node of the Selenium Grid.
We can use this parameter to select tests to run; for example, if you want to run smoke tests, you add -Dselenide.test.tags.include=smoke \ to the above command.
3.4. Run with Jenkins
We can also run automated tests through our private pipeline: platform-qa-ui-with-params.
Conclusion
Test automation at eXo has allowed increased coverage of test cases, early detection of anomalies (i.e. we have scheduled an automatic weekly Jenkins pipeline run for early bug detection) and time savings in execution (e.g. 1000 cases require 10 d/h to execute on one instance manually, while automatic tests are run in four hours on multiple instances in parallel).