Written by: Titus Fortner on September 7, 2017

The initial version of the Watigiri gem has just been released. Watigiri is an add-on to Watir that allows actions to be taken using Nokogiri (an HTML parser that uses native C or Java libraries) instead of Selenium in the places it makes sense to do so.

To install:

gem install watigiri

or in your Gemfile:

gem "watigiri", "~> 0.2"

Text Bang

The major feature of Watigiri is Watir::Element#text!. A common pattern in testing is to verify that the information that was entered into a form has correctly been sent to a view or list page. Rather than making several dozen wire calls to locate and obtain text information from each, you can make a single wire call to obtain the DOM and then quickly locate and obtain all of the information necessary at each element location.

The most important distinction between Element#text! and Element#text is that #text! returns what is in the DOM regardless of whether the text is actually visible (present) on the page. So if the element being present on the page matters, do not use #text!.

Also of note, Watigiri automatically flushes the cached DOM whenever a user takes an action that might have changed the DOM (clicks, navigations, etc). So the performance improvement will only come with the number of successive calls of #text! before taking other actions.

Regular Expression Location

Watir supports using a Regexp for all locators that accept a String. Watir implements this by locating a subset of elements that might be a match and then making wire calls on each of those to check if they actually match the provided regular expression. With Watigiri, iterating through this list of potentially matching elements is done using Nokogiri. Depending on the DOM and the kind of regular expression, this can be a small or slighly less small performance improvement.

Additional Features and Support

Watigiri is still effectively in Beta and the implementation and the the method names might change (for reasons). There are a number of other potential features that will be tracked in the Watigiri Issue Tracker. Please add additional feature requests or issues you find with this gem. Support for and discussion about this gem can be found in the #watir channel of Selenium Slack.


Thoughts about this article? Let us know!