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

Answered

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;

    @BeforeClass
    public void setUp(){
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get(“https://www.google.co.in/”);
    driver.findElement(By.id(“gb_70”)).click();
    }

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

    driver.findElement(By.id(“Email”)).sendKeys(UserName);
    driver.findElement(By.id(“Email”)).clear();
    driver.findElement(By.id(“Passwd”)).sendKeys(Password);
    driver.findElement(By.id(“Passwd”)).clear();
    driver.findElement(By.id(“signIn”)).click();
    }

    @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;
    }

    @AfterClass
    public void tearDown(){
    driver.close();
    driver.quit();
    }

    }

    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) iterator.next();
    headerStringBuffer.append(cell + “|”);
    }

    System.out.println(headerStringBuffer);

    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++) {

    dataStringBuffer.append(“\n”);
    for (int cell = 0; cell < maxCellNum; cell++) {
    Object cellValue;
    if(hssfSheet.getRow(row).getCell(cell)!=null){
    cellValue = hssfSheet.getRow(row).getCell(cell);
    }else{
    cellValue=””;
    }

    Object cellValue1;
    if(hssfSheet1.getRow(row).getCell(cell)!=null){
    cellValue1 = hssfSheet1.getRow(row).getCell(cell);
    }else{
    cellValue1=””;
    }

    //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]);
    }
    }
    System.out.println(dataStringBuffer);
    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:
    http://stackoverflow.com/questions/25549443/testng-using-multiple-dataproviders-with-single-test-method

    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.