1

testNG がテストケースを実行している間、テスト結果を DB に記録しています。入力データを提供するためにExcelシートを使用しています。

例:

tablename

       row1 col1
       row2  col2   
                  tablename

知りたいのですが、どの行が実行されていますか? カウンターを格納する dataprovider クラスの関数が存在する可能性があります。

カウンター値を取得するのを手伝ってください。

前もって感謝します。

4

2 に答える 2

0

あなたがやろうとしていることを私が理解しているかどうかは完全にはわかりません。しかし、データプロバイダーは、あなたが望む情報を取得することをほとんど許可できません. ITestListener インターフェイスを実装する場合は、メソッド引数に直接アクセスできます。

@Override
public void onTestStart(ITestResult result)
{
    Object[] params = result.getParameters();
}
于 2015-01-09T09:22:55.227 に答える
0
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);
}
于 2016-12-13T23:21:25.050 に答える