Monthly Archives: July 2007

Automated testing of ASP.NET web applications using Selenium


Lately, I’ve been focused on Web Application testing frameworks and I’ve been looking at a number of different options and having varying degrees of success. That is, of course, until I started looking at Selenium after Lino mentioned it to me and I’m very impressed. Selenium is an open source project with multiple tools designed for testing web applications. Selenium includes:

  • Selenium IDE an add-on to Firefox use for recording test scripts
  • Selenium RC (Remote Control) a Java server used for execution of test scripts
  • Selenium Core client side testing support for web applications added directly to your application

All of these are interesting in their own right so be sure to look closely at each piece.

Selenium IDE

Selenium IDE

The Selenium IDE is a non-modal dialog add-on for Firefox that supports Selenium test development. In fact, it’s more than fair to call this single dialog an IDE because it fully supports recording, development and debugging of test scripts. Additionally, it can format test scripts in any of the following for use with Selenium RC:

  • HTML
  • Java
  • C#
  • Perl
  • PHP
  • Python
  • Ruby

A Selenium test script consists of a series of Commands which have a Target and optionally a Value. For example, browsing to a web page using Selenium consists of the following:

Command: open
Target: http://localhost/myapp

To click on a link titled “About” on a page the Command might look like this:

Command: clickAndWait
Target: link=About

This will initiate the click and wait until the new page is done loading. There are literally hundreds of commands to choose from covering input (both keyboard and mouse), control manipulation, drag/drop, evaluation, verification, waiting, browser manipulation and just about anything else you’ll need.

If you’ve done any UI testing at all you’re familiar with the challenge of manipulating a UI programmatically in a manner independent from of the size, position or location of the control you’re trying to manipulate. Selenium solves this problem using XPATH and providing the ability to locate controls based on XPATH expressions alleviating the need to hard code HTML tag structure into a test script. This is particularly crucial for ASP.NET testing since the runtime mangles the ID attributes of rendered tags. For example, the ASP.NET runtime may render ID attributes that look like:

id=”ctl00_cphContents_gridMaint_DataGrid”

Finding this control using an XPATH expression can be simplified to something like this:

//table[contains(@id, “gridMaint”)]

In the event the nesting of the DataGrid changes the script will continue to function properly as long as table’s ID contains the text “gridMaint”.

Example of using the Find button on the Selenium IDE

Notice the link is highlighted in the browser

Playing back tests using Selenium TestRunner

The Selenium IDE has a toolbar button that will launch a feature called TestRunner which allows you to playback your tests using controls hosted in an IFRAME inside your browser. Here’s what it looks like:

Selenium TestRunner

You can playback your entire test from right within your browser. It’s like having the IDE built right into your application.

Selenium RC

Next, is Selenium RC which is a Java server application used execute Selenium tests and drive a browser instance through AJAX communication with the browser. To start Selenium RC simply execute the following from a command prompt:

java -jar selenium-server.jar -interactive

Since I’m focused on .NET I’ll discuss the C# approach. Once you’ve recorded and debugged your test you can capture it as C# and compile it into an NUnit compatible assembly where upon execution it will drive Selenium RC to manipulate the web application through a browser instance running on your desktop. Here is an example of the above recorded test in C#:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
    [TestFixture]
    public class NewTest
    {
        private ISelenium selenium;
        private StringBuilder verificationErrors;
        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium("localhost", 4444, "*firefox",
                              "http://localhost:4444");
            selenium.Start();
            verificationErrors = new StringBuilder();
        }
        [TearDown]
        public void TeardownTest()
        {
            try
            {
                selenium.Stop();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }
            Assert.AreEqual("", verificationErrors.ToString());
        }
        [Test]
        public void TheNewTest()
        {
            selenium.Open("/selenium-ide/");
            selenium.Click("link=About");
            selenium.WaitForPageToLoad("30000");
        }
    }
}

Generation of NUnit compatible tests is great because it makes it really easy to incorporate Selenium test suites into a continuous integration environment like CruiseControl.NET.

Conclusion

If you’re in need of a web application testing framework you owe it to yourself to check out Selenium. I’d go so far as to say if you’re doing doing any web related development and you’re not already using Selenium you should stop right now and go download it. Here are there RSS feeds.

After playing with Selenium for about an hour I was easily able to:

  • Record tests against a RIA
  • Build a C# NUnit compatible assembly to drive Selenium RC
  • Integrate the tests into an automated build using CruiseControl.NET

Since then I’ve been able to really dig in and accomplish a lot of work in a very short period of time. The next step is to build up a nice battery of tests and dig into NCover to help figure out where the holes are.

Lastly, I just want to tip my hat to the ThoughtWorks and volunteers and supporters of the Selenium project. Kudos for such a great framework!

Looking for advice on a water softener for very hard water

I’ve been very fortunate so far asking for advice and once again I thought I’d tap into the wisdom of crowds to see if I can get some help regarding water softeners and hopefully narrow the field a bit. I’ve been doing a bunch of research online though I have yet to reach a conclusion. I found this site which seemed helpful but locating unbiased information comparing various products has been hard to come by. Unfortunately, Consumer Reports doesn’t even seem to review water softeners, at least searching their site didn’t turn up any good results.

The Scotts Valley Water District provides a report each year on the quality of our water and it states a “Total Hardness of 216” which I believe by any means qualifies as “very hard”. I do know our water is reeking havoc with our appliances not to mention our hair and skin. On top of the hardness I’m not at all fond of the taste and use a Watts Premier 5 filter reverse osmosis system which fortunately corrects that problem.

Anyway, I’m looking for a whole house system for a family of five with the understanding it’s likely to be several thousand dollars installed. I’ve asked a number of friends and neighbors but have yet to reach any real conclusion though I’ve found many cases where admittedly systems are not well maintained. Do you have advice regarding whole house water softeners for a family of five with extremely hard water?

[Updated: July 30] Fix the spelling of “advise”. Doh! At least I caught it myself.

Diving into web application automated testing

My new job is completely focused on ASP.NET development and being a big believer in automated testing I’ve been investigating strategies for RIA‘s. I’ve found what I think is going to be a solution using Selenium which I’ll blog more about later though I’m curious to know what other frameworks people are using? Basically, I don’t want to overlook any potential candidates though at this point I’m very happy with Selenium.

What are you doing for automated testing of AJAX enabled Internet applications?

Portable applications on a SanDisk Cruzer Micro USB flash drive

SanDiskCruzer

A few weeks ago I bought a 4GB SanDisk Cruzer Micro USB 2.0 Flash drive ($39.95 @ Costco) with the intent of it being a convenient way to move files around. After using for a bit to do just that I’ve been playing with portable applications and I must say they rock! I’m using FireFox, $g(Google Talk), Skype, Thunderbird and Trillian all working on this drive. Basically, this drive contains my communications tools and has made it easy to move quickly onto my new work machine.

Kudos to the folks over at www.portableapps.com!

[Update: July 24] The apps just keep coming. I just added Notepad++ and 7Zip to my drive and there is now a PortableApps Suite available. Cool!

My Harry Potter book buying story

Like millions of people my wife has really enjoyed Harry Potter and last Friday after my wife went to bed I decided to brave the crowds to try to pick up a copy for her to have it sitting on the breakfast table in the morning. I simply didn’t realize how crazy things were going to be when I made it to Border’s in downtown Santa Cruz. I’d reserved a copy a few weeks ago but my first clue came when I hit Bookshop Santa Cruz and I had to slow down to drive through hoards of people leaving with their copy with some even carrying the empty cardboard boxes the books were shipped in. I made my way to the parking garage and walked over to Border’s. The street was full of people and Border’s itself was packed wall-to-wall with avid fans either waiting in line or seated on the floor reading the 700+ page book.

There was a wrist band system in effect though it wasn’t explained anywhere so I muddled through the crowd looking for clues of how to proceed until I finally ran into an employee who clued me in. I made my way to the wrist band line and after half an hour I got a small purple wrist band and was told that I’d probably get my copy around 2:00am, it was 12:40am. After wading through the crowd trying to assess the accuracy of that timetable I reached the conclusion that even that was probably optimistic so I headed home. I should have snapped a few pictures with my cell phone but I always seem to forget that I now have a camera wherever I go.

Anyway, the next morning we went to the farmer’s market and on our way back to Scotts Valley we decided to run by Costco since they had the book too. We parked and I ran in and found a palette of books right next to the 300 flat panel TV’s (if you’ve ever been to Costco you know what I’m talking about). Anyway, I ended up with a copy of Harry Potter for $19.74 tax included. The retail price was $34.99 and my wife mentioned Border’s had a 30% discount so we saved a little money.

Anyone else succeed where I failed?

Vista's Aero UI impacts both memory and battery resources

Vista Window Manager RAM usage

Exploring dwm.exe while switching from Basic to Aero UI
in Vista with only Process Explorer running

The other day I spent some time tweaking the performance of my MacBook Pro (my new work machine) and while I’ve been using Vista for over six months I’m just now coming to realize the cost its new Window manager (dwm.exe) particularly when using the Aero UI in terms of system resources. Basically, I’ve reached the conclusion that on this machine it’s not worth the memory nor battery power for the pretty UI. Not only does it consume 15 times (you read that right) more RAM than the Aero Basic setting it really helps chew through the battery which up until now is something I wasn’t concerned about as I wasn’t a laptop kind of guy.

How does your mileage with Aero compare, is it taking the same toll on system resources?

Using FeedBurner's MyBrand feature and regaining control of my RSS feed URL

Since last October I’ve had my RSS feed hosted by FeedBurner which has worked out well though one down side is that my feed URL wasn’t on my domain, at least not until now. A few weeks ago I blogged about FeedBurner PRO services that are now freely available including MyBrand described as follows on the FeedBurner website:

MyBrand lets you use your own domain name to host your feed instead of feeds.feedburner.com. It puts you in even greater control of your own content with FeedBurner and best of all, MyBrand is now free.

Below I outline the steps to get this setup on DiscountASP.NET (my hosting provider) but you should be able to do the same sort of thing on your host if you control your DNS settings.

  1. Login to your DiscountASP.NET account
  2. From the control panel under Tools & Utilities, select DNS Manager
  3. After reading, click “I Understand and Agree” on the warning page 
  4. Click the link to select the domain you wish to modify, in my case stevetrefethen.com
  5. In the CNAME Record Manager section click “New”
  6. Under the Domain Name column enter the prefix you wish to use for your domain’s feeds. I used “feeds”
  7. Under the Destination column enter feeds.feedburner.com
  8. Click “add”

The screen should look something like this:

CNAME editing

Be aware that changes to CNAME records may take some time to propagate so you may want to wait a day before trying to access your new URL. In fact, I’ve done this and have updated my RSS feeds to use my own domain name. Don’t worry, if you’re already subscribed you don’t have to change anything as the old FeedBurner URL will continue to work.

Vista's Windows Experience Index and the Apple MacBook Pro

I thought readers might find this interesting so here is a screen capture of the Windows Experience Index for my MacBook Pro (my work machine). Btw, the more I use this machine the more I like it, Apple has done a very nice job getting the drivers working for all of this machines features. I have yet to run into any sort of hardware related problem, everything just works. If you ask me, these numbers look pretty good. I’ll have to ping Mark Edington and see if I can get him to get me a screen capture of my old “mainframe box” at CodeGear for comparison (apple to oranges, er Dell’s but still).Windows Vista Experience Index MacBook Pro

Visual Studio Starter Kit for Facebook application development


UPDATED Nov. 6, 2008: A new release is available here.

I’ve created a Visual Studio Starter Kit for developing Facebook applications in ASP.NET using C#. This isn’t necessarily new though this post title more accurately describes the download. I’d never created a Start Kit before and in fact, it was easier than I thought. I’ve been following Internet Searches people use to find my blog and “Facebook” as a search term is certainly picking up and it seems many, many people are blogging about FB these days.

Let me know if you have any problems or suggestions for improvements.

Application Error. The application failed to initialize properly (0xc0000135) may mean .NET's not installed

While attempting to setup CruiseControl.NET on a new build server I ran into this error “Application Error. The application failed to initialize properly (0xc0000135). Click OK to terminate the application”. The problem? The .NET framework wasn’t installed on the machine. The server is running Windows XP and I was accessing it via remote desktop from a Vista box so the lack of .NET left me scratching my head for a second.