Thursday, October 14, 2010

Selenium RC : Using a spreadsheet with Selenium

Quite a lot of the work I've done with Selenium is very repetitive e.g. navigating to an application, logging in, doing some test and logging out.

It made sense to put this in some kind of spreadsheet where each line would have the application URL, login credentials (user field name, user name, password field name, password) and the name of the "Submit" button. Then do some application work perhaps and then logout.

The program could go through the spreadsheet row by row populating the values and then posting the page.

I put all the data into a csv file so I could use opencsv to read the rows.

The code looks something like:

CSVReader reader = new CSVReader(new FileReader("x.csv"));

while ((nextLine = reader.readNext()) != null)

if (!csvURL.equals("Exit"))
selenium = new DefaultSelenium( "localhost",


selenium.type(csvUserText, csvUser);
selenium.type(csvPasswordText, csvPassword);;


The code runs through the spreadsheet until it finds an "Exit" in the URL field.

populateParams looks like:

public void populateParams (String nextLine[])
csvURL = nextLine[1];
csvUserText = nextLine[2];
csvUser = nextLine[3];
csvPasswordText = nextLine[4];
csvPassword = nextLine[5];
csvSubmit = nextLine[6];


No comments: