我正在使用 TestNG 进行硒测试。有一个名为“创建公司”的测试需要在我的笔记本电脑上运行多次。
所以我为此编写了一个名为“CreateFirm”的类,各种公司的数据都保存在一个 Excel 电子表格中。
在不同的时间,我需要创建各种公司集,我使用 Excel 电子表格中的一列来控制它们,其中包含我的计算机名称。
我使用@Factory 创建我的“CreateFirm”类,它有一个@Test 方法来创建一个公司。
在 excel 电子表格中如果我以相同的顺序将 Firm1、Firm2、Firm3、Firm4 分配给我的笔记本电脑,@Factory 会以随机顺序创建它们,例如 Firm4、Firm3、Firm1、Firm2
我的问题是如何让@Factory 按我想要的顺序创建测试实例?
我的@Factory 方法是
@Factory
public Object[] runCreateFirm()
{
//This is where I get the list of test cases assigned to my laptop
this.test_id_list=get_test_ids_for_test_run("Create Firm (class approach).xls", "Global");
Object[] result = new Object[this.test_id_list.size()];
int index=0 ;
for (String firm_id: this.test_id_list)
{
//This is where I get all the test data from the Excel spreadsheet
HashMap<String,String> test_data_row=this.get_row_from_excel("Create Firm (class approach).xls", "Global", "test_case_id", firm_id);
System.out.println("Inside Firm Factory ,index="+index +", test case id="+ test_data_row.get("test_case_id"));
//CreateFirm is the class which will use the data and do all the UI actions to create a Firm
result[index]=new CreateFirm(test_data_row);
index++;
}
return result;
}
XML 是
<?xml version="1.0" encoding="UTF-8"?>
<suite name="CreateFirm Suite">
<test name="Create Firm Test" order-by-instances="false">
<classes>
<class name="regressionTests.factory.CreateFirmFactory"/>
</classes>
</test>
</suite>