Web Application Testing Using WatiN
Uncategorized February 28th, 2009Yestarday I was looking for a way to test a web application having hundred of links that have a certain structure. After a question on StackOverflow I got the same answer a colleague of mine already had given, WatiN. WatiN enables you to open a certain web page in Internet Explorer or Firefox and interacting with the web page though code (like clicking, entering text in controls, …).
In my Unit Test Project (VS2008) I used Internet Explorer as this development is a little bit ahead of the Firefox development. To create cross browser WatiN tests, check this link. I’ll try to port my project to cross browser testing later.
There’s also a WatiN Test Recorder. The next Release of this looks very promising!
Here’s an example how you get started by opening an Internet Explorer Window and go to a certain web page.
1 | IE ie = new IE("www.google.be"); |
Check if the page contains a certain text:
1 | Assert.IsTrue(ie.ContainsText("...")); |
To find a link and click on it:
1 | ie.Link(Find.ByText("...")).Click(); |
Search for a certain TableCell:
1 | ie.TableCell(Find.ByText("...")); |
Click on a TableCell:
1 | tableCell.Click(); |
Get all the TableCells of the current page:
1 | ie.TableCells; |
Search for a certain Frame:
1 | Frame frame = ie.Frame(Find.BySrc(new Regex(".*main.aspx"))); |
Does a certain Element exists:
1 | Assert.IsTrue(frame.Element("app").Exists); |
Follow Me!