Module: CapybaraPageObject::PageFactory

Defined in:
lib/capybara_page_object/page_factory.rb

Overview

Examples:

Making the PageFactory available to your step definitions

World(CapybaraPageObject::PageFactory)

Visiting a page for the first time in a Scenario

goto_page MyPage do |page|
   ...
end

using a page that has already been visited in a Scenario

on_page MyPage do |page|
  ....
end

Instance Method Summary collapse

Instance Method Details

#goto_page(page_class, params = {:using_params => {}}, &block) ⇒ PageObject

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

PageObject module or a string containing the name of the class available in the @params instance variable.

Parameters:

  • a (PageObject, String)

    class that has included the

  • Hash

    values that is pass through to page class a

  • an

    optional block to be called

Returns:



29
30
31
# File 'lib/capybara_page_object/page_factory.rb', line 29

def goto_page(page_class, params={:using_params => {}}, &block)
  new_page(page_class, params, true, &block)
end

#new_page(page_class, params = {:using_params => {}}, visit = false, &block) ⇒ Object

Create a page object.



36
37
38
39
40
41
42
43
# File 'lib/capybara_page_object/page_factory.rb', line 36

def new_page(page_class, params={:using_params => {}}, visit=false, &block)
  page_class = class_from_string(page_class) if page_class.is_a? String
  merged = page_class.params.merge(params[:using_params])
  page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
  @current_page = page_class.new(visit)
  block.call @current_page if block
  @current_page
end