我想用testng并行运行我的自动化测试(Selenium webdriver)。这是我正在运行的节点:如何使用testng并行运行我的硒测试方法
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
这是我的测试类:
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();
}
}
这里是我的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>
当我运行XML,我希望我的测试能够在两个线程中同时在两个浏览器上运行,但是当我运行XML时,我得到两个浏览器ances在第一时间运行,然后他们增加和50%的测试失败,你可以看到我试图在我的每个方法中实例化驱动程序,虽然这不是我的框架如何工作,但我试图去解决这个问题的瓶颈。 任何帮助将不胜感激 在此先感谢
要创建每个测试方法调用两个司机,你也只需要调用退出时,你拆掉 –
我已经修复了我的代码,现在的问题是,铬页面打开一个空白页,就是这样。 –