【发布时间】:2018-01-30 12:33:10
【问题描述】:
试图为我正在构建的作为学习工具的框架设置驱动程序工厂。但是,我正在努力在 testng 中并行执行测试类。
我正在使用万能插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<properties>
<suiteXmlFiles>
<suiteXmlFile>src/main/resources/master.xml</suiteXmlFile>
</suiteXmlFiles>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
我使用的testng版本是:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
而master.xml如下:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="classes" thread-count="2">
<test name="Test 1">
<classes>
<class name="testsuite.TestCase1"/>
<class name="testsuite.TestCase2"/>
</classes>
</test>
</suite>
为了发帖的目的,我已经简化了驱动程序工厂:
public class DriverFactory
{
//protected WebDriver driver;
private DriverFactory()
{
//Do-nothing..Do not allow to initializethis class from outside
}
private static DriverFactory instance = new DriverFactory();
public static DriverFactory getInstance()
{
return instance;
}
ThreadLocal<WebDriver> driver = new ThreadLocal<WebDriver>() // thread local driver object for webdriver
{
@Override
protected WebDriver initialValue()
{
System.setProperty("webdriver.chrome.driver",
"src/main/resources/chromedriver.exe");
return new ChromeDriver(); // can be replaced with other browser drivers
}
};
public WebDriver getDriver() // call this method to get the driver object and launch the browser
{
return driver.get();
}
public void removeDriver() // Quits the driver and closes the browser
{
driver.get().quit();
driver.remove();
}
}
使用以下mvn命令运行:
mvn 清洁测试
在阅读了我 cad 找到的几乎所有与此相关的教程、博客文章和文档后,我知道这对我来说会很愚蠢。
非常感谢任何帮助,即使只是为我指明正确的方向。
【问题讨论】:
-
我不明白是什么问题
-
@SeniorPomidor 抱歉,我正在尝试使用surefire 和测试在selenium 中获得并行执行。但是,无论我尝试什么,测试都会按顺序运行。
标签: java maven selenium parallel-processing testng