Sha256: 333f4f544acdd992181a21e0c33974e6c1b1ff8ce35b536821ee6107f6815812

Contents?: true

Size: 1.68 KB

Versions: 9

Compression:

Stored size: 1.68 KB

Contents

module PageObject
  #
  # 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 http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/.
  #
  # @example Making the PageFactory available to your step definitions
  #   World PageObject::PageFactory
  #
  # @example Visiting a page for the first time in a Scenario
  #   visit_page MyPageObject do |page|
  #     page.name = 'Cheezy'
  #   end
  #
  # @example using a page that has already been visited in a Scenario
  #   on_page MyPageObject do |page|
  #     page.name.should == 'Cheezy'
  #   end
  #
  module PageFactory

    #
    # Create and navigate to a page object.  The navigation will only work if the
    # 'page_url' method was call on the page object.
    #
    # @param [PageObject] a class that has included the PageObject module
    # @param an optional block to be called
    # @return [PageObject] the newly created page object
    #
    def visit_page(page_class, &block)
      on_page page_class, true, &block
    end

    #
    # Create a page object.
    #
    # @param [PageObject]  a class that has included the PageObject module
    # @param [Boolean]  a boolean indicating if the page should be visited?  default is false.
    # @param [block]  an optional block to be called
    # @return [PageObject] the newly created page object
    #
    def on_page(page_class, visit=false, &block)
      @current_page = page_class.new(@browser, visit)
      block.call @current_page if block
      @current_page
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
page-object-0.5.5 lib/page-object/page_factory.rb
page-object-0.5.4 lib/page-object/page_factory.rb
page-object-0.5.3 lib/page-object/page_factory.rb
page-object-0.5.2 lib/page-object/page_factory.rb
page-object-0.5.1 lib/page-object/page_factory.rb
page-object-0.5.0 lib/page-object/page_factory.rb
page-object-0.4.4 lib/page-object/page_factory.rb
page-object-0.4.3 lib/page-object/page_factory.rb
page-object-0.4.2 lib/page-object/page_factory.rb