2017-06-15 72 views
0

我有一個使用TestNG的基本測試。當我使用invocationcount = 2,threadpoolsize = 2(僅用於測試)運行測試時,我可以在intellij中看到測試正在運行,但只有一個瀏覽器打開。Java - Fluentlenium如何使用1種方法的線程運行TestNG

繼承人我的代碼:

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

任何人都知道如何解決這一問題?

+1

因爲您只打開一個瀏覽器窗口...將驅動程序初始化移入測試方法並檢查 – Grasshopper

回答

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

謝謝!它現在同時啓動兩個瀏覽器。現在唯一的解決方法是在啓動後爲何出現錯誤。 – ParkHyeon

相關問題