在 testNG 运行测试用例时,我将测试结果记录到 DB。我正在使用 excel 表来提供输入数据。
例如:
tablename
row1 col1
row2 col2
tablename
我想知道,哪一行被执行?dataprovider 类中可能有任何函数将存储计数器。
请帮我获取计数器值。
提前致谢。
在 testNG 运行测试用例时,我将测试结果记录到 DB。我正在使用 excel 表来提供输入数据。
例如:
tablename
row1 col1
row2 col2
tablename
我想知道,哪一行被执行?dataprovider 类中可能有任何函数将存储计数器。
请帮我获取计数器值。
提前致谢。
不完全确定我是否得到您尝试做的事情;但是数据提供者很难让你得到你想要的信息。如果实现 ITestListener 接口,则可以直接访问方法参数。
@Override
public void onTestStart(ITestResult result)
{
Object[] params = result.getParameters();
}
You can do the following to get the information you want.
1) Create a dataprovider class that reads from excel sheet
You can use the jdbc:odbc driver to do the same or use Apache POI
In the same class, create a method to get the record count. The queries
you will be writing is simply the number of rows in the excel sheet.
1) Implement the iterator inteface
public class RecordIterator implements Iterator<Object>
{
private int iRecordCtr = 1;
public RecordIterator()
{
iRecordCount = dataProvider.getNoOfRecords();
}
//Override the hasNext()
public boolean hasNext() {
return (iRecordCtr <= iRecordCount);
}
//Override the next() in iterator interface
public Object next()
{
//Read the columns in excel sheet. In the DAO you return you can
//also set the value of the record you process.
return new Object[] { data }
}
}
public static RecordIterator getMyIteratorImpl(String worksheet)
{
return new RecordIterator(params);
}
In your test:
@Test(dataProvider-"mydataProvider")
public void test(Data dataobj) //Single row of the excel sheet is returned as java object and one row is returned at a time. Lazy loading
}
@DataProvider(name="mydataProvider")
public Iterator<?> getMyIterator()
{
return new RecordIterator(excelsheet name);
}