如何将动态参数传递到testNG.xml来运行多个测试

问题描述 投票:0回答:2

我有发送多个测试和多个参数的xml套件。

示例:

        <test name="Create">       
        <classes>       
        <class name="TestClass">
            <methods>
                <parameter name="offerId" value="1234"/>
                <include name="testmethod"/>
            </methods>
        </class>                                          
      </classes>
      </test>
        <test name="Add">       
        <classes>       
        <class name="TestClass2">
            <methods>
                <include name="testmethod2"/>
            </methods>
        </class>                                          
      </classes>
      </test>

我需要多次使用不同的offerId参数运行该类。 (例如1234,4567,7899)

我只希望运行此请求一次,它将激怒所有不同的参数,并一次又一次运行whole suit,并在同一报告中给出结果。

这就是我所做的:

@Test
public void runSuites2(){

    TestNG testng = new TestNG();
    List<String> suites=new ArrayList<String>();
    suites.add("c:/tests/testng1.xml");//path to xml..

    testng.setTestSuites(suites);
    testng.run();

}

这样将加载并运行我需要的西装,但是如何在套件中更改参数?(之后,我将创建for循环)

[[目前,我复制了xml,并手动更改了每个测试的参数。然后运行套件套件]

测试:

@Parameters({ "offerId" })
@Test
public void testmethod(String offerId, ITestContext context) throws Exception {
    Reporter.log("offer ID is = " + offerId, true);
        }
java testng testng.xml
2个回答
1
投票

在这种情况下,您可以使用dataprovider或从excel读取值,并且将针对dataprovider / excel工作表中的每个值运行测试。提供一个示例,说明如何在测试用例中使用dataprovider。


0
投票

我知道这个答案有点晚了。但这可能对其他人有帮助,所以我将其发布。如果您喜欢我的答案,请投票。

© www.soinside.com 2019 - 2024. All rights reserved.