First Steps with WATIR

Watir is an open-source ruby-based browser automation tool. I first looked at it 6 months ago but with a new loadrunner role to involve myself with, I didn’t get far.

In any case, these are the steps I took to get started and to get things up and running.

  • 1. Install Ruby from ruby-lang.org. I chose version 1.9.2 as the most current stable build (despite a warning stating that Watir didn’t work on 1.9.2… we’ll see about that).
  • 2. Following the instructions here on watir.com, I updated the rubygems and installed Watir. I left the firefox addin as it’s not compatible with the latest version and I was loathe to downgrade my main browser. I have IE and Chrome too so I figured if one of them would run, that would be sufficient.
  • 3. Picked up the watir-webdriver whilst I was at it. Documentation can be found here at the excellent watirMelon site. I just used this command in a dos prompt:
  • gem install watir-webdriver
  • 4. I grabbed the chromedriver executable from here and dropped the executable in my ruby/bin/ folder as I know that’s in my path.

I built a simple test based on the things I’d done last time and what I’d managed to glean from other sites. All this does is attempt to open each of my installed browsers and navigate to a page.

require 'rubygems'
require 'watir-webdriver'
#########################################
browser = Watir::Browser.new :firefox
browser.goto "http://www.bbc.co.uk"
puts browser.url
sleep(30)
browser.close
#########################################
browser = Watir::Browser.new :chrome
browser.goto "http://www.amazon.com"
puts browser.url
sleep(30)
browser.close
#########################################
browser = Watir::Browser.new :ie
browser.goto "http://www.automationsolutions.org"
puts browser.url
sleep(30)
browser.close

And that’s as far as I’ve got for now, but it works, which means I’ve validated the installation and I can see the route I’m going to take to progress with Watir. More to come then, clearly, with step 2 being interacting with pages and step 3 being the addition of test conditions. After that I plan to look at parameterisation, extending to include output functionality, and then building test suites.

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress and ThemeMag