简体   繁体   中英

Running a single TestNG test on multiple threads simultaneously using Maven

Here's what I'm trying to do. I have a test that goes to the test page and perform some complex tasks, wait for a while and then take a screenshot if the test fails and uses OCR tool for further tasks. I want this same test to run on 10 chrome browser sessions simultaneously, we're trying to do a quasi load test with this and since the test is already complex enough using third party libraries, using something like WebDriver plugin for Jmeter doesn't look feasible here. In anycase, no matter what I try the test seems to run one after the other instead of opening 10 browser windows and running it in parallel. Here's what I've tried thus far from looking around the interwebs.

TestNG.xml route

<suite name="UI Tests" parallel="methods" preserve-order="true" thread-count="10">

did not work

Maven route

Added the following in pom.xml

...
<build>
 <plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M4</version>
    <configuration>
        <forkCount>10</forkCount>
        <reuseForks>true</reuseForks>
    </configuration>
  </plugin>
 </plugins>
</build>
...

tried something slightly hacky

Dataprovider route

Providing a unique data to the test so it can perhaps run the same test simultaneously but to no avail.

@DataProvider(name="Unique")
public static Object[][] unique(){
   return new Object[][] {
     {"someValue"},
     ....
     };
}

@Test(dataProvider="Unique")
public void test(String unique){
//test code
}

None of the above options have worked for me to run the same test multiple times simultaneously on chrome browser. Is there a better way of achieving it?

您是否尝试将 threadPoolSize 和 invocationCount 参数添加到 @Test 注释中?

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