Module: EDSL::PageObject::Visitation

Includes:
PageNavigation
Defined in:
lib/edsl/page_object/visitation.rb

Overview

Most of this is a semi-direct copy from PageObject::PageFactory

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.current_pageObject



81
82
83
# File 'lib/edsl/page_object/visitation.rb', line 81

def self.current_page
  @@current_page
end

Instance Method Details

#if_page(page_class, params = {:using_params => {}}, &block) ⇒ PageObject Also known as: if

Create a page object if and only if the current page is the same page to be created

available in the @params instance variable.

Parameters:

  • a (PageObject, String)

    class that has included the PageObject module or a string containing the name of the class

  • Hash

    values that is pass through to page class a

  • an (block)

    optional block to be called

Returns:



102
103
104
105
106
# File 'lib/edsl/page_object/visitation.rb', line 102

def if_page(page_class, params={:using_params => {}},&block)
  page_class = class_from_string(page_class) if page_class.is_a? String
  return @@current_page unless @@current_page.class == page_class
  on_page(page_class, params, false, &block)
end

#on_current_page {|@@current_page| ... } ⇒ Object

Yields:



88
89
90
91
# File 'lib/edsl/page_object/visitation.rb', line 88

def on_current_page(&block)
  yield @@current_page if block
  @@current_page
end

#on_page(page_class, params = {:using_params => {}}, visit = false, &block) ⇒ Page Also known as: on

Create a page object.

the @params instance variable.

Parameters:

  • page_class (Page, String)

    the page class to create

  • params (Hash) (defaults to: {:using_params => {}})

    values that is passed through to page class available in

  • visit (Boolean) (defaults to: false)

    a boolean indicating if the page should be visited? default is false.

Returns:

  • (Page)

    the newly created page



71
72
73
74
75
76
77
78
79
# File 'lib/edsl/page_object/visitation.rb', line 71

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

#visit_page(page_class, params = {:using_params => {}}, &block) ⇒ Page Also known as: visit

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

the @params instance variable.

Parameters:

  • page_class (Page, String)

    the page class to create

  • params (Hash) (defaults to: {:using_params => {}})

    values that is passed through to page class available in

Returns:

  • (Page)

    the newly created page



53
54
55
# File 'lib/edsl/page_object/visitation.rb', line 53

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