【发布时间】:2018-02-20 19:56:50
【问题描述】:
我想知道我们如何使用不同的数据集多次运行 testng xml。 我正在根据 testng xml 中存在的 testcaseno 参数从 excel 文件中获取数据,并且它按预期工作。现在我想通过对多组数据使用相同的 xml 文件来扩展我的测试。
testng.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Sample Test Suite 1">
<parameter name="browser" value="Firefox"/>
<parameter name="TestCaseNo" value="1"/>
<test name="Testcase1">
<classes>
<class name="packagename.ABCTest">
<methods>
<include name="method_A" />
<include name="method_B" />
<include name="method_C"/>
<include name="method_D"/>
</methods>
</class>
</classes>
</test>
</suite>
截至目前,我的 excel 实用程序正在从 testng xml 获取 testcaseno 值并获取与所需行对应的数据。 我想为 5 个测试用例运行相同的 testng xml。
请帮助我实现这一目标。 我可以根据测试用例编号实现调用计数吗,因为我依赖于 testng xml 中的参数来从 excel 中获取值。
提前致谢!
【问题讨论】:
-
@Yashica...使用
@DataProvider.. 发布您的代码,以便我可以告诉您如何实现相同 -
@GauravGenius,嗨 Gaurav,我正在使用 dataprovider 从 excel 中获取数据,我的 dataprovider 正在返回 hashmap
其中键是标题,值是这些标签的值。即 username=abc 以便用户可以根据键名获取列值。我想要的是:像这样为 testcase1,2,3,4 运行相同的 testngxml。 -
@DataProvider(name="getdata") public static Object[][] getData(ITestContext context) throws Exception { HashMap
ExcelDataMap= new HashMap (); String TestCaseNo = context.getCurrentXmlTest().getParameter("TestCaseNo"); ExcelDataMap=hashMap.get(TestCaseNo);返回新对象[][]{ {ExcelDataMap} }; } hashmap 包含整个 excel,其中键作为测试用例编号和相应的行值 -
我尝试使用 dataprovider 根据 testng xml 中指定的参数返回对象,但这种方式 @Test 注释是根据对象数量运行的。我想用一个参数运行整个测试套件一次,然后用第二个参数运行。我们可以这样做吗?