问题
I want to run my automation suite (implemented using Selenium Webdriver (Java) + TestNG + Maven) in parallel against multiple browser capabilities. I can run it in parallel for different capabilities using below sample testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="5" name="Functional Test Suite" parallel="tests">
<test name="Windows-FF-37.0" preserve-order="true" >
<parameter name="browser" value="Firefox"/>
<parameter name="version" value="37.0"/>
<parameter name="os" value="Windows"/>
<parameter name="os_version" value="8.1"/>
<parameter name="device" value=""/>
<classes>
<class name="uat.mycompany.tests.FirstTest"/>
<class name="uat.mycompany.tests.SecondTest"/>
<class name="uat.mycompany.tests.ThirdTest"/>
<class name="uat.mycompany.tests.FourthTest"/>
</classes>
</test>
<test name="MAC-Yosemite-Chrome-36.0" preserve-order="true">
<parameter name="browser" value="Chrome"/>
<parameter name="version" value="36.0"/>
<parameter name="os" value="OS X"/>
<parameter name="os_version" value="Yosemite"/>
<parameter name="device" value=""/>
<classes>
<class name="uat.mycompany.tests.FirstTest"/>
<class name="uat.mycompany.tests.SecondTest"/>
<class name="uat.mycompany.tests.ThirdTest"/>
<class name="uat.mycompany.tests.FourthTest"/>
</classes>
</test>
</suite>
But when I run this testng.xml, it starts with 'FirstTest' on both VMs; one with Chrome+Mac & another with Forefox+Windows configuration. I DO NOT want this, because the data modified by one script fails another script.
My requirement is to run all classes from one node in parallel and nodes in sequence. As a work around, I can always put classes name in different order in different test nodes, but since I am having hundreds of test classes, it is not feasible solution.
Also, eventually I want to set up these parameters through some properties file so that I can manage the run environments easily.
回答1:
You can follow the below steps:
- Define 2 different suites (XML files) for different tests.
- for each suite mention:
thread-count="4" parallel="classes"
- Create a third suite (xml file) to run the above 2 files sequentially (Don't mention thread-count & parallel parameters for suite.)
First XML file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="5" name="Functional Test Suite1" parallel="classes">
<test name="Windows-FF-37.0" preserve-order="true" >
<parameter name="browser" value="Firefox"/>
<parameter name="version" value="37.0"/>
<parameter name="os" value="Windows"/>
<parameter name="os_version" value="8.1"/>
<parameter name="device" value=""/>
<classes>
<class name="uat.mycompany.tests.FirstTest"/>
<class name="uat.mycompany.tests.SecondTest"/>
<class name="uat.mycompany.tests.ThirdTest"/>
<class name="uat.mycompany.tests.FourthTest"/>
</classes>
</test>
</suite>
Second XML file:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="5" name="Functional Test Suite2" parallel="classes">
<test name="MAC-Yosemite-Chrome-36.0" preserve-order="true">
<parameter name="browser" value="Chrome"/>
<parameter name="version" value="36.0"/>
<parameter name="os" value="OS X"/>
<parameter name="os_version" value="Yosemite"/>
<parameter name="device" value=""/>
<classes>
<class name="uat.mycompany.tests.FirstTest"/>
<class name="uat.mycompany.tests.SecondTest"/>
<class name="uat.mycompany.tests.ThirdTest"/>
<class name="uat.mycompany.tests.FourthTest"/>
</classes>
</test>
</suite>
Third XML file (Need to execute this file):
<suite name="suite of suites">
<suite-files>
<suite-file path="Functional Test Suite1.xml" />
<suite-file path="Functional Test Suite2.xml" />
</suite-files>
</suite>
回答2:
For the above example set <suite thread-count="4" name="Functional Test Suite" parallel="classes">
If you set thread-count
to be less than the number of classes
inside a test
then tests
will run sequentially but the classes
will run in parallel. Once all the test classes
are run in the test
then next test
will start.
回答3:
<test name="api test" parallel="methods">
<groups>
<run>
<include name="test_proxy" />
</run>
</groups>
<classes>
<class name="com.spire.test.TestAutomation" />
</classes>
</test>
<test name="api test1" parallel="methods">
<groups>
<run>
<include name="test" />
</run>
</groups>
<classes>
<class name="com.spire.test1.TestAutomation1" />
</classes>
</test>
回答4:
You can code like below, it will work.
来源:https://stackoverflow.com/questions/31351565/how-to-run-testng-test-nodes-in-sequence-but-all-inside-classes-in-parallel-for