Module: Druid::PageFactory

Defined in:
lib/druid/page_factory.rb

Overview

Module to facilitate to creating of page objects in step definitions. You can make the methods below available to all of your step definitions by adding this module to World. This idea was first discussed in Alister Scott’s blog entry watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/.

Examples:

Making the PageFactory available to your step definitions

World Druid::PageFactory

Visiting a page for the first time in a Scenario

visit_page MyPageObject do |page|
  page.name = 'Tim'
end

using a page that has already been visited in a Scenario

on_page MyPageObject do |page|
  page.name.should == 'Tim'
end

Instance Method Summary collapse

Instance Method Details

#on_page(page_class, visit = false) {|@current_page| ... } ⇒ PageObject

Create a page object.

Parameters:

  • a (page_class)

    class that has included the Druid module

  • should (Bool)

    the page be visited? default is false.

  • an

    optional block to be called

Yields:

  • (@current_page)

Returns:

  • (PageObject)

    the newly created page object



42
43
44
45
46
# File 'lib/druid/page_factory.rb', line 42

def on_page(page_class, visit=false, &block)
  @current_page = page_class.new(@driver, visit)
  yield @current_page if block_given?
  @current_page
end

#visit_page(page_class, &block) ⇒ PageObject

attr_accessor :page

Create and navigate to a page object. The navigation will only work if the ‘page_url’ method was call on the page object.

Parameters:

  • a (page_class)

    class that has included the Druid module

  • an

    optional block to be called

Returns:

  • (PageObject)

    the newly created page object



31
32
33
# File 'lib/druid/page_factory.rb', line 31

def visit_page(page_class, &block)
  on_page page_class, true, &block
end