Test automation - all well and good, but what happens when the product you are testing is UI heavy and your test suite increases to hundreds of tests and takes hours to fully execute? Each extra minute of runtime takes you one inch away from the Holy Grail, namely CI/CD.
The answer is test parallelisation. Executing the tests in parallel can exponentially decrease runtime, thus allowing you to get the test results faster and release quicker into Production.
Opening multiple browser instances simultaneously may not work perfect each time, but luckily we have a bulletproof solution in Docker's Selenium Hub.
This article will present a Frontend test automation framework built with Serenity and Java and the steps for configuring its parallel test execution in a Selenium Docker Hub.
1. Setup the Docker Hub
Depending on the machine's OS, Docker is installed in different ways. In this case, the operating system was MacOS so Docker Desktop was initially installed.
Now, using a Docker Compose .yml file that contains all the setup info, you can start the grid as per your requirements (the required Docker images will be downloaded automatically). In the terminal, go to the folder where the .yml file is located and run the following command, specifying the number of Firefox and Chrome containers (2 in this case):
The debug versions of the Firefox and Chrome images will allow you to connect to them using VNC Viewer in order to see realtime the test execution.
Access http://localhost:4445/grid/console and the up and running grid is shown.
2. Configure the automation framework for parallel test execution in the newly create grid
Update the serenity.properties file with the type and new location for the webdriver:
webdriver.remote.url = http://localhost:4445/wd/hub
webdriver.remote.driver = chrome
webdriver.remote.os = LINUXUpdate in the pom.xml file the Maven Failsafe plugin configuration, plugin responsible in this case for test execution, to run the tests in parallel in the new grid setup:
<configuration>
<includes>
<include>**/*TestSuite.java</include>
</includes>
<reuseForks>true</reuseForks>
<argLine>-Xmx512m</argLine>
<parallel>classes</parallel>
<threadCount>2</threadCount>
<forkCount>2</forkCount>
</configuration>3. Run the tests
In the terminal call the Failsafe plugin, which will execute all the TestSuite classes:
$ mvn clean verify
During runtime you will see the nodes that are in use as faded out:
Check the summary results in the console and the detailed HTML report:




No comments:
Post a Comment