I am trying to run parallel tests configuring a suite file. The tests are for web application using Selenium. The suite file is composed from multiple tests. Every test contains more than one test classes. The first class in every test is used to initialize (@BeforeTest) the WebDriver and shut down it (@AfterTest). The WebDriver is static in order to pass it to the other classes (The reason is that we need to continue the tests from the point where the last test-class has end).
The tests are successfully running when the suite is configured to run the tests sequentially. But when the suite is configured to run the tests in parallel, all the suite tests are using only the last loaded webdriver and each test is not running in it respective browser.
Do you have any idea how i can overcome this situation?
Check the suite template below:
<suite name="Register and Login functionality" parallel="tests" thread-count="2">
<test name="Test-1">
<parameter name="browser" value="chrome" />
<classes>
<class name="Init" />
<class name="Register" />
<class name="Login" />
</classes>
</test>
<test name="Test-2">
<parameter name="browser" value="chrome" />
<classes>
<class name="Init" />
<class name="Register" />
<class name="Login" />
</classes>
</test>
</suite>
The template from the Init test-class:
public class Init{
private static WebDriver driver;
public WebDriver getWebDriver(){
return this.driver;
}
@BeforeTest
public void setUp(){
driver = new ChromeWebDriver();
}
@AfterTest
public void quit(){
driver.stop();
}
}
The template from the register test class:
public class Register{
private WebDriver driver;
@BeforeClass
public void setUp(){
driver = Init.getWebDriver();
}
@Test
public void test1(){
........
........
}
@Test
public void test2(){
........
........
}
}
The template from login test-class:
public class Login{
private WebDriver driver;
@BeforeClass
public void setUp(){
driver = Init.getWebDriver();
}
@Test
public void test1(){
........
........
}
@Test
public void test2(){
........
........
}
}