POM , excel data returning null data in DataProvider

67 views
Skip to first unread message

Rashmi Upari

unread,
Jan 29, 2019, 11:44:56 PM1/29/19
to Selenium Users
Hi,
I am trying to pass data from excel to DataProvider using PageObjectModel but null data is getting passed
Attached is excel file and error screenshot, please let me know where i m going wrong.

Here is the Locators, Actions, Excel read and Main codes
LOCATORS
package locators;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class locators 
{
public static WebElement reg_click(WebDriver driver)
{
WebElement reg_btn = driver.findElement(By.xpath("//*[@id=\"wrapper\"]/div[1]/div[1]/div[2]/div/span[2]/a"));
return reg_btn;
}
//*****************Personal details**************************//
public static WebElement FirstName(WebDriver driver)
{
WebElement FN = driver.findElement(By.id("input-firstname"));
return FN;
}
public static WebElement LastName(WebDriver driver)
{
WebElement LN = driver.findElement(By.id("input-lastname"));
return LN;
}
public static WebElement Email(WebDriver driver)
{
WebElement email = driver.findElement(By.id("input-email"));
return email;
}
public static WebElement TeleNum(WebDriver driver)
{
WebElement telephone = driver.findElement(By.id("input-telephone"));
return telephone;
}
public static WebElement FaxNum(WebDriver driver)
{
WebElement fax = driver.findElement(By.id("input-fax"));
return fax;
}
//*********************************************************************//
//************************Address*************************************//
public static WebElement companyname(WebDriver driver)
{
WebElement name = driver.findElement(By.id("input-company"));
return name;
}
public static WebElement Address1(WebDriver driver)
{
WebElement Add1 = driver.findElement(By.id("input-address-1"));
return Add1;
}
public static WebElement Address2(WebDriver driver)
{
WebElement Add2 = driver.findElement(By.id("input-address-2"));
return Add2;
}
public static WebElement City(WebDriver driver)
{
WebElement City = driver.findElement(By.id("input-city"));
return City;
}
public static WebElement PostalCode(WebDriver driver)
{
WebElement Postcode = driver.findElement(By.id("input-postcode"));
return Postcode;
}
public static WebElement Country(WebDriver driver)
{
WebElement country = driver.findElement(By.id("input-country"));
return country;
}
public static WebElement State(WebDriver driver)
{
WebElement state = driver.findElement(By.id("input-zone"));
return state;
}
//**********************************************************************

//***********Password***************************************************
public static WebElement pwd(WebDriver driver)
{
WebElement pwd = driver.findElement(By.id("input-password"));
return pwd;
}
public static WebElement repwd(WebDriver driver)
{
WebElement repwd = driver.findElement(By.id("input-confirm"));
return repwd;
}
//**********************************************************************
public static WebElement continue_btn(WebDriver driver)
{
WebElement continue_btn = driver.findElement(By.xpath("//*[@id=\"content\"]/form/div/div/input"));
return continue_btn;
}
//*********************************************************************
public static WebElement catalog_kurti(WebDriver driver) throws Throwable
{
WebElement catalog = driver.findElement(By.xpath("//*[@id=\"wrapper\"]/div[2]/div[2]/div/div/ul/li[2]/a"));
Actions menu = new Actions(driver);
menu.moveToElement(catalog).build().perform();
Thread.sleep(1000);
//Click on submenu Kurti
WebElement kurti_click = driver.findElement(By.xpath("//*[@id=\"wrapper\"]/div[2]/div[2]/div/div/ul/li[2]/ul/li[1]/a/span"));
return kurti_click;
}
public static WebElement kurti_select(WebDriver driver)
{
WebElement kurti = driver.findElement(By.xpath("//*[@id=\"content\"]/div[4]/div/div[4]/div/div[1]/a/img"));
return kurti;
}
public static WebElement kurti_size(WebDriver driver)
{
WebElement sizeofkurti=driver.findElement(By.id("input-option333"));
return sizeofkurti;
}

public static WebElement kurti_qty(WebDriver driver)
{
WebElement qty = driver.findElement(By.id("input-quantity"));
return qty;
}

public static WebElement addtocart(WebDriver driver)
{
WebElement cart = driver.findElement(By.id("button-cart"));
return cart;
//cart.click();
}
}



ACTIONS
package actions;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

import locators.locators;

public class actions 
{
static WebDriver driver;
public static void register(WebDriver driver)
{
locators.reg_click(driver).click();
}
public static void firstname(String firstname)
{
locators.FirstName(driver).sendKeys(firstname);
System.out.println("Actions call " +firstname);
}
public static void lastname(WebDriver driver, String lastname)
{
locators.LastName(driver).sendKeys(lastname);
}
public static void email(WebDriver driver, String email)
{
locators.Email(driver).sendKeys(email);
}
public static void telephone(WebDriver driver, String telenum)
{
locators.TeleNum(driver).sendKeys(telenum);
}
public static void fax(WebDriver driver, String faxnum)
{
locators.FaxNum(driver).sendKeys(faxnum);
}
//****************************************************************************
//**********************Company details*****************************
public static void companyname(WebDriver driver, String companyname)
{
locators.companyname(driver).sendKeys(companyname);
}
public static void Add1(WebDriver driver, String Add1)
{
locators.Address1(driver).sendKeys(Add1);
}
public static void Add2(WebDriver driver, String Add2)
{
locators.Address2(driver).sendKeys(Add2);
}
public static void City(WebDriver driver, String city)
{
locators.City(driver).sendKeys(city);
}
public static void Postcode(WebDriver driver, String postalcode)
{
locators.PostalCode(driver).sendKeys(postalcode);
}
public static void Country(WebDriver driver, String country) throws Throwable
{
Select a = new Select(locators.Country(driver));
a.selectByVisibleText(country);
Thread.sleep(1000);
}
public static void State(WebDriver driver, String state)
{
Select b = new Select(locators.State(driver));
b.selectByVisibleText(state);
}
//***********************************************************************

//*************Password*************************************************
public static void password(WebDriver driver, String pwd)
{
locators.pwd(driver).sendKeys(pwd);
}
public static void reenter_pwd(WebDriver driver, String repwd)
{
locators.repwd(driver).sendKeys(repwd);
}
//*******************************************************************
public static void hit_continue(WebDriver driver)
{
locators.continue_btn(driver).click();
}
//*****************************************************************
public static void catalog(WebDriver driver) throws Throwable
{
locators.catalog_kurti(driver).click();
}
public static void select_kurti(WebDriver driver)
{
locators.kurti_select(driver).click();
}
public static void select_kurti_size(WebDriver driver, String size)
{
Select a = new Select(locators.kurti_size(driver));
a.selectByVisibleText(size);
}
public static void qty_kurti(WebDriver driver, String qty)
{
locators.kurti_qty(driver).clear();
locators.kurti_qty(driver).sendKeys(qty);
}
public static void addtocart(WebDriver driver)
{
locators.addtocart(driver).click();
}
}


EXCELDATA

package exceldata;


import java.io.FileInputStream;


import org.apache.poi.ss.usermodel.DataFormatter;


import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class excel_data

{

public static  Object[][] readdata() throws Throwable

{

FileInputStream input_file = new  FileInputStream("/Users/rashmimohan/Desktop/Selenium_IDE/TestData_RumasCollection.xlsx");

XSSFWorkbook workbook = new XSSFWorkbook(input_file);

XSSFSheet sheet = workbook.getSheet("Sheet 1");

int rowCount = sheet.getLastRowNum();

         int column = sheet.getRow(0).getLastCellNum();

         System.out.println(rowCount);//2

         System.out.println(column);//17

DataFormatter d = new DataFormatter();

int row=2, col=1;

Object[][] data = new Object[3][17];

for( row=2;row<=2;row++)

{

for( col=1;col<=16;col++)

{

System.out.println("COL FOR LOOP  " +row  +"  " +col);

data[row][col] = d.formatCellValue(sheet.getRow(row).getCell(col));

 

System.out.println(data[row][col]);

}

//System.out.println("data within loop" +data[row][col]);

}

//System.out.println("Data from excel  " +data);

return data;

}

}


MAIN

package main;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.BeforeTest;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;


import exceldata.excel_data;


public class main 

{

public String baseurl ="http://rumascollection.com.sg/standout";

static WebDriver driver;

@BeforeTest

public void  browseropen() 

{

System.setProperty("webdriver.chrome.driver", "/Users/rashmimohan/Desktop/Selenium_IDE/chromedriver");

driver = new ChromeDriver();

driver.get(baseurl);

driver.manage().window().maximize();

}

@Test(dataProvider="getdata_fromexcel")

public static void actionmethods(String firstname, String lastname, String email, String telenum, String faxnum, String companyname, String Add1, String Add2, String city, String postalcode, String country, String state, String pwd, String repwd, String size, String qty) throws Throwable

{

System.out.println("*******************");

actions.actions.register(driver);

System.out.println(firstname);

actions.actions.firstname(firstname);

System.out.println("&&&&&");

System.out.println(firstname);

actions.actions.lastname(driver,lastname);

actions.actions.email(driver, email);

actions.actions.telephone(driver, telenum);

actions.actions.fax(driver, faxnum);

actions.actions.companyname(driver, companyname);

actions.actions.Add1(driver, Add1);

actions.actions.Add2(driver, Add2);

actions.actions.City(driver, city);

actions.actions.Postcode(driver, postalcode);

actions.actions.Country(driver, country);

Thread.sleep(1000);

actions.actions.State(driver, state);

actions.actions.password(driver, pwd);

actions.actions.reenter_pwd(driver, repwd);

actions.actions.hit_continue(driver);

actions.actions.catalog(driver);

actions.actions.select_kurti(driver);

actions.actions.select_kurti_size(driver, size);

actions.actions.qty_kurti(driver, qty);

actions.actions.addtocart(driver);

}  

@DataProvider

public Object[][] getdata()

{

Object[][] data = new Object[1][16];

data[0][0]="FirstName1";

data[0][1]="LastName1";

data[0][2]="xyz...@gmail.com";

data[0][3]="22222222";

data[0][4]="3333333";

data[0][5]="CompanyName";

data[0][6]="Add1";

data[0][7]="Add2";

data[0][8]="Mangalore";

data[0][9]="575003";

data[0][10]="India";

data[0][11]="Karnataka";

data[0][12]="Password";

data[0][13]="Password";

data[0][14]="S";

data[0][15]="4";

return data;

}

@DataProvider

public  Object[][] getdata_fromexcel() throws Throwable 

{

Object[][] data1 =excel_data.readdata();

System.out.println("data passed is " +data1);

return data1;

}

}

TestData_RumasCollection.xlsx
Screenshot 2019-01-30 at 10.13.55 AM.png

rarunp04

unread,
Jan 30, 2019, 12:39:27 AM1/30/19
to seleniu...@googlegroups.com
From the attached screenshot of error you have received , I can see that the parameters are mismatching.
Being said that , the parameters you pass in the dataprovider Test should be same as the text being present in excel .

Example : First Point - In excel sheet , can see S.No - this your not passing in the dataprovider - hence remove this.
Second Point - The names provided in excel sheet should match - the names given in the dataprovider method 
excel you have provided - Email but in dataprovider method it is email . 
Please pass the text exactly as in Excel Sheet


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/fa2588d4-8d8d-41da-bcc1-785346f5f502%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rashmi Upari

unread,
Jan 30, 2019, 1:24:44 AM1/30/19
to Selenium Users
i implemented both of your points but getting same error

Rashmi Upari

unread,
Jan 30, 2019, 6:57:35 AM1/30/19
to Selenium Users
I did few changes in my excel data class and now getting new error (attached)
Please help me to resolve this..

package exceldata;

import java.io.FileInputStream;

import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class excel_data
{
public static  Object[][] readdata() throws Throwable
{
FileInputStream input_file = new  FileInputStream("/Users/rashmimohan/Desktop/Selenium_IDE/TestData_RumasCollection.xlsx");

XSSFWorkbook workbook = new XSSFWorkbook(input_file);

XSSFSheet sheet = workbook.getSheet("Sheet 1");

//DataFormatter d = new DataFormatter();

int row,col;
int rowCount = sheet.getLastRowNum();
        int column = sheet.getRow(0).getLastCellNum();
        System.out.println(rowCount);
        System.out.println(column);
Object[][] data = new Object[rowCount][column];

for(row=2;row<3;row++)

{
XSSFRow row1 = sheet.getRow(row);
for(col=0;col<=15;col++)

{

System.out.println("COL FOR LOOP  " +row  +"  " +col);

// data[row][col] = d.formatCellValue(sheet.getRow(row).getCell(col));
XSSFCell cell = row1.getCell(col);
                 DataFormatter formatter = new DataFormatter();
                 String val = formatter.formatCellValue(cell);
                 data[row - 2][col] = val;
 

System.out.println(data);

//System.out.println(data);

//return data;

}

//System.out.println("data within loop" +data[row][col]);

}

//åSystem.out.println("Data from excel  " +data);

return data;
}
}


On Wednesday, 30 January 2019 11:09:27 UTC+5:30, rarunp04 wrote:
Screenshot 2019-01-30 at 5.26.39 PM.png

rarunp04

unread,
Jan 30, 2019, 7:10:27 AM1/30/19
to seleniu...@googlegroups.com
I did check your code , and found below changes to be done :

1. In Main method : you have not given the dataprovider name . Also please change the column name Reset Password without space (to have ResetPassword)
2. In Actions method for the first name pass the Webdriver argument as you did for other locators

Please check the Main method and excel data methods and please compare


Excel Method:
package exceldata;

import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import main.main;

public class excel_data {

public static void main(String[] args) throws Throwable {
readdata();
}

public static Object[][] readdata() throws Throwable {
FileInputStream input_file = new FileInputStream("C:\\Users\\araja1\\Downloads\\TestData_RumasCollection.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(input_file);
XSSFSheet sheet = workbook.getSheet("Sheet1");
int rowCount = sheet.getLastRowNum();
int column = sheet.getRow(0).getLastCellNum();
System.out.println(rowCount);// 1
System.out.println(column);// 16

DataFormatter d = new DataFormatter();
int row = 2, col = 1;
Object[][] data = new Object[2][16];

for (row = 1; row <= 1; row++) {
for (col = 0; col < 16; col++) {
System.out.println("COL FOR LOOP  " + row + "  " + col);
data[row][col] = d.formatCellValue(sheet.getRow(row).getCell(col));
System.out.println(data[row][col]);
}
}
return data;
}
}

Main Method:

package main;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import exceldata.excel_data;

public class main {

public String baseurl = "http://rumascollection.com.sg/standout";
static WebDriver driver;

@BeforeTest
public void browseropen() {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
driver = new ChromeDriver();
driver.get(baseurl);
driver.manage().window().maximize();
}

@Test(dataProvider = "getdata")
public static void actionmethods(String FirstName, String LastName, String Email, String Telephone, String Fax,
String Company, String Address1, String Address2, String City, String PostalCode, String Country,
String State, String Password, String ReconfirmPassword, String Size, String Quantity) throws Throwable {

System.out.println("*******************");
actions.actions.register(driver);
actions.actions.firstname(driver, FirstName);
actions.actions.lastname(driver, LastName);
actions.actions.email(driver, Email);
actions.actions.telephone(driver, Telephone);
actions.actions.fax(driver, Fax);
actions.actions.companyname(driver, Company);
actions.actions.Add1(driver, Address1);
actions.actions.Add2(driver, Address2);
actions.actions.City(driver, City);
actions.actions.Postcode(driver, PostalCode);
actions.actions.Country(driver, Country);

Thread.sleep(1000);
actions.actions.State(driver, State);
actions.actions.password(driver, Password);
actions.actions.reenter_pwd(driver, ReconfirmPassword);
actions.actions.hit_continue(driver);
actions.actions.catalog(driver);
actions.actions.select_kurti(driver);
actions.actions.select_kurti_size(driver, Size);
actions.actions.qty_kurti(driver, Quantity);
actions.actions.addtocart(driver);
}

@DataProvider(name = "getdata")

Serguei Kouzmine

unread,
Feb 1, 2019, 12:44:25 AM2/1/19
to Selenium Users
@Rashmi
You can use Excel datapaprovicers to parameterize testng or junit tests

Rashmi Upari

unread,
Feb 3, 2019, 11:28:08 PM2/3/19
to Selenium Users
Hi,
I resolved this with simple change in excel class

Object[][] data = new Object[1][17];

for( int row=0;row<=1;row++)

{

for( int col=1;col<=16;col++)

{

System.out.println("COL FOR LOOP  " +row  +"  " +col);

data[row][col] = d.formatCellValue(sheet.getRow(row+2).getCell(col));

 

System.out.println(data[row][col]);

Rahul Gudi

unread,
Feb 4, 2019, 12:31:33 AM2/4/19
to seleniu...@googlegroups.com
When writing code in eclispe selenium webdriver shows the methods it is not showing for me. What should I do?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Rashmi Upari

unread,
Feb 4, 2019, 5:06:38 AM2/4/19
to Selenium Users
Which method??
can you please post your query clearly??

Thanks

Rahul Gudi

unread,
Feb 4, 2019, 11:02:55 AM2/4/19
to seleniu...@googlegroups.com
When you write invoke method in eclipse for example if you type driver. It show list of methods for that in eclipse.

Sent from my iPhone

sachin patil

unread,
Feb 4, 2019, 11:17:34 AM2/4/19
to seleniu...@googlegroups.com
Hello Rahul, 


Please check whether you have provided correct Jar/Dependency for the same.



Thanks 

Rahul Gudi

unread,
Feb 4, 2019, 11:20:40 AM2/4/19
to seleniu...@googlegroups.com
Will check 

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages