'Data provider reading null cells , how do i handle it?
I'm trying to get the values from an excel sheet of 2 rows, the 1st row are the headings and the second row is the data, when I execute the code the 1st set of data is entered but, the next row which is empty is also being entered that has null values, don't know why the null value rows are being read.
The data driven approach code
public class DatadrivenTest {
static WebDriver dr;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver_win32 (2)\\chromedriver.exe");
dr = new ChromeDriver();
dr.get("https://testitecy.azurewebsites.net/JS/account/signUp");
dr.manage().window().maximize();
Xls_Reader reader = new Xls_Reader(
"C:\\Users\\hruda\\eclipse-workspace\\Itecy\\src\\com\\TestData\\ItecyJSRegistrationTestData.xlsx");
int rowCount = reader.getRowCount("Testdata");
for (int rowNum = 2; rowNum <= rowCount; rowNum++) {
String firstName = reader.getCellData("Testdata", "FirstName", rowNum);
System.out.println(firstName);
String lastName = reader.getCellData("Testdata", "LastName", rowNum);
String Ccode = reader.getCellData("Testdata", "CountryCode", rowNum);
String Contact = reader.getCellData("Testdata", "Contact Num", rowNum);
String Email = reader.getCellData("Testdata", "Email", rowNum);
String Pwd = reader.getCellData("Testdata", "Password", rowNum);
String Cpwd = reader.getCellData("Testdata", "C Password", rowNum);
String File = reader.getCellData("Testdata", "File", rowNum);
dr.findElement(By.xpath("//*[@id='FirstName']")).clear();
dr.findElement(By.xpath("//*[@id='FirstName']")).sendKeys(firstName);
dr.findElement(By.xpath("//*[@id='LastName']")).clear();
dr.findElement(By.xpath("//*[@id='LastName']")).sendKeys(lastName);
Select select = new Select(dr.findElement(By.xpath("//*[@id='CountryCode']")));
select.selectByVisibleText("+91");
dr.findElement(By.xpath("//*[@id='Contact']")).clear();
dr.findElement(By.xpath("//*[@id='Contact']")).sendKeys(Contact);
dr.findElement(By.xpath("//*[@id='EmailId']")).clear();
dr.findElement(By.xpath("//*[@id='EmailId']")).sendKeys(Email);
dr.findElement(By.xpath("//*[@id='Password']")).clear();
dr.findElement(By.xpath("//*[@id='Password']")).sendKeys(Pwd);
dr.findElement(By.xpath("//*[@id='ConfirmPassword']")).clear();
dr.findElement(By.xpath("//*[@id='ConfirmPassword']")).sendKeys(Cpwd);
dr.findElement(By.xpath("//*[@id='uploadResume']")).clear();
dr.findElement(By.xpath("//*[@id='uploadResume']")).sendKeys(File);
}
}
}
the rowcount code that has been used above
public int getRowCount(String sheetName) {
int index = workbook.getSheetIndex(sheetName);
if (index == -1)
return 0;
else {
sheet = workbook.getSheetAt(index);
int number = sheet.getLastRowNum();
return number;
}
}
Please help resolve the issue, can't find a solution anywhere!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|