Browser.new

Using Browser.new

With Watir 1.6, a new interface to Watir has been provided to make it easier to write tests that are portable across browsers. Currently it supports IE and Firefox. With time, it will support additional browsers.

Updating Your Tests

In your tests, you should use

Watir::Browser.new

instead of

Watir::IE.new

Specifying Which Browser to Test

Instead of hard-coding the browser in your tests, you can now specify which browser should be tested at run time. There are several ways to do this.

Environment variable

> set watir_browser=ie
> set watir_browser=firefox
> set watir_browser=safari
>

This setting will determine which browser "Watir::Browser.new" will test.

Watir::Browser.default

You can specify what browser will be used directly in your Ruby code:

Watir::Browser.default = 'ie'

Config file

Create a file like this, called options.yml

browser: ie

In your program, execute the following code before calling "Watir::Browser.new":

Watir.options_file = 'c:/work/options.yml'

You will need to provide the full path to your file. Once you have done this, "Browser.new" will use the option settings from this file. If you also use an environment variable, it will override this setting.

Specifying additional options

Currently the following options are configurable for IE:

speed: fast
visible: true

Valid speed settings are "fast", "slow" and "zippy"

Compatibility

Watir 1.6.2 does not support Browser.attach. This will be supported in a future version.

For details on other compatibility issues with Watir's support for IE and Firefox, see Firewatir Compatibility

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jan 01, 2009

    Alister Scott says:

    For consistency, should we allow users to specify speed in the ruby code as well...

    For consistency, should we allow users to specify speed in the ruby code as well?
    For example:

    Watir::Browser.speed = 'zippy'