使用Selenium和TestNG并行交叉浏览器测试,而不使用testng.xml

Jam*_*mar 5 java testng selenium maven selenium-webdriver

我正在使用Maven Failsafe + TestNG来运行Selenium测试.我知道可以通过在pom.xml中定义系统属性来将参数传递给我的TestNG测试,如下所示:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <systemPropertyVariables>
        <browser>firefox</browser>
      </systemPropertyVariables>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

我的TestNG测试将此属性称为:

@Parameters("browser")
public void setUpClass(@Optional("firefox") String browser)
{
   ...
}
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否可以并行运行跨浏览器测试而无需指定testng.xml文件.我正在尝试这样的事情,但它没有用.感谢您是否可以提供帮助.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <systemPropertyVariables>
        <browser>firefox, chrome</browser>
      </systemPropertyVariables>
      <parallel>tests</parallel>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

是否可以通过pom.xml配置实现这一目标?由于我的项目具有多模块特性,我并不热衷于使用testng.xml文件.

Roc*_*oon 0

您可以填充 *.properties 文件中的所有属性,然后将其与Properties Maven Plugin一起使用。QATools Properties将使它们在驱动程序配置期间易于使用。