Module: PageObject::PageFactory
- Includes:
- PageNavigation
- Defined in:
- lib/page-object/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/.
If you plan to use the navigate_to method you will need to ensure you setup the possible routes ahead of time. You must always have a default route in order for this to work. Here is an example of how you define routes:
Notice the first entry of :another_route is passing an argument to the method.
Instance Method Summary collapse
-
#if_page(page_class, params = {:using_params => {}}, &block) ⇒ PageObject
(also: #if)
Create a page object if and only if the current page is the same page to be created.
-
#on_page(page_class, params = {:using_params => {}}, visit = false, &block) ⇒ PageObject
(also: #on)
Create a page object.
-
#visit_page(page_class, params = {:using_params => {}}, &block) ⇒ PageObject
(also: #visit)
Create and navigate to a page object.
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.
91 92 93 94 95 |
# File 'lib/page-object/page_factory.rb', line 91 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_page(page_class, params = {:using_params => {}}, visit = false, &block) ⇒ PageObject Also known as: on
Create a page object.
available in the @params instance variable.
69 70 71 72 73 74 75 76 77 |
# File 'lib/page-object/page_factory.rb', line 69 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? PageObject 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) ⇒ PageObject 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.
PageObject module or a string containing the name of the class available in the @params instance variable.
52 53 54 |
# File 'lib/page-object/page_factory.rb', line 52 def visit_page(page_class, params={:using_params => {}}, &block) on_page page_class, params, true, &block end |