Watir, WatirMaker & FireWatir

I didn’t want to have to work through browser screens while I was debugging my controls, constantly searching for postcodes etc., so I’ve started using Watir (pronounced ‘Water’) to create and run browser automation scripts.

Watir

Watir installation is simple. Running a script is even easier:

C:\>ruby myScript.rb

An example script for your project might be:

#requires
require 'watir'

#includes
include Watir

browser = IE.new

browser.goto( 'http://localhost:3112/' )

browser.text_field( :id, /username$/ ).set( 'memberuser1' )
browser.text_field( :id, /password$/ ).set( 'password1' )
browser.button( :id, /submit$/ ).click

Watir Maker

WatirMaker lets you easily record Watir scripts as you click through a session in the browser:

C:\>ruby WatirMaker.rb > myScript.rb

It provides you with a basic script quickly and easily and then you can modify it (the Watir cheatsheet is handy).

FireWatir

FireWatir is Watir for Firefox. Once you’ve installed the JSSh extension and started Firefox with the -jssh switch you can run your modified scripts. The only changes that should be required to your scripts are at the start:

#requires
require 'firewatir'

#includes
include FireWatir

browser = Firefox.new

Important tools for development time and you can port the scripts straight into your UAT environment, too.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s