Archive for the ‘WatiN’ tag
Debugging Cuke4Nuke Step Definitions
At a client today, we were doing some tricky automation with WatiN (against Telerik controls) in Cuke4Nuke. We wanted to dig into what WatiN was finding in the browser. The obvious move was to fire up the debugger. But with Cuke4Nuke, this is trickier than you might think. The Cuke4Nuke gem includes a release build—no debug symbols. Plus, the process isn’t around long enough to attach to if you use the cuke4nuke executable. We probably could have figured it out, but it wasn’t worth the trouble.
Since we weren’t debugging the Cucumber side of things, we didn’t need all the Cucumber and Cuke4Nuke plumbing. We just needed to run the code using WatiN.
NUnit and Resharper to the rescue…Cuke4Nuke cares about Given, When, Then, Before, and After attributes on your methods. But that doesn’t mean those are the only attributes allowed. Read the rest of this entry »
How to Remove Duplication in Cucumber Tests Using Scenario Outlines
Gojko Adzic has a new blog post demonstrating the new table parameter support in Cuke4Nuke. Table parameters are an important part of Cucumber. They’re great for setting up data and asserting that lists are what you expect. But I use them much less often than the other kind of table in Cucumber, scenario outlines. Read on to see how to use them »
The Latest on Cuke4Nuke
This morning, I released version 0.3.0 of Cuke4Nuke. With this release, Cuke4Nuke supports almost everything you can do with Cucumber in Ruby or Java, making C# a first class language for Cucumber. (The only missing features are small things like tags on Before and After hooks and a richer Table object.) Check out the Cuke4Nuke wiki for instructions to install and get started with Cucumber in .NET. To see it in action, check out my screencast on Cuke4Nuke and WatiN.
Screencast: Testing Web Applications in .NET with Cuke4Nuke and WatiN
Yesterday, I released Cuke4Nuke 0.2.2, which added WatiN compatibility and an example of how to use the two tools together. Here’s a short screencast in which I walk through the example:
Resources from the video:
- The Cuke4Nuke Wiki with installation instructions
- WatiN
- Source code from the example
- The new Ruby installer
WatiN Patterns #3: Don’t Over-specify
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.
WatiN Patterns #2: One Assertion and a Name to Match
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.
WatiN Patterns #1: No Browser Left Behind
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.
Another Look at WatiN
At my current client, we’ve decided to use WatiN, largely for the C# vs. Ruby reason I discussed earlier this week. After spending a week working with WatiN (following a year of rarely using it), I’m impressed. Ruby and the active Watir community still have their advantages. But WatiN has really come into its own with C# 3.0 features like lambdas. I’m pleased with the test code we’re producing in terms of readability, speed, flexibility, and maintainability. I’ve proposed an Agile 2009 tutorial session on the patterns I’m using to get those results, and I’ll post more on that topic here soon. (Which will hopefully help with one of WatiN’s shortcomings—documentation.)
Web Testing for .NET Teams: WatiN or Watir?
I’ve noticed a pattern with several of my .NET clients who want to get into automated acceptance testing for web applications. They like the idea of WatiN because it would let them write tests in the same language as their production code. But then they notice that there’s much more documentation and apparently a much more active community around Watir. And that Ruby language looks interesting too. What to do?
I think there are good arguments for both. Here are the major pros and cons from my perspective…
