The future of PageObject

This post is going to layout the direction I am taking the PageObject gem. But first, a little history is in order.

When I first created the PageObject gem there was a significant difference between the Watir and Selenium gems. The PageObject gem started as a high-level wrapper around over these two gems. Over the years the difference between those gems have become distinct and now Watir is a very nice layer over Selenium.

Because of this I have decided to fundamentally change the PageObject gem. With todays’ release (2.1) I have removed the selenium platform. You can still pass a Selenium driver to the gem but it will simply be wrapped by Watir. On the API level, you will not see any differences but you might have to make some simple changes to your calls to RSpec matchers if you used the predicate matchers.

So what is different?

In addition to providing all of the high-level capabilities that have always existed in PageObject, version 2.1 is an abstraction over Watir only. One significant difference is that the gem is no longer using delegation. Delegation caused me to have to add new methods to PageObject every time Watir added a new capability. This meant that at times there was capability that existed in Watir that was not available in PageObject. With this release the gem will forward method invocations to the watir natives without displaying the deprecation warning. This means that as soon as something new is added to Watir it is immediately available to PageObject.

Will I need to change any code?

You might have to make a change to some of your expectations. If you use the RSpec predicate matchers then you should be aware that it will check to see if the method is available before calling it and if it doesn’t exist it will throw an error. So if you have had code like this:

expect(my_element).to be_visible

then RSpec will check to see if the visible? method exists. In the new version of PageObject it doesn’t exist. This call is intercepted and sent to Watir. This means you will get an error. You can simply change the exception to this:

expect(my_element.visible?).to be(true), 
        "expected my_element to be visible"

and everything should be fine. Notice that I provided the additional parameter to make the message meaningful in the case of a failure.

So what is the path forward?

Version 2.2 will be released in a week or two and it will remove the way that the gem is injecting the Watir platform and further simplify the code. A week or two after that I will release 2.3 which will remove the final pieces of this larger refactoring – the parts that build out custom path.

From that point further the gem will continue to focus on providing high-level functionality that will make testing easier. I will also be focusing on addressing other issues we run into when writing tests – namely things like test data management, service virtualization, test configuration, etc. I hope to continue to build out a full suite of tools that make writing test automation a joy.

7 thoughts on “The future of PageObject

  1. Empirically, I find that

    expect(my_element.visible).to be(true)

    does not work but

    expect(my_element.visible?).to be(true) #(note the ‘?’ after visible)

    does work

  2. Hi I am stalking you for help, lol. 🙂 I left a post on cucumber and cheese and a tweet. here is my error:

    /Users/zbomani/.rvm/rubies/ruby-2.2.6/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/zbomani/RubymineProjects/learn_watir/first_script.rb
    /Users/zbomani/.rvm/rubies/ruby-2.2.6/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require’: cannot load such file — watir-webdriver (LoadError)
    from /Users/zbomani/.rvm/rubies/ruby-2.2.6/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require’
    from /Users/zbomani/RubymineProjects/learn_watir/first_script.rb:2:in `’
    from -e:1:in `load’
    from -e:1:in `’

    Process finished with exit code 1

    Pretty sure it has to do with my paths but not certiain. Thank you.

  3. Hi Cheezy, I was watching one of your webinars on youtube and you mentioned about putting your Rubymine templates and shortcut keys on Git. Did this ever happen?

    Ps your book is great!

    Many thanks



  4. Hi, A coworker of mine was at a training you did and thought that you might be a good fit for some consulting/training work we have coming up. I couldn’t find your new company Tango online to send an email through that. Please let me know if you are interested in the opportunity

Leave a Reply

Your email address will not be published. Required fields are marked *