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)
{
populateParams(nextLine);
if (!csvURL.equals("Exit"))
{
selenium = new DefaultSelenium( "localhost",
4444,
"*iexplore",
csvURL);
selenium.start();
selenium.windowMaximize();
selenium.open(csvURL);
selenium.waitForPageToLoad("30000");
selenium.type(csvUserText, csvUser);
selenium.type(csvPasswordText, csvPassword);
selenium.click(csvSubmit);
selenium.waitForPageToLoad("30000");
...
}
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];
...
}
Enjoy!
No comments:
Post a Comment