One of the tools that I am trying out recently is Watir (pronounced Water). It's too early for me to say whether it's as good as or better than Selenium but I have to admit, learning ruby in the process is a nice bonus. Compared to my experience learning TCL, I found Ruby to be easier to learn.
Here's a quick run down of the steps to get started with installing Ruby and using Watir. Before anything else, I would recommend absolute newbies to try this on Windows first because it will be much easier and quicker.
- Download the Ruby one click installer
- Double click on the file you download and follow the instructions to install ruby
- Open a command prompt and type the following to update ruby and install watir
- We would also want to run tests on firefox, so let's install additional ruby packages that will allow us to do that
- To allow firefox to work with Watir, you'll need to install the jssh plugin for firefox.
gem update --system
gem install watir
gem install firewatir
# set the variables
validator_site = "http://validator.w3.org"
url_to_check = "http://www.google.com"
browser = "ff"
if browser == "ie"
ctrl = Watir::IE.new
ctrl = Firefox.new
puts "1. Open validator site"
puts "2. Type url to validate"
puts "3. Submit the URL"
puts "4. Results ... "
if ctrl.text.include? "Errors found"
puts " Test FAILED."
puts " Test PASSED!"
To execute the script, open a command prompt and type
To try it with Internet Explorer, change the browser variable from 'ff' to 'ie'.
The script simply loads up the w3c validator site and submit "http://www.google.com" for validation. The command prompt will output messages as the script progresses. In the end, it checks whether the words "Errors found" is on the page and outputs a Success or Fail depending on whether those words are found or not.