- Getting Started
- How do I use Watir?
- How do I gem install Watir behind a proxy server?
- I can't install the Watir gem, or update rubygems on Ruby 188.8.131.52, what do I do?
- How do I require all ruby files in the current directory?
- Can I use Watir with Linux, Mac, Safari, Firefox?
- Page Elements
- How do I identify the attributes of HTML elements on my page?
- Why do I get an access denied error when trying to access a frame?
- How do I use regular expressions for object recognition?
- I have more than one object of the same name. How do I commit an action on anything but the first one?
- How do I create an application/object map?
- Why does my code work in IRB but not in my .rb script?
- How do I access Any Tag in HTML (DOM) with Watir?
- How do I deal with timing issues and not use sleep?
- How do I attach to a pop up window?
- How do I access a security alert window?
- How do I hide the browser window without using the -b flag?
- How do I open multiple IE windows in separate processes?
- How do I close all open IE windows?
- How do I right click an element?
- How do I save all images on a webpage?
- Running Tests
- Why are my test cases running in the wrong order?
- How do I generate XML reports from my test case results?
- How do I use Excel with Watir for data-driven tests?
- How do I use OpenOffice.org Calc with Watir for data-driven tests?
- What should I do if two browser windows appear when running a test under Windows Vista?
- Ruby & Watir
- How do I get the version numbers of Ruby and Watir?
- How do I install a gem from the latest development source?
- How do I search the mailing list archives?
- How to create a Jira Ticket?
- How do I take screenshots and append to a Word file?
- How do I delete all cookies
- How do I use variables with regular expressions?
- How do I fix a WIN32OLERuntimeError when I use AutoIt?
- Using enabled_popup.rb with Watir 1.6.2
Anther good way to understand how to use Watir and get examples is to take a look at the unit tests. There are tests for all of the features in Watir which can serve as excellent documentation and a basic tutorial.
Goto the cmd line
Explained in more detail here.
gem install watir
If you are getting an error like:
What you need to do is manually install the latest version of rubygems. Download the zip file from here, extract it and run setup.rb.
Once you have done this the commands "gem install watir" and "gem update watir" will work correctly.
Take a look at Platforms page of Watir web site.
There are toolbars you can use in Internet Explorer and Firefox. See Install Browser Developer Toolbar for instructions.
See Frames page.
See Regular Expressions page.
I have more than one object of the same name. How do I commit an action on anything but the first one?
See Multiple Attributes page.
Insert the object recognition into a small method
then in your test class do:
See IRB page.
Using Watir 1.5.6 or later, it is easy to extend Watir to support additional tags. Thus:
This article from Bret about how to create your own classes that access HTML elements on the page using the Container Module using previous versions of Watir.
Sometimes you need to wait for something to happen in the Application under test before you interact with it. Sleep statements are hardcoded and lock you down into a certain number of seconds before moving through your test. To avoid that, we've written a polling mechanism in the latest versions of Watir - the wait_until method.
An example might be that you're loading the Google home page and for some reason it's taking time to load. Here's a basic contrived script with a sleep statement.
Unfortunately the sleep is hardcoded and doesn't work for anyone else on my team who have slower network connections, my connection has gotten faster, but it still waits for 5 seconds before setting the text field.
Watir 1.5.x has added a wait_until method that can poll for a certain condition to return true before continuing on or erroring out. By default it checks the condition every half second up until 60 seconds. So I rewrite my code to look like this:
It now works for me with a half second delay, but also works for the other members of my team who have network delays up to a minute. If you're considering using sleep, use wait_until instead. It will make your test code more resilient to timing issues in those cases where you really need to use it.
See Pop Ups page.
See Security Alerts page.
See Tips and Tricks page.
As of development build 184.108.40.2060 a new IE.new_process method was added to 'watir/contrib/ie-new-process'. This starts up a new IE process for each IE window, which is really how it should be done. To close these use IE#kill. Any one getting intermittent RPC errors when opening windows may want to use this instead.
The following Example uses this method to create 5 IE process and add them to an array:
This routine can be useful as part of setup or teardown. It attaches to, and closes, all open IE windows.
An enhanced version of this functionality is now included in Watir 1.5. (It also closes modal web dialogs.)
A final brute-force method (that works on Windows XP) might be to kill all iexplore.exe processes via a system command:
if you include asynchronous JS in your definition of done, you'll need to code around that specifically. There's an open feature request to have Watir's wait method track XHRs and timers that are launched when the page is loaded, and wait for them as well. That may be tricky to do though, and with an all-volunteer project, it really depends on someone making the time to do it.
In lieu of that, one option is having the application keep track if XHRs and timers that it kicks off, and setting the some value to true when they are all complete. For example:
A simpler option is:
Another option is to retry until timeout or no exception is raised.
See the Right Click an Element page.
See the Save All Images on a Webpage page.
See Test Unit page.
If your tests inherit from TestCase or RSpec, take a look at Nick Sieger's project ci_reporter which can run from a Rakefile and collect your results in xml that can be picked up by projects that understand xunit xml reports, such as Cruise Control. Cruise Control is a great continuous integration server with versions for Ruby, Java and .Net and can provide a nice dashboard and runner for your tests.
Here's an extremely simple example using test::unit and ci_reporter. For more examples refer to the information for ci_reporter on Nick's site.
Note: Report files are written, by default, to the test/reports or spec/reports subdirectory of your project. If you wish to customize the location, simply set the environment variable CI_REPORTS (either in the environment, on the Rake command line, or in your Rakefile) to the location where they should go.
See Data-Driven Tests page.
See Data-Driven Tests page.
Try one of these:
- Add your defaut homepage (or 'About:Blank' if you start with a blank page) to the same security group (e.g. 'intranet' or ''trusted sites') as the site you are testing; or
- Turn off Internet Explorer Protected Mode; or
- Change your ruby permissions to "run as administrator"; or
- Disable User Access Control
See Tips and Tricks page.
see Building Watir
Visit Watir Search, Google custom search engine that searches Watir web sites, wiki, bug tracker, source and all Watir related mailing lists (and nothing else).
- go to http://jira.openqa.org/browse/WTR
- log in
- click link CREATE NEW ISSUE (at orange bar near the top of the page)
- you will need openqa.org account to log in
- if you do not have one, you can create it at http://www.openqa.org/sass/index.action
In some cases, after you install Watir, the .dll file fails to get registered which gives an error similar to the following:
If this is your problem, then all you need to do is type the following where your AutoItX3.dll file is installed (if you are using Watir's version of AutoIt then on windows for 1.5.6 it should be at: c:\ruby\lib\ruby\gems\1.8\gems\watir-1.5.6\watir, for 1.6.2 it should be at: C:\ruby\lib\ruby\gems\1.8\gems\watir-1.6.2\lib\watir )
Following this you will see a pop-up window saying: "DllRegisterServer in autoitx3.dll succeeded."
Most of the time, if you are require'ing 'watir/contrib/enabled_popup', you will get the following error:
NameError: uninitialized constant Watir::PageContainer::Win32
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
However, in 1.6.2, you will need to add "require 'watir/ie'" after you require 'watir' to fix this error message. This issue has been fixed in the git version of watir and will be fixed in gems subsequent to 1.6.2.
For more info see this thread: