使用动态测试标签和参数测试NG Cucumber平行自动化



我当前正在使用TestNG并行在Cucumber中运行多个测试,我成功地完成了此操作。现在,我的要求是,而不是在带有不同参数的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());
    }

}

我很高兴找到了这篇文章。如果有人试图实现同一件事,非常有用。动态测试ng ialtersuitelistener

maven命令:> MVN编译测试-ddeviceflavors =" Google nexus 6"," Google Pixel" -ddeviceosflavors =" 6.0"," 7.1" -dsurefire.suitexmlfiles = testng.xml = testng.xml

最新更新