Why testNG @Test annotation is iterating for 4 times instead of 3 times with dataProvider parameter

Can anybody help me?

samba Train Asked on December 14, 2014 in Selenium WebDriver.

Hi
please give Some More Details..?

on December 14, 2014.

Either provide more details on this question or I will delete this question.

on December 15, 2014.

Dear Sir, Here I am writing all of my code,

This is my Util Class to read data from excel file and returning data


package com.syner.poi;
import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

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

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

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

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

import org.apache.poi.ss.usermodel.WorkbookFactory;
public class Util {

public static Object[][] readExcelData() throws InvalidFormatException, IOException

{

Object[][] data=new Object[4][2];

InputStream f=new FileInputStream("GmailTestData.xlsx");

Workbook workbook=WorkbookFactory.create(f);

Sheet sheet=workbook.getSheetAt(0);

int rc=sheet.getLastRowNum();

for(int i=0;i<rc;i++)

{

Row r=sheet.getRow(i+1);

int cc=r.getLastCellNum();

for(int j=0;j<cc;j++)

{

Cell c=r.getCell(j);

if(c.getCellType()==c.CELL_TYPE_STRING)

{

data[i][j]=c.getStringCellValue();

}

else if(c.getCellType()==c.CELL_TYPE_NUMERIC)

{

//data[i][j]=c.getNumericCellValue();

data[i][j]=new Long((long) c.getNumericCellValue());

}

System.out.println("Data: "+data[i][j]);
}

}
return data;
}
}

This is my ExcelFile class to get data from Util class and execute the tesecases.


package com.syner.poi;
import java.io.IOException;

import java.lang.annotation.Retention;

import java.lang.annotation.RetentionPolicy;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;
public class ExcelFile {

WebDriver driver;
@DataProvider(name="excelData")

public Object[][] readData() throws InvalidFormatException, IOException

{

return Util.readExcelData();

}
@BeforeMethod

public void setUp()

{

driver=new FirefoxDriver();

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

driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");

}
@Test(dataProvider="excelData")

public void testApp(String firstName,long mobileNumber)

{

driver.findElement(By.xpath(".//*[@id='FirstName']")).sendKeys(firstName);

driver.findElement(By.xpath(".//*[@id='RecoveryPhoneNumber']")).sendKeys(""+mobileNumber);

}
@AfterMethod

public void tearDown() throws InterruptedException

{

Thread.sleep(3000);

driver.close();

}
}

This is my  GmailTestdata excel file.
Why testNG @Test annotation is iterating for 4 times instead of 3 times with dataProvider parameter

When I execute the above code, it has to execute 3 times because GmailTestdata excel file having 3 recods but it is executing 4 times and for 4th time it is taking (null,null) as arguments.

Thanks & Regards
Samba.

on December 15, 2014.

Please close the question.

on December 16, 2014.
Add Comment
1 Answer(s)

Try changing this statement:

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

xLov3rDns Professor Answered on December 15, 2014.
Add Comment

Your Answer

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