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
-
fixed "Unknown property or method `document'" errors
-
fixed outputting "browser.goto('javascript:'';')"
-
added support for link identification by text instead of index
-
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
