Is it possible using two two excel file for executing a single testcase?


Respected All,

I have a problem, we can preform a data driven testing using single excel file but I want to perform data driven testing using two excel file for a single test case.

Till now I am not able to do so. please help me . It is very urgent.

Train Asked on November 13, 2014 in Selenium WebDriver.

Hello Biswajit

that’s really strange requirement i would say , why in any case you require test data from different excel sheet ?

always keep it simple:)

on November 14, 2014.
Add Comment
  • 2 Answer(s)
    Best answer

    Hello All,

    The problem solved with the help of my friends,

    Please follow the steps:-

    public class LoginGmail {

    public WebDriver driver;

    public void setUp(){
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    @Test(dataProvider = “login”)
    public void gmailLogin(String UserName, String Password){


    @DataProvider(name = “login”)
    publicĀ  Object[][] loginToGmail() throws IOException {
    System.out.println(new File(“.”).getAbsolutePath());
    Object[][] cellData = ExcelUtils.getInstance().readData(“src/Login.xls”, 0, “src/LoginPass.xls”, 0);
    System.out.println(“MMMMMM : ” + cellData);
    return cellData;

    public void tearDown(){


    and My Excel Utils is:-

    public class ExcelUtils {

    private static ExcelUtils excelUtils = new ExcelUtils();

    private ExcelUtils() {


    public static ExcelUtils getInstance() {

    return excelUtils;

    public Object[][] readData(String workbook, int sheet, String workbook1, int sheet1) throws IOException {
    Object[][] data = new Object[0][0];

    HSSFWorkbook hssfWorkbook = new HSSFWorkbook(new FileInputStream(new File(workbook)));
    HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(sheet);

    HSSFWorkbook hssfWorkbook1 = new HSSFWorkbook(new FileInputStream(new File(workbook1)));
    HSSFSheet hssfSheet1 = hssfWorkbook1.getSheetAt(sheet1);

    Row headerRow = hssfSheet.getRow(0);
    StringBuffer headerStringBuffer = new StringBuffer(“WorkBook Header\n”);
    for (Iterator<Cell> iterator = headerRow.iterator(); iterator.hasNext();) {
    Cell cell = (Cell);
    headerStringBuffer.append(cell + “|”);


    int maxRowNum = hssfSheet.getLastRowNum();
    int maxCellNum = headerRow.getLastCellNum();

    System.out.println(“Row Sise “+maxRowNum+” Clo Size “+maxCellNum);

    data = new Object[maxRowNum][maxCellNum+1];
    StringBuffer dataStringBuffer = new StringBuffer(“WorkBook Data\n”);

    for (int row = 1; row <= maxRowNum; row++) {

    for (int cell = 0; cell < maxCellNum; cell++) {
    Object cellValue;
    cellValue = hssfSheet.getRow(row).getCell(cell);

    Object cellValue1;
    cellValue1 = hssfSheet1.getRow(row).getCell(cell);

    //Object cellValue = hssfSheet.getRow(row).getCell(cell);

    dataStringBuffer.append(cellValue.toString() + “|”);
    data[row – 1][cell] = cellValue.toString();
    data[row – 1][cell+1] = cellValue1.toString();
    System.out.println(“ROW :”+(row-1)+”Col :”+cell +”Data : “+data[row – 1][cell]);
    return data;



    Train Answered on November 18, 2014.
    Add Comment

    Replying on it with assumption that you are using testng for making your test data driven.

    Per my knowledge I never face this kind of situation.
    For a single test method there areĀ not two dataprovider annotations.

    But there is a work around that I have found. I think that may help you:

    Train Answered on November 17, 2014.

    Hi Friend,

    Thank you for you help and I will proceed with the example and let you know the updated soon.

    on November 17, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.