Richard Lawrence

On making software teams happier and more productive

Archive for the ‘WatiN Patterns’ tag

WatiN Patterns #3: Don’t Over-specify

3 comments

After a long hiatus, I’m resuming the WatiN Patterns series. Pattern #1 covered why and how your tests should clean up after themselves. Pattern #2 covered how you should name your tests and why they should only assert one thing.

Pattern #3 is about keeping your tests maintainable by specifying just enough in your element selectors.

Read the rest of this entry »

Written by Richard

October 30th, 2009 at 8:20 am

WatiN Patterns #2: One Assertion and a Name to Match

2 comments

One way to keep your WatiN tests maintainable is to keep them small and focused. WatiN Pattern #2, then, is a way to do just that.

Read the rest of this entry »

Written by Richard

February 11th, 2009 at 4:46 pm

WatiN Patterns #1: No Browser Left Behind

no comments yet

In my previous posts on WatiN, I lamented the shortage of online documentation and resolved to do something about it by documenting the patterns I’ve found for good WatiN tests. This is the first in a series in which I’ll take an example of the typical beginner WatiN test I see and refactor it to use the patterns I recommend.

Consider this test:

63
64
65
66
67
68
69
70
71
72
        [TestMethod]
        public void SearchPageTest()
        {
            IE ie = new IE();
            ie.GoTo("http://www.google.com/");
            ie.TextField(Find.ByName("q")).TypeText("Richard Lawrence");
            ie.Button(Find.ByName("btnG")).Click();
            Assert.IsTrue(ie.ContainsText("www.richardlawrence.info"));
            ie.Close();
        }

It has a few problems, but I want to highlight one in this post: This test doesn’t properly clean up after itself. If the code on lines 66-70 throws an exception or if the assertion fails, line 71 will never be executed. When you’re testing on your own machine, this can be annoying—you have to close the IE window manually. But if the test runs unattended (e.g. as part of continuous integration) it can be much more than annoying.

Read the rest of this entry »

Written by Richard

February 4th, 2009 at 4:35 pm