简体   繁体   中英

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

I have a basic test using 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.

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. You can try with thread local WebDriver as given below.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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