简体   繁体   中英

Parallel cross browser testing with Selenium and TestNG without using testng.xml

I am using Maven Failsafe + TestNG to run Selenium tests. I know it is possible to pass parameters to my TestNG tests by defining system properties in pom.xml like this:

 <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>

My TestNG test refers this property like this:

@Parameters("browser")
public void setUpClass(@Optional("firefox") String browser)
{
   ...
}

However, I was wondering is it possible to run cross browser tests in parallel without a need to specify a testng.xml file. I was trying something like this but it didn't work. Appreciate if you can help.

 <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>

Is it possible to achieve this with just pom.xml configuration? Because of the multi-module nature of my project, I am not keen in using testng.xml file.

You may populate all properties in *.properties file and then use it with Properties Maven Plugin . QATools Properties will make easy to use them during drivers configuration.

You can run any TestNG test programmatically as well. Check here TestNG Running programmatically so from maven u just need to call your class with main method having the code to run testng programmatically and read whatever properties you wish from any source (csv, properties, xml, xlsx.,etc..)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM