Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara

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