Hi,
Can we pass array of string using dataprovider in testng.
In the following example how can we pass array of string in testDataProviderExample function.
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import jxl.*;
public class dataProviderExample {
@DataProvider(name = "DP1")
public Object[][] createData1() throws Exception{
Object[][] retObjArr=getTableArray("F:\\Selenium\\Test.xls",
"Global");
return(retObjArr);
}
@Test (dataProvider = "DP1")
public void testDataProviderExample(String IncludeTest,
String TestCaseName, String Description, String TimeStampUse) throws Exception {
//enter the movie title
System.out.println("IncludeTest:"+test[0][0].toString());
System.out.println("TestCaseName:"+test[0][1].toString());
System.out.println("Description:"+test[0][2].toString());
System.out.println("TimeStampUse:"+test[0][3].toString());
}
public String[][] getTableArray(String xlFilePath, String sheetName) throws Exception{
String[][] tabArray=null;
Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
Sheet sheet = workbook.getSheet(sheetName);
int startRow,startCol, ci,cj;
startRow=sheet.getRows();
startCol=sheet.getColumns();
tabArray=new String[startRow-1][startCol];
ci=0;
for (int i=1;i<startRow;i++,ci++){
cj=0;
for (int j=0;j<startCol;j++,cj++){
tabArray[ci][cj]=sheet.getCell(j,i).getContents();
}
}
return(tabArray);
}
}//end of class