Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

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