簡體   English   中英

無法在Testng中的Dataprovider中發送String對象

[英]Unable to send String object in Dataprovider in testng

我試圖將記事本文件中的值提供給testng中的測試方法。

我在記事本文件中有多個值,例如

uname1 pwd1 uname2 pwd2等等...

我為DataProvider方法編寫了以下代碼

List<String> list=FileRead.doRead(); //This is method returning list of values from txt file
String[] array=list.toArray(new String[list.size()]);
String uname=null, pwd=null;
for (int x=0; x<array.length; x++)
{
    uname=array[x];
    pwd=array[x+1];
}
Object obj[][]={{uname, pwd}};      
return obj;

我想問一下我們是否可以將字符串對象傳遞給Object數組? 因為我在這上面出錯了。 如果可以,請告訴我。 我提到的方法也得到了ArrayIndexOutOfBounds。 我的測試方法具有以下代碼

@Test(dataProvider="mydp")
public void testCase1(String uname, String pwd) throws FileNotFoundException,
IOException
{
    getLoginDetails(uname, pwd);
}

請為我提供上述解決方案

謝謝你的時間。

您不應該使用String數組。 但是,真正的問題是1D數組,而不是2D數組。 此代碼會將其轉換為2D數組。

Object[] arr = FileRead.doRead().toArray();
Object[][] data = new Object[arr.length/2][2];
for (int x = 0; x < arr.length; x+=2){
   data[x/2][0]=arr[x];
   data[x/2][1]=arr[x+1];
}
return data;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM