Share
Go down
karthik palicherla
Posts : 2
Join date : 2015-01-29

Data provider passing arrays into another method

on Sat Mar 28, 2015 9:41 am
package RUF;
import java.awt.List;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Row;
import org.openqa.selenium.By;

import jxl.read.biff.BiffException;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;


public class DataProviderExample {

@Test(dataProvider="getData")
public void setData(Support1 sp1)
{
System.out.println(sp1.getUsername() + " " + sp1.getPassword());
}

@DataProvider(name = "getData")
public Object[][] getData() throws BiffException, IOException
{

       FileInputStream file1=new FileInputStream("C://Users//KARTHIK//Desktop//Desktop//Selenium//LoginDetails.xls");
//HSSFWorkbook workbook = new HSSFWorkbook(file1);
HSSFWorkbook workbook = new HSSFWorkbook(file1);
HSSFSheet sheet2 =  workbook.getSheetAt(0);
int rowCount = sheet2.getLastRowNum()+1;
    int colCount = sheet2.getRow(0).getLastCellNum();
    Object[][] obj = new Object[rowCount][colCount];
    int lastRowNumber = sheet2.getPhysicalNumberOfRows();
    ArrayList list = new ArrayList();
for (int i=0; i < rowCount ; i++)
{
Support1 sp1 = new Support1();
String username = sheet2.getRow(1).getCell(0).getStringCellValue();
String password = sheet2.getRow(1).getCell(1).getStringCellValue();

sp1.setUsername(username);
sp1.setPassword(password);
list.add(sp1);
System.out.println(list.size());
} // End of For Loop
for (int l = 0; l < lastRowNumber; l++) {
obj[l][0] = list.get(l);
}
return obj;
}
}




public class Support1 
{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}

Excel File Data

UnamePwd
kpalicheasdf
bpalukuradsfa
basahuasdfa
ragrandhasfa



Error Message: Data provider passing 2 parameters by setData is accepting 1.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum