Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Geting issues in identifying the elsements in webdriver
Fri Feb 17, 2017 4:41 pm by janbaskt

» WebDriver - why not to use a singlton for it?
Fri Feb 17, 2017 4:40 pm by janbaskt

» WebDriver session when using testng annotation to invoke driver instance
Fri Feb 17, 2017 4:39 pm by janbaskt

» Selenium fails to launch Chrome
Fri Feb 17, 2017 4:39 pm by janbaskt

» why do i get this error
Fri Feb 17, 2017 4:38 pm by janbaskt

» Selenium Tutorial
Thu Feb 16, 2017 5:21 pm by Rahul

» When to use Selenium IDE, RC and WebDriver
Mon Feb 13, 2017 2:35 pm by azharuddin

» How to integrate selenium with ZAPI-Zephyr
Sat Feb 11, 2017 2:25 am by gseera002c

» Selenium Webdriver
Sat Feb 04, 2017 6:47 pm by soumyamishrav@gmail.com

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Data provider passing arrays into another method

View previous topic View next topic Go down

Data provider passing arrays into another method

Post by karthik palicherla 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.

karthik palicherla

Posts : 2
Join date : 2015-01-29

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum