I'm having some issues with parallel execution of tests using TestNG + Selenium (Chrome WebDriver). Basically, my tests don't actually appear to be truly executed in parallel.
Trying to achieve: Data being read from an Excel spreadsheet. All test cases in TestSuite.java should execute for every row of data, in separate WebDriver instances - running in parallel. Eg testing 5 separate login/password combinations simultaneously in separate browser windows.
Simplified illustration:
public class TestSuite {
private String param;
@DataProvider
public static Object[][] provider() {
return new Object[][] {{"1"},{"2"}};
}
@Factory(dataProvider = "provider")
public TestSuite(String data) {
this.param = data;
System.out.println(String.format("[Thread: %d] TestSuite (%s)", Thread.currentThread().getId(), param));
// Can't initialise webdriver instances here, different thread
}
@BeforeClass
public void init() {
System.out.println(String.format("[Thread: %d] BeforeClass (%s)", Thread.currentThread().getId(), param));
// This is where I'm retrieving webdriver instances
}
@Test
public void TC_001() {
System.out.println(String.format("[Thread: %d] TC_001 (%s)", Thread.currentThread().getId(), param));
}
@Test
public void TC_002() {
System.out.println(String.format("[Thread: %d] TC_002 (%s)", Thread.currentThread().getId(), param));
}
}
TestNG.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="instances" group-by-instances="true">
<test name="Test">
<classes>
<class name="TestSuite" />
</classes>
</test>
</suite>
Output:
[Thread: 1] TestSuite (1)
[Thread: 1] TestSuite (2)
[Thread: 11] BeforeClass (1)
[Thread: 11] TC_001 (1)
[Thread: 11] TC_002 (1)
[Thread: 12] BeforeClass (2)
[Thread: 12] TC_001 (2)
[Thread: 12] TC_002 (2)
The main issue here is that my tests are clearly being executed SEQUENTIALLY. Can anyone explain what I have done wrong - what is the correct approach to achieve the desired outcome that I explained above?
make parallel as methods in TestNG.xml as below
suite name="Suite" parallel="methods" group-by-instances="true"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.