Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» why do i get this error
Sun Apr 23, 2017 9:43 pm by anbarasi

» wait property
Sun Apr 23, 2017 12:50 pm by anbarasi

» What is the use of Selenium Remote Control
Fri Apr 21, 2017 7:24 pm by azharuddin

» How can I fix it? TCP PORT Exhaustion
Wed Apr 19, 2017 3:29 pm by JohnSnow

» Difference between QTP, Selenium and Silk test
Wed Apr 19, 2017 2:30 pm by Basilios Will

» Locator for google document
Tue Apr 18, 2017 10:01 pm by SergeyK

» I encountered a mistake: Couldn't register this node
Sat Apr 15, 2017 9:06 pm by skyshine725

» Current version tutorial for just creating a browser instance - Visual Studio
Fri Apr 14, 2017 2:47 am by KilpAr

» cant able to select drop down otions
Thu Apr 13, 2017 6:08 pm by anbarasi

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