The Agile development community has struggled for years with an array of solutions for automated testing solutions for web development. NUnitASP is a good way to unit test server side ASP.Net code, especially now that it doesn’t require XHTML compliant pages, but it can’t handle client side scripting and AJAX is exploding in popularity. Several tools have used COM (must die) to drive Internet Explorer (IE) with varying degrees of success. My personal experience is that the IE COM API is too byzantine and flat out flaky. Besides the flakiness, Firefox and other browsers are gaining in popularity so the IE only testing might not cut it anymore.
The API libraries communicate with the Selenium Server, a Java executable that can start and stop any supported browser and send testing commands to the browser. The .Net callable wrapper works by sending HTTP messages to the Selenium Server that controls a browser. The first step is to start up the Selenium Server from a command prompt.
java -jar server\selenium-server.jar -interactive
The next step was to create a simple HTML page with a textbox that changes values when a button is clicked:
Next I wrote a little NUnit test fixture class to run tests against the web page. The key object is the DefaultSelenium class that is created in the SetUp() method:
It’s a trivial example, but it’s a start.
What I don’t know –
- What’s the best way to handle the Selenium Server process? How do you guarantee it’s up when you start your tests? I’m thinking some kind of Windows service wrapper
- How do you integrate Selenium with CruiseControl.Net to get it into your Continuous Integration strategy? I can’t find much on the web about this yet. You can run Selenium from NUnit for developer testing, but that isn’t a very desirable answer from a tester’s perspective. For a couple of reasons, our thinking is to wrap the Selenium manipulation inside a FitNesse DoFixture. We already know how to integrate FitNesse tests within a CC.Net build and it’s convenient to run all the tests together. We’re also hoping that the DoFixture tests will be easier to understand and that we can hide some of the web page details behind the fixture.
We’re looking primarily at Selenium, but we’re also considering WATIR (Ruby based tool) and Sahi (I don’t know much about it, but it looks strong). One of our colleagues is experimenting with a Ruby based DSL for testing another web product using WATIR as the core that looks promising. I’ve also been playing with the Ruby driver for Selenium with an eye towards creating a testing DSL for our application.