Posts filed under ‘Potentially Useful Stuff’

ci_reporter output for Watir

I’ve been using the ci_reporter gem to grab the results from my Test::Unit verifications and put them in an xml file.  Then I apply an xsl stylesheet to the xml to transform the results into html.  It’s not the prettiest report, but it beats reading xml or parsing through command line output.  My goal is to move my test framework to a rails app for better reporting and data management, but for now, I’m sticking with the ci_reporter output.  Here’s how it works:

First you need to install the ci_reporter gem and require the ci_reporter rake task in your framework class (in my case in my Test::Unit class):

require 'ci/reporter/rake/test_unit_loader'

After running your framework, ci_reporter will create ‘test/reports’ subdirectories and place the xml output of your tests in the reports folder.

Next, you’ll need to transform this xml output to html.  This is accomplished by applying an xsl stylesheet to your xml.  I’ve saved my stylesheet text as a doc file here:

https://tcfodor.files.wordpress.com/2009/04/transform-results.doc

To apply the stylesheet, add the following at line 2 of your xml output:

<?xml-stylesheet type="text/xsl" href="transform-results.xsl"?>

In my case, I just make sure the stylesheet is saved in the local directory.  If you want to save it somewhere else, you’ll need to supply a relative path.

As part of my framework, I’ve automated updating the xml output and renaming  it with a test run.  Then it saves the xml output and xsl transform to a network location to share with the rest of the team.

This assumes that IE is your browser of choice, to view the report in Firefox, add the following line to your xml output at line 3.

<xsl:if test="system-property('xsl:vendor')='Transformiix'"></xsl:if>
Advertisements

July 23, 2009 at 9:09 pm Leave a comment

watir-console, my new best friend

I’ve made the move from irb to watir-console for troubleshooting Watir code.

Since version 1.5.2, watir-console has been part of the Watir installation.  Basically, it’s an irb session on steroids.  It’s launched through a regular console the same way irb is (c:\>watir-console), but it also includes the following:

  • a local log of your session (saved as console.log)
  • tab complete functionality
  • does require ‘watir’ automatically

Jim Knowlton has a great example of adding helper class functionality to watir-console so that any classes or methods you want can be automatically available when you launch watir-console.

http://www.agilerubytester.com/2009/02/customizing-watir-console.html

Pair watir-console with an HTML element inspector like Firebug (for Firefox) or IE Developer Toolbar, and you have a great environment for testing and troubleshooting watir tests.

April 2, 2009 at 7:06 pm Leave a comment

Multiline comments in Ruby.

Maybe the Google failed me, maybe I was just not being observant, but when I first started using Ruby, I could not for the life of me figure out how to make multiline comments.  I had resorted to using lots of # signs, which isn’t especially difficult, but it just felt like there had to be an easier way.

Turns out, there is an easier, although perhaps still a bit clunky, way.  To start a multiline comment put =begin before the first line of comments and =end after the last line.  Note that these commands can not be indented at all, you have to put them at the beginning of the line.

March 17, 2009 at 1:33 am 3 comments

IRB is your friend.

They say that there’s no such thing as a dumb question, but we’ve all asked questions that we wish we could take back.  That’s why IRB and watir-console are so great when you’re writing Watir tests- you get to try out any command (or even a group of commands) to quickly see if it works without having to ask someone else or run your whole test.  The best part is that, unlike a post to a group, any totally off base attempts are not available for the world to see.

Think of IRB as a buffer for embarrassing questions.  Learn it, use it, love it.

From a command prompt:

C:>irb
irb(main):001:0> require 'watir'
=> true
irb(main):002:0> browser = Watir::Browser.new
=> a bunch of output describing the browser

irb(main):003:0> browser.goto('http://www.google.com')
=> 1.115
irb(main):004:0> browser.text_field(:name, 'q').set('watir information')
=> ""

If I try something that doesn’t work, I get a helpful error message:

irb(main):005:0> browser.text_field(:name, 'qwerty').set('watir information')
=>Watir::Exception::UnknownObjectException: Unable to locate element, using :name, "qwerty"

March 11, 2009 at 4:20 pm Leave a comment


Categories

Recent Tweets