The line marked in star is giving error when the test is run in TestNG
Guys tell me what am I doing wrong in this.
I have attached the excel with 3 rows and 3 columns in 1st sheet.
Data lib code-
package Datalibrery;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Dataconfig {
XSSFWorkbook WB;
XSSFSheet sheet1;
public Dataconfig(String Excelpath){
try {
File src=new File(Excelpath);
FileInputStream fis=new FileInputStream(src);
WB=new XSSFWorkbook(fis);
sheet1=WB.getSheetAt(0);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
}
public String getData(int sheetno,int row,int col){
sheet1=WB.getSheetAt(sheetno);
**String data=sheet1.getRow(row).getCell(col).getStringCellValue();**
return data;
}
public int getRowCount(int sheetindex){
int row=WB.getSheetAt(sheetindex).getLastRowNum();
row=row+1;
return row;
}
}
Script Code-
package SampleTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import Datalibrery.Dataconfig;
public class ContactusDDT {
WebDriver driver;
@BeforeTest
public void beforeTest() {
// If the browser is Firefox, then do this
driver = new FirefoxDriver();
// Doesn't the browser type, lauch the Website
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void login(){
driver.get("Websit URL here");
driver.findElement(By.xpath("//*[@id='u157-4']/p")).click();// contact
}
@Test(dataProvider = "Contactdata")
public void testLogIn(String Harshal1, String harshalb ,String Hi) throws Exception {
driver.findElement(By.xpath("//*[@id='widgetu798_input']")).clear();
driver.findElement(By.xpath("//*[@id='widgetu798_input']")).sendKeys(Harshal1);
driver.findElement(By.xpath("//*[@id='widgetu783_input']")).clear();
driver.findElement(By.xpath("//*[@id='widgetu783_input']")).sendKeys(harshalb);
driver.findElement(By.xpath("//*[@id='widgetu791_input']")).clear();
}
@DataProvider(name = "Contactdata")
public Object[][] Testdata()
{
Dataconfig conf=new Dataconfig("C:\\Users\\harshadab\\workspace\\Sampledatadiven\\excelData\\Managemygrp.xlsx");
int rows=conf.getRowCount(0);
Object[][] data = new Object[rows][3];
for(int i=0;i<rows;i++)
{
***data[i][0]=conf.getData(1, i, 0);***
data[i][1]=conf.getData(1, i, 1);
data[i][2]=conf.getData(1, i, 2);
}
return data;
}
}
getData
method? Siraj has a potential solution for you, but it would be better to validate that against the parameters he's changing.