18 February 2007

Basic Web Application Testing

I was looking for a free application test program to regression test software. Our tester suggested Watir for testing Web application using MSIE. Watir is based on Ruby, which would be a fun language to learn in the future. For the present, there's a Java version called Watij.

To start Watij, just unpack the archive, start a Cmd console and enter launchWatijBeanShell.bat (simply clicking on launchWatijBeanShell.bat in Explore doesn't work). A Java BeanShell console opens where you can interactively enter Java statements to start MSIE and execute commands. Here's a sample session to open a Google search page and make a query:

IE ie = new IE();
ie.start("http://www.google.com");
ie.textField(name, "q").set("Hello World");
ie.button(name, "btnG").click();

How do we find the controls on a Web page (e.g. the name of the query field)? If you use Chris Pederick's Firefox WebDeveloper add-in, select Forms / Display Form Details feature to see the attributes of each form's element.

Having made a query, we should verify that we get the expected result. For a simple test, we want to know if Wikipedia can be found in the search results. Here, I combined a Java if-else statement with BeanShell's print():

if (ie.containsText("Wikipedia")) {
  print("Yes");
} else {
  print("No");
}
Yes

Watij doesn't have a way to record events like WinRunner. Scott Hanselman has written WatirMaker but it doesn't look like it's quite ready for general use.

Last minute: FireWatir for Firefox is also available.