重用线程/使用maven surefire生成新浏览器,使用低threadCount生成TestNG

时间:2018-02-16 15:22:43

标签: java testng parallel-testing

重用线程可能不是一个正确的术语,但是我正在运行一个测试自动化设置,它使用来自maven surefire的<threadCount>来运行我的testNG测试套件。问题是:

测试正在运行并打开新浏览器,直到要运行的测试数量大于指定的threadCount。例如,如果我在运行中有10个测试并指定7个线程,我将最初启动7个浏览器,但是不会等到关闭它们以启动另外3个,它将重新使用7个浏览器中的3个来执行接下来的测试。

如何在此实例中等待7完成,然后启动另外3个全新的浏览器,而不重复使用相同的浏览器实例。

扩展它将变得不可行,如果我有100个测试运行并使用10个线程,我将在原始10个浏览器实例中重新运行90个测试。

  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>${maven.surefire.version}</version>
  <configuration>
     <parallel>methods</parallel>
     <threadCount>${thread.count}</threadCount>
      <suiteXmlFiles>   

这里有一些代码用于启动我的驱动程序:

@BeforeSuite(alwaysRun = true, description = "Driver Instantiation")
public static void instantiateDriverObject() {
    driverFactory = new ThreadLocal<DriverFactory>() {
        @Override
        protected DriverFactory initialValue() {
            DriverFactory driverFactory = new DriverFactory();
            webDriverThreadPool.add(driverFactory);
            return driverFactory;
        }
    };
}

0 个答案:

没有答案