哪个函数在testNG中为我提供了dataprovider循环计数器

哪个函数在testNG中为我提供了dataprovider循环计数器,testng,testng-dataprovider,Testng,Testng Dataprovider,在testNG运行测试用例时,我将测试结果记录到DB中。我正在使用excel工作表提供输入数据 例如: tablename row1 col1 row2 col2 tablename 我想知道,哪一行被执行?dataprovider类中可能有存储计数器的任何函数 请帮我得到计数器的值 提前谢谢。我不完全确定我是否明白你的意图;但数据提供者很难让您获得所需的信息。 如果要实现ITestListener接口,就可以直接访问方

在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);
}