我使用TestNG进行基本测试。当我使用invocationcount = 2,threadpoolsize = 2(仅用于测试)运行测试时,我可以在intellij中看到测试当前正在运行,但只打开了一个浏览器。
Heres'我的代码:
public class GoogleTesting extends FluentTestNg {
// Defines the Driver
public WebDriver driver = new ChromeDriver();
@Override
public WebDriver newWebDriver() {
return driver;
}
@Test(invocationCount = 2, threadPoolSize = 2)
public void GoogleTest(){
goTo("http://google.com");
System.out.println(getCookies());
}
}
任何人都知道如何解决这个问题?
答案 0 :(得分:0)
这里有一个webdriver实例,并在两个线程中调用。您可以尝试使用下面给出的线程本地WebDriver。
public class GoogleTesting extends FluentTestNg {
// Defines the Driver
private static ThreadLocal<WebDriver> WebDriverTL = new ThreadLocal<WebDriver>();
public void setWebdriver(Webdriver driver){
WebDriverTL.set(driver);
}
@Override
public WebDriver newWebDriver() {
return WebDriverTL.get ();
}
@beforeMethod
public void launch browser(){
WebDriver driver = new ChromeDriver();
setWebdriver(driver);
}
@Test(invocationCount = 2, threadPoolSize = 2)
public void GoogleTest(){
goTo("http://google.com");
System.out.println(getCookies());
}
}