Watir 6.7 Released!

Written by: Titus Fortner on August 14, 2017

Watir 6.7.0 is now available on RubyGems! A bunch of new features.

To install:

gem install watir

or in your Gemfile:

gem "watir", "~> 6.7"


HTML5.1 and SVG2 Support

There have been some bugs and inconsistencies with these features, but they have been addressed in this release.

Watir now parses the latest official W3C HTML & SVG standards to automatically generate Element classes with their officially supported attributes.

These can be used for both element location and obtaining attribute values in a properly encapsulated fashion:

element = browser.text_field(tabindex: '1')
element.tabindex
# => 1

Non-standard attributes for elements can still be located and returned with:

element = browser.div(css: "div[notstandard='foo']")
element.attribute_value('notstandard')
# => 'foo'


Table Features

Working with tables can be a challenge. Often it is easy enough to get the Table cell you need, but have to interact with elements in relation to it. Here are two useful ways to make this easier:

# Get the title of the first row for the located cell
cell_name = browser.td(text: "John Smith")
cell_name.column_header
# => "Full Name"

# Interact with a sibling cell based on the header
cell_name.sibling_from_header(text: "Opted In").checkbox.click


Iterating with Elements

Some elements can in some respects be considered Collections.

  • OList and UList each effectively have a collection of LI
  • Table effectively has a collection of TableRow
  • TableRow effectively has a collection of TableCell

Now you can iterate over them as if they were a collection like:

browser.ol(id: 'countries').each(&:text)
# => ['USA', 'Canada', 'France']


Siblings

Element#siblings returns an HTMLCollection of all of the elements that are direct children of the calling element’s parent. Note that the element calling this method is included in the results. As with all adjacent methods, this method accepts a hash that will filter the results by any valid Watir locator.

Original Window

We can have long debates about this, and you are free to disagree, but I am not a fan of using Ruby blocks when they are merely used to manage a simple order of code execution (as opposed to using it to reference variables not defined until the context of the calling method).

To switch to a window, take an action, and return to the original window you can currently:

browser.window(title: 'Foo').use do |browser| 
  do_the_things
end

# or
original_window = browser.window.handle
browser.window(title: 'Foo').use
do_the_things
browser.window(handle: original_window).use

With this update you can now use a second window procedurally without having to explicitly store a variable:

browser.window(title: 'Foo').use
do_the_things
browser.original_window.use


Stealing From the Page Object Gem

While going through Cheezy’s updated Page Object gem, I found a number of features that deserve be included directly in Watir. If you already use page-object.gem, you likely won’t see anything new from this.

  • Checkbox #set, #set?, and #clear can now be handled with #check, #checked? and #uncheck respectively
  • Element#attribute_value can now be accessed with Element#attribute (also like Selenium)
  • Added support for Element #scroll_into_view, #location, #size, #height, #width and #center/#centre
  • Radio #set and #set can now be handled with #select and #selected? respectively

See the Changelog for the complete history of updates.

Tags:

Thoughts about this article? Let us know!