【发布时间】:2019-06-30 14:25:25
【问题描述】:
我有发送多个测试和多个参数的 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)
我只想运行这个请求一次,它会刺激所有不同的参数并一次又一次地运行整个套装,并在同一个报告上给出结果。
这就是我所做的:
@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);
}
【问题讨论】:
-
您可以在其中添加您正在使用 offerId 参数的 testMethod 代码吗?
-
添加了java测试@SameerArora
-
@IdanShabat 让我知道答案是否对您有帮助 :)
-
嗨@SameerArora - 感谢您的意见,但这没有帮助。它确实从属性文件运行了测试,但我需要在同一个参数上多次运行相同的测试。当我向同一个参数添加不同的值时 - 它采用最新的并且不会运行两次。
标签: java testng testng.xml