I have used @Dataprovider in testNG test case, what i need to do is take the data from excel and use that data wherever i need in my test.
@DataProvider(name="productdata")
public Object[][] productdata(){
Object[][] objectarray=getExcelData("C:/Documents/New Microsoft Excel Worksheet (3).xls","sheet1");
objectarray[0][0]="p";
objectarray[0][1]="url";
objectarray[0][2]="size";
}
//Reading excel sheet value
@SuppressWarnings({ "null", "resource" })
public String[][] getExcelData(String s2pproductprices, String sheet1) {
String[][] arrayExcelData = null;
try {
String Filepath = "C:/Documents and Settings/saalam/Desktop/Excel sheets/New Microsoft Excel Worksheet (3).xls";
FileInputStream file = new FileInputStream(Filepath);
HSSFWorkbook hw = new HSSFWorkbook(file);
HSSFSheet sheet = hw.getSheet("sheet1");
for (int i= 1 ; i < sheet.getLastRowNum(); i++) {
for (int j=0; j < 4; j++) {
arrayExcelData[i-1][j] = sheet.getRow(i).getCell(j).getStringCellValue();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
}
return arrayExcelData;
}
I had run this testng test case but its giving me error as below:
[TestNG] Running: C:\Documents \testng-eclipse--1785696757\testng-customsuite.xml
FAILED CONFIGURATION: @AfterTest
the path which is seen in the error doesn't match with the one provided in the code. can any one suggest me how this can be done or do i have to provide @parameters .