运行 并行的多个 testng 套件,每个套件都有不同的参数

Running Multiple testng suites in parallel with different parameters for each of those suites

我正在尝试 运行 多个 testng 套件并行使用不同的参数 cucumber.With 每个 tesng 套件都试图通过不同的浏览器,testinfo 等 forth.I 想实现这个通过 maven 命令行选项。 我关注了 https://rationaleemotions.wordpress.com/2016/03/29/parallel-execution-of-multiple-testng-suites/#comment-1723 上的 post。我想做的是 运行 套件与不同的 JVM 参数集并行。

我尝试了以下方法来实现相同的目的,这只会启动一个 firefox 浏览器来执行测试并完全忽略 chrome 浏览器(甚至 运行 顺序)

mvn verify  -Dcucumber.options="--tags @123" -DGrid="false" -Dbrowser="chrome" 
-Durl="https://abc.xyz.com" -Dtestinfo="R3.0-Regression-chrome" -DNewuser="123test1"  
-DsuiteXmlFile=Chrometestng.xml,-Dcucumber.options="--tags @123" -DGrid="false" 
-Dbrowser="firefox" -Durl="https://abc.xyz.com" -Dtestinfo="R3.0-Regression-FF" 
-DNewuser="123test2" -DsuiteXmlFile=FFtestng.xml  -Dthreads=2

我的必火如下

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
    <testFailureIgnore>true</testFailureIgnore>
    <suiteXmlFiles>
        <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
    </suiteXmlFiles>
    <skipTests>false</skipTests>
    <properties>
        <property>
            <name>suitethreadpoolsize</name>
            <value>${threads}</value>
        </property>
    </properties>
</configuration>

我的testNg如下

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>

我的 chrometestng.xml 和 Chrometest运行ner 如下(FFtestng.xml 和 FF运行ner 类似于 chrome 除了 suite/test姓名)

<suite name="ChromeSuite" parallel="false">
<test name="ChromeTest">
    <classes>
        <class name="abc.runner.ChromeTestRunner"></class>
    </classes>
</test> <!-- Test -->

  @RunWith(ExtendedCucumber.class)
  @ExtendedCucumberOptions(
    jsonReport = "target/cucumber.json",
    detailedReport = true,
    jsonUsageReport = "target/cucumber-usage.json",
    toPDF = true,
    excludeCoverageTags = {"@flaky" },
    includeCoverageTags = {"@passed" },
    reportPrefix = "abc_Report",
   outputFolder = "abc_Reports/PDFReports/${testinfo}/DATE(yyyy-MM-dd-HH-mm-SS)/")
@CucumberOptions(plugin = { /*"html:target/cucumber-html-report",*/
    "json:target/cucumber.json"/*, "pretty:target/cucumber-pretty.txt",
    "usage:target/cucumber-usage.json", "junit:target/cucumber-results.xml"*/ },
    features={"src/test/resources/featurefiles"},strict = false, dryRun=false,
    glue = {"abc_stepdefinitions"},
    tags = {"@123"})
@Test
public class ChromeTestRunner extends ExtendedTestNGRunner {    
}

当我尝试这个时

mvn verify DsuiteXmlFile=Chrometestng.xml,FFtestng.xml -Dthreads=2

它至少会同时启动两个 chrome 浏览器。

我想弄清楚我的方法有什么不正确的地方,以及实现这个目标的正确方法是什么。如果这不可能,有没有一种方法可以让我在一个套件中拥有多个测试标签(chrome/ff/ie),并通过 Maven 命令行为每个测试分别传递测试级别信息。

我怀疑我可能会覆盖 JVM 值,如 -Dbrowser="chrome",被 -Dbrowser="firefox"

覆盖

更多详情

我基本上是在 parallel.In 中尝试使用黄瓜进行跨浏览器测试,在这种情况下,我基本上可以在单个套件中拥有 3 个测试标签(每个标签用于 chrome,ff,ie),但是我的关注的是如何从 maven 命令行分别传递浏览器、testinfo(每个测试唯一的)等参数。将类似于 -Dchrometest.browser="chrome" 和 -Dfirefoxtest.browser="firefox"在这里工作。现在我为每个浏览器都有 3 个批处理文件并同时调用 3 个。所以 3 个单独的 JVM instance.Downside 是 cpu 利用率总是 100% 并且 IE 总是失败

你链接到这个问题的博客是我创建的。

回来回答你的问题。如果不进行一些丑陋的黑客攻击,您的要求是不可能的。 我之所以说这是不可能的,是因为您需要确保套件的数量与作为 JVM 参数一部分的逗号分隔值相匹配。

所以假设你的线程数是 2 并且你通过 JVM 参数将两种浏览器风格作为逗号分隔值传递,解析逻辑仍然无法区分第一个值是检索或是否要检索第二个值。

您可以采用的一种方法如下:

  1. 定义一个class,它是同步的并且是一个单例。
  2. 这个 class 在被调用时基本上能够解析 JVM 参数(在这种情况下传递的浏览器风格)并且 return 为每次调用返回一个浏览器值。因此,如果它被调用两次,它将尝试 return 从已解析的 JVM 参数(逗号分隔值)中返回两个值。
  3. 现在在您的套件中,您基本上只需查询这个新的单例 class。所以每次查询都会 return 返回一个独特的浏览器风格。

我建议使用虚拟机执行此操作。为每组不同的 jvm 参数使用不同的虚拟机。这应该会简化事情,因为每组功能都将被隔离