0

I have a requirement to test the large list of webpages for specific website and have to verify i) if the content on all provided webpages is present or not? ii) the content is neither duplicated as well on that particular page.

I need to automate this using Selenium WebDriver (Java). I want that I just provide all the pages URL into an excel sheet (.csv file) and just run the test through it and get back the results for my requirements.

Please help me in this.

Thanks in advance..

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
user2767326
  • 1
  • 1
  • 1
  • what did you try so far? You could make a start and ask for specific help. For generic ideas programmers.. may be better site – Jayan Sep 11 '13 at 05:38
  • I've searched for different libraries to be imported yet. Just started with that. I am at beginner level and want to learn (taking that initiative myself to automate this) – user2767326 Sep 11 '13 at 07:24
  • You can use apache-poi to read excel files or [opencsv][1] for reading csv. [1]: http://opencsv.sourceforge.net/ – Jayan Sep 11 '13 at 07:30
  • thanks..will post further if facing any issues – user2767326 Sep 11 '13 at 07:43

1 Answers1

0

Maybe you can try with jxl libraries.

With Maven, that is the pom dependency:

<dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
    <artifactId>jxl</artifactId>
    <version>2.6.12</version>
</dependency>

In case of read username, password, ... you can use a bean like this:

import java.io.File;
import java.io.IOException;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 * 
 * This is a bean to easily get users data from an excel file.
 * 
 * @author Hector Flores - hectorfb@gmail.com
 * 
 */
public class ExcelUserBean {

private String filepath = null;
private Sheet sheet = null;

/**
 * Read an excel file with users
 * 
 * @param filepath
 * @throws IOException
 */
public ExcelUserBean(String filepath) throws IOException {
    this.filepath = filepath;
    // TestData td = new TestData("SignUpUsers.xls");
    getDatafromXL(this.filepath);
}

/**
 * Get ID counter from excel file
 * 
 * @param row
 *            (0 for column title, >0 for values)
 * @return
 */
public String getId(int row) {
    return sheet.getCell(0, row).getContents();
}

/**
 * Get email form excel file
 * 
 * @param row
 *            (0 for column title, >0 for values)
 * @return
 */
public String getEmail(int row) {
    return sheet.getCell(1, row).getContents();
}

/**
 * Get name form excel file
 * 
 * @param row
 *            (0 for column title, >0 for values)
 * @return
 */
public String getName(int row) {
    return sheet.getCell(2, row).getContents();
}

private void getDatafromXL(String filepath) throws IOException {
    File inputWorkbook = new File(filepath);
    Workbook w;
    try {
        w = Workbook.getWorkbook(inputWorkbook);
        // Get the first sheet
        sheet = w.getSheet(0);

    } catch (BiffException e) {
        e.printStackTrace();
    }
    }// End parseXLTestCase

}

Now in your test cases you can fill your bean

    ExcelUserBean userBean = new ExcelUserBean(FILEPATH);
    //ROWS
    int begin = PropertiesConfig.getUserExcelRowFrom(); <-- from
    int end = PropertiesConfig.getUserExcelRowTo();   <-- to

    for (int excelRow = begin; excelRow <= end; excelRow++) {

       driver.findElement(By.id("signfirstname")).sendKeys(userBean.getName(excelRow));
       driver.findElement(By.id("lastname")).sendKeys(userBean.getSurname(excelRow));
    }

Hope it helps!

Héctor Flores
  • 253
  • 2
  • 9