0

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 .

autoD
  • 109
  • 2
  • 14
  • What do you have in @AfterTest? – niharika_neo Aug 06 '15 at 08:49
  • i have another method in aftertest, which i need to execute after each test – autoD Aug 07 '15 at 05:41
  • @AfterClass public void remove(){ driver.findElement(By.xpath("//span[contains(text(),'View')]")).click(); driver.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS); driver.findElement(By.xpath("//input[@id='remove-button-0']")).click(); driver.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS); System.out.println(" removed "); } – autoD Aug 07 '15 at 10:01

0 Answers0