I am trying to run my automated tests(Selenium webdriver) in parallel using testng. this is the node which I am running:
java -Dwebdriver.gecko.driver=chromedriver.exe -jar selenium-server-standalone-3.4.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=chrome,maxInstances=2 -maxSession 2
this is my test class:
public class TestParallel {
Login login;
//@BeforeMethod(alwaysRun = true)
public SeleniumDriverCore testSetup() throws FileNotFoundException, IOException{
SeleniumDriverCore driver = new SeleniumDriverCore("config/chromeDriverConfig");
Properties config = new Properties();
config.load(new FileInputStream("config/testConfig"));
this.login = new Login(driver);
driver.browser.open("https://test.test.xyz");
driver.browser.maximize();
driver.waits.waitForPageToLoad();
return driver;
}
@Test(groups={"parallel"})
public void test_one() throws FileNotFoundException, IOException{
SeleniumDriverCore driver=testSetup();
login.navigateToPage(Pages.LOGIN);
login.assertion.verifyLoginPopupAndTitleDisplayed();
testCleanup(driver);
}
@Test(groups={"parallel"})
public void test_two() throws FileNotFoundException, IOException{
SeleniumDriverCore driver=testSetup();
login.navigateToPage(Pages.LOGIN);
login.assertion.verifyLoginPopupAndTitleDisplayed();
testCleanup(driver);
}
@Test(groups={"parallel"})
public void test_three() throws FileNotFoundException, IOException{
SeleniumDriverCore driver=testSetup();
login.navigateToPage(Pages.LOGIN);
login.assertion.verifyLoginPopupAndTitleDisplayed();
testCleanup(driver);
}
@Test(groups={"parallel"})
public void test_four() throws FileNotFoundException, IOException{
SeleniumDriverCore driver=testSetup();
login.navigateToPage(Pages.LOGIN);
login.assertion.verifyLoginPopupAndTitleDisplayed();
testCleanup(driver);
}
public void testCleanup(SeleniumDriverCore driver){
driver.close();
driver.quit();
}
}
and here is my xml:
<suite name="Ontega - All Tests Mobile" parallel="methods" thread-count="2">
<test name="Ontega - All Tests Mobile">
<groups>
<run>
<include name="parallel"/>
<exclude name="open-defects"/>
</run>
</groups>
<packages>
<package name="tests.*"/>
</packages>
</test>
</suite>
when I run the XML, I expect to have my tests to be running on two browsers in two threads at a time, however when I run the XML I get two browser instances running at the first time and then they are incremented and 50% of the tests are failing, as you can see I am trying to instantiate the driver in each of my methods, although it's not how my framework is working, but I am trying to get to the bottleneck of this issue.
Any help would be very appreciated
Thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…