【问题标题】:Test NG Cucumber Parallel Automation with Dynamic test tags and param使用动态测试标签和参数测试 NG Cucumber 并行自动化
【发布时间】:2019-05-13 18:22:37
【问题描述】:

我目前正在寻找使用 testng 在黄瓜中并行运行多个测试,并且我成功地做到了。 现在我的要求是不要在 testNG 文件中使用不同参数的多个测试标签,而是从 maven 命令行获取它。所以我可以在不编辑 testNg.xml 文件的情况下进行自动化。有没有办法实现它?请找到我当前的 testng.xml 配置。

testng.xml

   <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng Cucumber Suite" thread-count="2"   parallel="tests">

<!--  In order to run test cases please copy and one test and add make sure you add relevant parameters -->
  <test name="Run_Nexus_06">
       <parameter name="deviceName" value="Google Nexus 6" />
            <parameter name="platformVersion" value="6.0" />
        <classes>
            <class name="cucumber.mobile.ParallelRunner">
            </class>
        </classes>

  </test>

    <test name="Run_Google_Pixel">
        <parameter name="deviceName" value="Google Pixel" />
        <parameter name="platformVersion" value="7.1" />
        <classes>
            <class name="cucumber.mobile.ParallelRunner">
            </class>
        </classes> 
    </test> 

</suite>

跑步者类:

@CucumberOptions(plugin = {"pretty", "html:target/html/", "json:target/cucumber.json", "junit:TEST-all.xml"},
        features = "src/test/resources/features/SignUp.feature", glue = {"steps"}, tags = {"@Mobile"})
public class ParallelRunner  extends Hook{

       List<Object[]> data;
    //<parameter name="deviceName" value="Google Pixel" />
   // <parameter name="platformVersion" value="7.1" />
    @BeforeTest
    @Parameters({"deviceName","platformVersion"})
    public void bb(String deviceName, String platformVersion){
        Device device = new Device();
        device.setDeviceName(deviceName);
        device.setOsVersion(platformVersion);
        DeviceFactory.setDevice(device);
        System.out.println("Device" + deviceName + "Os Version" + platformVersion + "   " + Thread.currentThread().getId());
    }


}

【问题讨论】:

  • 你想从 cmd 读取测试参数吗?像设备名称。这是您的要求还是您想从 cmd 传递 @CucumberOptions 标签。
  • @ThrSociety 没错。 (如 deviceName )所以每次我不需要手动更新我的 testNg.xml 文件。另外,我想把它带到 Jenkins 工作中,用户可以选择参数并动态传递给 TestNg 文件并执行
  • 谢谢,@TheSociety 我从另一篇文章中找到了解决方案 :-)

标签: cucumber testng testng-dataprovider


【解决方案1】:

我很高兴找到这篇文章。如果有人试图实现同样的目标,这将非常有用。 Dynamic Test ng IAlterSuiteListener

Maven 命令:> mvn compile test -DdeviceFlavors="Google Nexus 6","Google Pixel" -DdeviceOsFlavors="6.0","7.1" -Dsurefire.suiteXmlFiles=testng.xml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多