Watir 6.8 Released!

Written by: Titus Fortner on August 29, 2017

Watir 6.8.0 is now available on RubyGems! Several new features including new methods to increase performance.

To install:

gem install watir

or in your Gemfile:

gem "watir", "~> 6.8"


Bang Methods

Drivers are slow when it comes to typing text. Typically the intent of a test that enters text into a field is to verify:

  1. the user can type into the field
  2. the actions associated with events get fired
  3. the application properly handles the data

None of these three things require that a driver type each character.

By using a Element#set! instead of Element#set, Watir will:

  1. send clear via the applicable driver command to ensure the user can interact with the field
  2. use JavaScript to quickly fill the field with the specified text
  3. type the last character via the applicable driver command to ensure that appropriate events get fired

Depending on how much text is being entered, this could provide a huge performance improvement without negatively impacting the effectiveness of the test.

Along with Element#set!, Watir now supports bang (!) methods with JavaScript implementations for:

  • Element#click!
  • Element#double_click!
  • Select#select!
  • Select#select_all!

The clicks are unlikely to provide a performance improvement and should be used sparingly. The Select methods have the potential to decrease the time it takes to interact with especially large select lists.

Let us know what kind of performance improvements you see with these methods.


Radio Sets

Input elements of type="radio" are not independent (clicking one radio button in a set will de-select another radio button in the set), but until now Watir has required users to treat them independently. Element#radio_set now allows users to identify the collection of related radio buttons and interact with it similarly to how one currently interacts with a Select List.

A RadioSet is initialized with a locator for any of the constituent radio buttons. When the name value is the same between radio buttons, the RadioSet initialized by their locators will be the same:

radio_set_yes = browser.radio_set(id: "new_user_newsletter_yes")
radio_set_no = browser.radio_set(id: "new_user_newsletter_no")
radio_set_yes == radio_set_no # => true

A RadioSet:

  • Can be iterated over
  • Returns currently selected radio button with #selected
  • Returns text and value of the selected radio button with #text and #value
  • Returns whether the radio button with the provided label/text is currently selected with #selected?(#{label})
  • Selects the radio button with the specified label/text with: #select(#{label})


Selecting drop down options

Select#select_value has been deprecated. Select#select will now allow users to locate elements by text, label or value. Having one primary way to select options both matches the original Watir implementation as well as making it easier to support automatic form filling methods in Page Object libraries.


Input Label

Sometimes a user might want to click on the label of an input element instead of the element itself. With the new Input#label, a user can now do:

radio_button = browser.radio(id: "new_user_newsletter_yes")
radio_button.label.click


See the Changelog for the complete history of updates.