简体   繁体   English

Java-Fluentlenium如何使用1种方法的线程运行TestNG

[英]Java - Fluentlenium how to run TestNG with threading for 1 method

I have a basic test using TestNG. 我有一个使用TestNG的基本测试。 When I run the test using invocationcount = 2, threadpoolsize = 2 (just for testing), I can see in intellij that the tests is running currently but only one browser open. 当我使用invocationcount = 2运行线程测试时,threadpoolsize = 2(仅用于测试),我可以在intellij中看到测试当前正在运行,但是仅打开了一个浏览器。

Heres' my code: 这是我的代码:

 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()); } } 

Anyone know how to fix this? 有人知道怎么修这个东西吗?

Here you have one webdriver instance and calling in two threads. 在这里,您有一个webdriver实例,并在两个线程中调用。 You can try with thread local WebDriver as given below. 您可以尝试使用线程本地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());
 } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM