31 July 2012

Watir does support all element tags

In my last post, I commented on how brittle the Watir example was in the Watir documentation.  But I since found that Watir does support all the normal ID's and element Class'... here's a list of some of it's capabilties:
http://wiki.openqa.org/display/WTR/Ways+Available+To+Identify+HTML+Element

Watir: simple automation sample that's far too brittle

Once Watir is installed, along with Ruby and the Ruby DevKit (instructions for which are at www.watir.com), I was able to write out the following after reading their basic manual:

require "watir-webdriver"
browser = Watir::Browser.new :ff
browser.goto "google.com"
browser.link(:text => "Images").click
browser.text_field(:name => "q").set "plane"
browser.button(:value => "Search by image").click


I saved it to a .rb file and ran it: ruby google_search.rb 

Is there any problem with this example?

Yes, there is.  It works, for now.  That's the problem.  It's entirely too brittle.  In fact the example that comes with Watir doesn't work.  Google has changed their value for the Search button since the documentation was written. 

The Watir example used a value of "Search Images" - which has since changed to "Search by image" - if you use this type of automation text will no doubt change often.  It's best to use CSS ID's or Classes as often as you can. 

I'm not sure yet if Watir supports ID's, i'm sure it does.  But I'll need to dig into it further

Watir and Ruby

I started QA / Web automation in a language called Groovy.  I found it very difficult to pick up.  The people who suggested it as a useful language felt it was easy for newcomers to pick up. 

The problem with Groovy is:
  • The training resources are written for Java developers.  If you're not a Java developer you almost need to pick up Java first then learn Groovy - which is entirely backwards to the goal
  • Groovy has little support out there, compared to Ruby
  • Pain in the Ass to set up an automation framework in it.  Very fragile.  I've been using GEB - but you end up having all sorts of conflicts with the Groovy compiler verison, Webdriver verison, Spock version, etc.   It's constantly needing supervision and maintenance. 
The upside of Groovy is:
  • Native use of Java (you can just type Java code and the Groovy compiler will run it)
  • Native support for JODBC drivers.
But tonight, having never used Ruby, I decided to try and install Watir to see how daunting a task it would be. 

In less then about 20min (10min to install Ruby and Watir) I was able to write a test in the Watir framework. 

Groovy took me months to get the GEB framework going. 

I love IRB - interactive ruby is so great to actually see how to drive the browser before comitting to code... I can just type:
irb
>require "watir"
>browser=Watir::Browser.new

At this point a default browser spawns!

>browser.goto "watir.com"

It pulls up www.watir.com

Pretty nifty and easy.  IRB is great to just see what you want to get done. 

I'm not sure yet if Watir will have the great JQuery that Groovy has built in, but I'll give it a spin and see how it works out.