简体   繁体   English

使用 Maven 同时在多个线程上运行单个 TestNG 测试

[英]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.我有一个测试,它进入测试页面并执行一些复杂的任务,如果测试失败并使用 OCR 工具执行进一步的任务,请稍等片刻然后截屏。 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.我希望同样的测试同时在 10 个 chrome 浏览器会话上运行,我们正在尝试使用它进行准负载测试,并且由于使用第三方库的测试已经足够复杂,因此使用 Jmeter 的 WebDriver 插件之类的东西看起来并不在这里可行。 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.无论如何,无论我尝试什么,测试似乎都在一个接一个地运行,而不是打开 10 个浏览器窗口并并行运行。 Here's what I've tried thus far from looking around the interwebs.这是我迄今为止尝试过的而不是环顾互联网的方法。

TestNG.xml route TestNG.xml 路由

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

did not work不工作

Maven route马文路线

Added the following in pom.xml在 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尝试了一些有点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.以上选项都没有让我在 chrome 浏览器上同时多次运行相同的测试。 Is there a better way of achieving it?有没有更好的方法来实现它?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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