Well I finally jumped on board and gave Ruby and Watir a try and boy was I impressed. I’m somewhat ashamed to say that I’ve yet to dive into the TDD/Unit test world (I’m currently working on one of those projects that was due a month ago and can’t afford to let it slip any farther, but don’t worry, unit test are planned for version 1.1) but with Watir I can at least now quickly setup some basic UI testing.

Scott Hanselman created a cool C# program called WatirMaker that recorded your actions in IE and generated a Watir script. It was later converted to native Ruby by Michael Kelly and John Hann. Needless to say this makes writing unit test for your Web UI much faster. I decided to put my ruby skills to the test (ok so this stuff was easy but hey, it was my first attempt at ruby) and make a few improvements to the script.

Here is the new script and here is a list of changes I made:

  • Renamed “ie.” to “browser.” in the output to be more FireWatir friendly
  • Added ability to control the output of Debug and Warning Messages
    • wm.setDebugLevel(1) makes it only output warning messages, level 2 includes debug messages
  • fixed "Unknown property or method `document'" errors
    • the original script had a capital “U” by my system had a lower case “u” in the error message so my output scripts had tons of “unknown property or method `document'” printed in the output. I just removed the “u” completely from the error matching to it will now work if the error message regardless of case
  • fixed outputting "browser.goto('javascript:'';')"
    • not sure if this was an issue only on my system or not but I was sometimes getting "browser.goto('javascript:'';')" in the output so I just check for that string before printing the output
  • added support for link identification by text instead of index
    • in the original version when you clicked on a link it would output something like “ie.document.all[ '56' ].click” now it reads the innerText of the <a> tag and outputs “browser.link( :text, 'The Link Text' ).click”
  • added support for regular expression generation of asp.net like id values
    • if WatirMaker is going to use “:id” as the “how” and the “what” contains a “_” then it uses a regular expression match of everything after the last “_”. This makes generating scripts for asp.net pages easier because then if the name of a container changes (like a master page) your script will still work. In cases where there are multiple controls with the same id but different containers you will have to hand tweek the output to get the results you expect.
    • Original output: ie.text_field( :id, 'ctl00_cphBody_txtUsername' ).set( 'username' )
      New Output: browser.text_field( :id, /txtPassword$/ ).set( 'password' )

I tested the new script on Windows XP MCE (which is really the same as XP Pro) using IE 7 beta 3.

If you have any problems or suggested improvements feel free to leave a comment or send me an email. My next improvement will be to have WatirMaker output ruby unit test.

UPDATE: WatirMaker is now hosted on openqa.org.  Here is a direct link:
http://svn.openqa.org/fisheye/browse/watir-recorder/trunk/Ruby/src

kick it on DotNetKicks.com

Posted at 7/23/2006 11:21 PM
Comments [2] - Permalink

I figured out the problem to my Visual Studio 2005 memory issue awhile ago and forgot to post about it.

The sample solution that I created to reproduce the problem included several strongly typed ArrayList generated with code smith (I know I should be using generics but when I found the problem it was in a 1.1 project converted to 2.0 that had too many generated strongly typed ArrayList in place to replace with generics versions). It turns out that it wasn’t the ArrayList that was causing the problems but the XML comments . I found a bug report that describes the problem:http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=90681

It looks like there is now a hotfix out to fix the problem. KB917452 describes the problem and you can get a hotfix if you call in to Microsoft. That hotfix also includes the hotfix for KB915038 that fixes a bunch of VB Compiler problems. I have the compiler hotfix installed (fixed a separate issue I was having) but have not tried the newer hotfix yet, I instead removed all my xml comments from my generated code and my VS memory consumption is way down.

On a side note Microsoft was very helpful in fixing the problem. I initially though it was a Web Application Project problem and the Asp.net team replied almost instantly when I emailed about the problem. When I called Microsoft to get the hotfix for KB915038 they were quick and helpful.

Posted at 7/23/2006 10:40 PM
Comments [0] - Permalink