Passing the data from excel using parameters is not working – pls help

package ddt1;

import java.io.FileInputStream;
import java.io.IOException;

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;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class DDT_Test {
WebDriver driver;
XSSFWorkbook wb;
XSSFSheet sh;
XSSFRow row;
int rowCount;
String username;
String password;
int rc;
int cc;
XSSFCell c1, c2;

@BeforeTest
public void setup()
{
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“https://www.makemytrip.com/”);
}

@Test(dataProvider=”testdata”)
public void setupdata(String uname, String upwd)
{
//Add the buttons program into the code
driver.findElement(By.xpath(“//*[@id=’ch_login_email’]”)).sendKeys(uname);//username
driver.findElement(By.xpath(“//*[@id=’ch_login_password’]”)).sendKeys(upwd);//password
driver.findElement(By.xpath(“//*[@id=’ch_login_btn’]”)).click();//login
System.out.println(“The title of the page is :” + driver.getTitle());
driver.findElement(By.xpath(“//*[@id=’ch_logged-in’]”)).click();//log out drop
driver.findElement(By.xpath(“//*[@id=’ch_logged-inlogout’]”)).click();//logout
System.out.println(“The title of the page is :” + driver.getTitle());
System.out.println(“Logged out successfully”);
}

@DataProvider(name=”testdata”)
public Object[][] TestData() throws IOException
{

driver.findElement(By.xpath(“//*[@id=’ch_login_icon’]”)).click();//login
System.out.println(“Enter username and password”);
FileInputStream fi = new FileInputStream(“D:\\swarupa\\codes\\MakeMyTrip.xlsx”);
wb = new XSSFWorkbook(fi);
sh = wb.getSheetAt(0);
rc = sh.getLastRowNum();
//rc = sh.getRows();
System.out.println(“The number of rows are : ” + rc);
row = sh.getRow(1);
cc = row.getLastCellNum();
System.out.println(“The number of rows are : ” + cc);

Object [][] passdata = new Object[rc][cc];
for(int i=1; i<rc; i++)
{
c1 = sh.getRow(i).getCell(0);
passdata[i][0] = c1.getStringCellValue();
System.out.println(“The data in row ” + i + ” and column [0] is : ” + passdata[i][0]);
c2 = sh.getRow(i).getCell(1);
passdata[i][1] = c2.getStringCellValue();
System.out.println(“The data in row ” + i + ” and column [1] is : ” + passdata[i][1]);
}
return passdata;
}

@AfterTest
public void close()
{
driver.close();
}
}

==============================

 

Passing the data from excel using parameters is not working - pls help

The data is in the image

It is printing the values on console from excel but it is not passing the data to the browser

output:

Enter username and password
The number of rows are : 2
The number of rows are : 3
The data in row 1 and column [0] is : swarupa692@gmail.com
The data in row 1 and column [1] is : swarupa@692
FAILED: setupdata

Data provider mismatch
Method: setupdata([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [null,null,null]

Default test
Tests run: 1, Failures: 1, Skips: 0

 

Pls help me

Default Asked on July 23, 2017 in Selenium WebDriver.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.