簡體   English   中英

並行運行多個testng套件,每個套件具有不同的參數

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

我試圖與黃瓜並行運行具有不同參數的多個testng套件。每個tesng套件都試圖傳遞不同的瀏覽器,testinfo等。我想通過maven命令行選項來實現這一點。 我已經關注了https://rationaleemotions.wordpress.com/2016/03/29/parallel-execution-of-multiple-testng-suites/#comment-1723上的帖子。 我想做的是與不同的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和Chrometestrunner如下所示(FFtestng.xml和FFrunner與chrome類似,但套件/測試名稱有所不同)

<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命令行分別為每個測試傳遞測試級別信息。

我的疑問是我可能會像-Dbrowser =“ chrome”中那樣覆蓋JVM值,而被-Dbrowser =“ firefox”覆蓋

更多細節

我基本上是在嘗試並行使用Cucumber進行跨瀏覽器測試。在這種情況下,我基本上可以在單個套件中擁有3個測試標簽(每個用於chrome,ff,ie),但我關心的是如何傳遞瀏覽器,testinfo等參數(對於每個測試都是唯一的),這與-Dchrometest.browser =“ chrome”和-Dfirefoxtest.browser =“ firefox”類似。 現在我有3個批處理文件,每個瀏覽器並調用3個同時。 所以3個獨立的JVM實例。缺點是cpu利用率始終為100%,IE總是失敗

您與此問題相關的博客是由我創建的。

回到回答您的問題。 如果不添加一些丑陋的技巧,您所要求的是不可能的。 我之所以說不可能,是因為您需要確保套件的數量與JVM參數中以逗號分隔的值相匹配。

因此,假設您的線程數為2並且您通過JVM參數以逗號分隔的值傳入了兩種瀏覽器樣式,解析邏輯仍然無法區分是要檢索第一個值還是要獲取第二個值。檢索。

您可以采取的一種方法如下:

  1. 定義一個已同步且為單例的類。
  2. 調用此類時,基本上可以解析JVM參數(在這種情況下將傳遞瀏覽器樣式),並為每次調用返回一個瀏覽器值。 因此,如果要調用兩次,它將嘗試從已解析的JVM參數返回兩個值(以逗號分隔的值)。
  3. 現在,在您的套件中,您基本上只需查詢這個新的單例類。 因此,每次查詢都將返回獨特的瀏覽器風格。

我建議使用虛擬機執行此操作。 為每個不同的jvm參數集使用不同的虛擬機。 這應該簡化事情,因為每組功能都將被隔離

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM