使用动态测试标签和参数测试NG黄瓜并行自动化

时间:2019-05-13 08:18:47

标签: cucumber testng testng-dataprovider

我目前正在尝试使用testng在黄瓜中并行运行多个测试,并且我成功地做到了这一点。 现在,我的要求不是从maven命令行在testNG文件中使用不同的参数使用多个Test TAGS。因此,无需编辑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());
    }


}

1 个答案:

答案 0 :(得分:0)

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

Maven命令:> mvn编译测试-DdeviceFlavors =“ Google Nexus 6”,“ Google Pixel” -DdeviceOsFlavors =“ 6.0”,“ 7.1” -Dsurefire.suiteXmlFiles = testng.xml