这是我的类,包含我想要并行执行的测试方法。 来自Data Provider的每个输入都是一个新线程。 当我在2个线程中执行此方法时,因为数据提供程序有2个输入,测试在一个浏览器中挂起而其他执行
public class DemoTest {
private static final ThreadLocal<WebDriver> webDriverThreadLocal= new InheritableThreadLocal<>();
private String baseUrl;
private String severity;
@BeforeMethod
public void beforeMethod() {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().window().maximize();
webDriverThreadLocal.set(driver);
System.out.println("In before method:"+Thread.currentThread().getId());
System.out.println("FF hashcode:"+driver.hashCode());
}
@DataProvider(name = "data-provider", parallel=true)
public Object[][] dataProviderMethod() throws IOException {
System.out.println("On dp");
new Object[] { 1, "a" },
new Object[] { 2, "b" },
}
public void testProgramOptions(Integer n, String s) {
WebDriver driver = webDriverThreadLocal.get();
baseUrl = "http://www.google.com/";
driver.get(baseUrl);
System.out.println("method f id:"+Thread.currentThread().getId()+" n:"+n+" s:"+s);
//test continues
}
@AfterMethod
public void afterMethod() {
WebDriver driver = webDriverThreadLocal.get();
System.out.println("In after method for id:"+Thread.currentThread().getId());
driver.quit();
}
}
这是testng.xml
<suite name="Suite" parallel="methods">
<test name="prelogin" >
<classes>
<class name="DemoTest"></class>
</classes>
</test>
</suite>