WatirMelon AMA: Ask Me Anything

WatirMelon AMAThere comes a time in one’s blogging life when one decides to conduct an ‘Ask Me Anything’ (AMA). That time is now. Feel free to submit the contact form below with your question(s) and I’ll collate these over the next week or so and (try to) answer as many as I can, either in group form for short questions or as individual posts for more meaty ones.

Feel free to ask me anything, whether it be an automated test strategy or approach question, or what it’s like to live in Australia and work remotely for one of the world’s largest blogging/content platforms.

Your name, email and website are all optional, if you choose to provide your name and/website I will put this against the original question when answering it (I won’t include your email). Any toxic or inappropriate questions will be politely ignored.

Improving my WatirMelonCucumber page object framework

I’ve been working on some improvements to my WatirMelonCucumber page object framework, partly inspired by the SpecDriver C# framework I put together, and also inspired by a work colleague who’s especially good at ruby and meta-programming.

Base Page Class to inherit from

The first improvement is adding a base page class that all pages defined inherit stuff from. This means I don’t have to write an initialize for every page, as the base page class initializes each page automagically. This base page class can also navigate to the selected pages direct if needed, check for the appearance of a certain element if needed, and check the title is correctly displayed, again, if needed. Lastly, the base page class catches any methods that are missing and throws these to the browser, which means you can call browser methods such as title, and text at the page level.

class BasePageClass
  include WatirWebDriverHelper

  def initialize browser, visit = false
    @browser = browser
    goto if visit
    expected_element if respond_to? :expected_element
    has_expected_title? if respond_to? :has_expected_title?
  end

  def method_missing sym, *args, &block
    @browser.send sym, *args, &block
  end
end

Watir Page Helper Mixin

I originally saw the Watir Helper idea in Jeff Morgan’s cucumber framework, which I have used here. I have made quite a few changes, not only to support more elements, but also to allow passing in blocks to the helper methods. This helper is included in the base page class, and therefore is accessible in any page defined that inherits from the base page class.

Update: 5th May: See my watir-page-helper gem to include this automatically.

Resulting page model example
The combination of these two improvements mentioned, now mean the actual page classes are nice and neat. For example:

class GoogleHomePage < SearchPageClass

  direct_url "http://www.google.com"
  expected_title "Google"

  button :google_search, :name => "btnG"

  def search_for term
    self.search = term
    google_search
    GoogleResultsPage.new(@browser, false)
  end
end

Ruby & Browser Support

I have changed the framework to use Chrome, since it’s so fast, but that’s easily configurable in env.rb, and watir-webdriver headless instead of Celerity. This means JRuby is not needed, and it can run under Ruby 1.9.2.

Summary

By introducing the base page class, and the watir page helper methods, it means the resulting page models are short, simple and easy to understand. There is a lot less repetition, for example, not including the watir helper in every page, as it’s included in the base, and also not needing an initialize for each page that essentially does the same thing.

Let me know what you think.

AWTA 2009 survey results

I conducted a survey for the Austin Workshop on Test Automation (AWTA) to see what people thought was good about the workshop and what could be improved in the future.  The response was very positive.

Whilst there were twenty-one questions, I believe the following two graphs tell the story:

How much fun did you have at AWTA 2009?
How much fun did you have at AWTA 2009?
Would you attend another AWTA?
Would you attend another AWTA?

The full results are available here. Bret also did a nice writeup of the AWTA 2009 proceedings here.