Reputation: 1
My goal is to a run test cases parallel on below combination and produce a extent report for each combination, total 8 combination
Have come up with this after searching over net.
This <suite>
run all <test>
tags parallel and each <test>
represents a OS & browser combination that again run test classes parallel. Each test class has a RemoteWebDriver instance.
TestNg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests">
<test name="Windows_Chrome" parallel="classes" thread-count="3">
<parameter name="os" value="windows" />
<parameter name="browser" value="chrome" />
<classes>
<class name="com.mag.SeleniumGrid.Test_001" />
<class name="com.mag.SeleniumGrid.Test_002" />
<class name="com.mag.SeleniumGrid.Test_00N" />
<!--Each class create RemoteWebDriver instance based on parameters-->
</classes>
</test>
<!-- ..... all 8 combinations -->
<test name="Linux_Chrome" parallel="classes" thread-count="3">
<parameter name="os" value="linux" />
<parameter name="browser" value="chrome" />
<classes>
<class name="com.mag.SeleniumGrid.Test_001" />
<class name="com.mag.SeleniumGrid.Test_002" />
<class name="com.mag.SeleniumGrid.Test_00N" />
</classes>
</test>
</suite>
Upvotes: 0
Views: 213
Reputation: 31
Can't say I have used this method so apologies but I use maven to run the tests and have found it works fine. You can add a test to a group by doing:
@Test(groups = {"WindowsChrome", "LinuxChrome"})
public class Test123 {
You can run tests with maven like:
mvn test -Dgroups=WindowsChrome
If you want to run this in a pipeline then I would checkout the code and clone it for each environment. In the pipeline you can add .env files that each environment will use containing variables like "OS_TYPE" and "BROWSER_TYPE". Now you can do:
stage('Windows Chrome Tests') {
steps {
bat "mvn test -f WindowsChrome/pom.xml -Dgroups=WindowsChrome"
}
}
stage('Linux Chrome Tests') {
steps {
bat "mvn test -f LinuxChrome/pom.xml -Dgroups=LinuxChrome"
}
}
In order to have logs making any sense with parallel tests you need to use ThreadLocal with Logger which will create a unique instance for each thread. Ensure you remove this when done or a following test using the same thread will continue on using the same instance. I would put the OS/browser in the log file name.
Upvotes: 1