Class: WatirPump::Page
- Extended by:
- Forwardable
- Defined in:
- lib/watir_pump/page.rb
Overview
Representation of a single page of the application under test.
Implements Singleton
pattern.
Constant Summary collapse
- INSTANCE_DELEGATED_METHODS =
List of class methods forwarded to the singleton instance
%i[ browser open open_yield open_dsl use use_yield use_dsl act act_yield act_dsl loaded? matches_current_url? url_template ].freeze
Constants included from Constants
Constants::CLICKABLES, Constants::METHODS_FORWARDED_TO_ROOT, Constants::READABLES, Constants::WRITABLES
Instance Attribute Summary
Attributes inherited from Component
Class Method Summary collapse
-
.instance ⇒ Page
Returns singleton instance of current Page.
-
.uri(uri = nil) ⇒ Object
Class macro declaring Page’s URI template.
Instance Method Summary collapse
-
#loaded? ⇒ Boolean
Predicate denoting if page is ready to be interacted with Overload in child class to customize the readiness criteria.
-
#matches_current_url? ⇒ Boolean
Predicate denoting if current browser URL matches pages ‘uri` template.
-
#open(params = {}, &blk) ⇒ Object
Opens the page in the browser and executes passed block in the scope of the page instance.
-
#open_dsl(params = {}, &blk) ⇒ Object
Opens the page in the browser and executes passed block in the scope of the page instance (
instance_exec
). -
#open_yield(params = {}, &blk) ⇒ Object
Opens the page in the browser and executes passed block in the scope of the page instance.
-
#url_template ⇒ String
Returns complete (base plus URI) URL template for current Page.
-
#use(&blk) ⇒ Object
(also: #act)
Executes passed block in the scope of the page instance.
-
#use_dsl(&blk) ⇒ Object
(also: #act_dsl)
Executes passed block in the scope of the page instance.
-
#use_yield {|_self, browser| ... } ⇒ Object
(also: #act_yield)
Executes passed block in the scope of the page instance.
-
#wait_for_loaded ⇒ Page
Waits until current Page is loaded.
Methods inherited from Component
component, components, custom_reader, custom_writer, decorate, element, elements, #fill_form, #fill_form!, #form_data, form_field_readers, form_field_writers, #initialize, #inspect, inspect_properties, query, region, #root
Methods included from Components::Flag
#flag_accessor, #flag_reader, #flag_writer
Methods included from Components::DropdownList
#select_accessor, #select_reader, #select_writer
Methods included from Components::CheckboxGroup
#checkbox_accessor, #checkbox_reader, #checkbox_writer
Methods included from Components::RadioGroup
#radio_accessor, #radio_reader, #radio_writer
Constructor Details
This class inherits a constructor from WatirPump::Component
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class WatirPump::Component
Class Method Details
.instance ⇒ Page
Returns singleton instance of current Page
47 48 49 |
# File 'lib/watir_pump/page.rb', line 47 def instance @instance ||= new(WatirPump.config.browser) end |
.uri(uri = nil) ⇒ Object
Class macro declaring Page’s URI template. Example: ‘/jobs/{job_id}’
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/watir_pump/page.rb', line 32 def uri(uri = nil) return @uri if @uri if uri.nil? ancestors[1..-1].each do |a| return @uri = a.uri if a.respond_to?(:uri) && a.uri end else @uri = uri end @uri end |
Instance Method Details
#loaded? ⇒ Boolean
Predicate denoting if page is ready to be interacted with Overload in child class to customize the readiness criteria
166 167 168 |
# File 'lib/watir_pump/page.rb', line 166 def loaded? matches_current_url? end |
#matches_current_url? ⇒ Boolean
Predicate denoting if current browser URL matches pages ‘uri` template
173 174 175 |
# File 'lib/watir_pump/page.rb', line 173 def matches_current_url? Addressable::Template.new(url_template).match browser.url end |
#open(params = {}, &blk) ⇒ Object
Opens the page in the browser and executes passed block in the scope of the page instance. Depending on the value of WatirPump.config.call_page_blocks_with_yield
method #open_yield or #open_dsl is called internally
65 66 67 68 69 70 71 |
# File 'lib/watir_pump/page.rb', line 65 def open(params = {}, &blk) if WatirPump.config.call_page_blocks_with_yield open_yield(params, &blk) else open_dsl(params, &blk) end end |
#open_dsl(params = {}, &blk) ⇒ Object
Opens the page in the browser and executes passed block in the scope of the page instance (instance_exec
).
101 102 103 104 105 106 |
# File 'lib/watir_pump/page.rb', line 101 def open_dsl(params = {}, &blk) url = Addressable::Template.new(url_template).(params).to_s browser.goto url use_dsl(&blk) if block_given? self end |
#open_yield(params = {}, &blk) ⇒ Object
Opens the page in the browser and executes passed block in the scope of the page instance. Current page
and browser
references are passed to the yielded block.
84 85 86 87 88 89 |
# File 'lib/watir_pump/page.rb', line 84 def open_yield(params = {}, &blk) url = Addressable::Template.new(url_template).(params).to_s browser.goto url use_yield(&blk) if block_given? self end |
#url_template ⇒ String
Returns complete (base plus URI) URL template for current Page
55 56 57 |
# File 'lib/watir_pump/page.rb', line 55 def url_template WatirPump.config.base_url + self.class.uri end |
#use(&blk) ⇒ Object Also known as: act
Executes passed block in the scope of the page instance. Depending on the value of WatirPump.config.call_page_blocks_with_yield
method #use_yield or #use_dsl is called internally
112 113 114 115 116 117 118 |
# File 'lib/watir_pump/page.rb', line 112 def use(&blk) if WatirPump.config.call_page_blocks_with_yield use_yield(&blk) else use_dsl(&blk) end end |
#use_dsl(&blk) ⇒ Object Also known as: act_dsl
Executes passed block in the scope of the page instance. (instance_exec
)
145 146 147 148 149 |
# File 'lib/watir_pump/page.rb', line 145 def use_dsl(&blk) wait_for_loaded instance_exec(&blk) self end |
#use_yield {|_self, browser| ... } ⇒ Object Also known as: act_yield
Executes passed block in the scope of the page instance. Current page
and browser
references are passed to the yielded block.
130 131 132 133 134 |
# File 'lib/watir_pump/page.rb', line 130 def use_yield wait_for_loaded yield self, browser self end |
#wait_for_loaded ⇒ Page
Waits until current Page is loaded
155 156 157 158 159 160 |
# File 'lib/watir_pump/page.rb', line 155 def wait_for_loaded Watir::Wait.until(message: "Timeout waiting for #{self} to load") do loaded? end self end |