Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在多个并行线程中运行单个testng测试用例_Java_Selenium_Testng - Fatal编程技术网

Java 如何在多个并行线程中运行单个testng测试用例

Java 如何在多个并行线程中运行单个testng测试用例,java,selenium,testng,Java,Selenium,Testng,我想在任何浏览器中多次并行运行单个测试NG测试用例。要多次运行测试用例,请在@test注释中使用invocationCount属性。此调用计数确定TestNG应运行此测试方法的次数 @Test(invocationCount = ?) A.2。要在不同线程中多次运行测试用例,请在@test注释中使用threadPoolSize属性。该属性告诉TestNG创建一个线程池,以便通过多个线程运行测试方法 @Test(invocationCount = ?, threadPoolSize = ?)

我想在任何浏览器中多次并行运行单个测试NG测试用例。要多次运行测试用例,请在@test注释中使用invocationCount属性。此调用计数确定TestNG应运行此测试方法的次数

@Test(invocationCount = ?)
A.2。要在不同线程中多次运行测试用例,请在@test注释中使用threadPoolSize属性。该属性告诉TestNG创建一个线程池,以便通过多个线程运行测试方法

@Test(invocationCount = ?, threadPoolSize = ?)
B.3。要在不同线程的多个浏览器中运行测试用例,请将webDriver初始化为ThreadLocal

private static ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
创建驱动程序处理程序和testbase类。使用驱动程序处理程序设置和获取webDriver,并使用基类获取浏览器名称

@BeforeTest
@Parameters("browserName")
public void webDriverHandler(String browserName){
  // String browserName contains parameter value
}
驱动程序处理程序:

public class DriverHandler {

private static ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();

public static WebDriver getDriver() {
    return webDriver.get();
}

public static void setWebDriver(String browser) {

     WebDriver driver = null;

     if (browser.contains("firefox")) {

       driver = new FirefoxDriver();

    } else if (browser.contains("chrome")) {

       ChromeOptions options = new ChromeOptions();
       driver = new ChromeDriver(options);  

    }
    webDriver.set(driver);
}


}

请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅“如何提问”页面以获得澄清此问题的帮助。请参阅:SO的期望是,提出问题的用户不仅要进行研究以回答自己的问题,还要共享研究、代码尝试和结果。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!另请参见:对于多次运行同一测试用例,可以使用以下代码@test(invocationCount=100)public void testCount(){},对于并行执行,可以使用多线程。
public class DriverHandler {

private static ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();

public static WebDriver getDriver() {
    return webDriver.get();
}

public static void setWebDriver(String browser) {

     WebDriver driver = null;

     if (browser.contains("firefox")) {

       driver = new FirefoxDriver();

    } else if (browser.contains("chrome")) {

       ChromeOptions options = new ChromeOptions();
       driver = new ChromeDriver(options);  

    }
    webDriver.set(driver);
}


}
public class TestBase { 

 @BeforeTest
 @Parameters("browserName")
 public void threadHandler(String browserName) {

    Thread.currentThread().setName(browser.toLowerCase());
    if (DriverManager.getDriver() == null)
        DriverManager.setWebDriver(browser);
 }


}