Module: Pagetience
- Defined in:
- lib/pagetience.rb,
lib/pagetience/dsl.rb,
lib/pagetience/version.rb,
lib/pagetience/meditate.rb,
lib/pagetience/configuration.rb,
lib/pagetience/platforms/page-object-gem.rb
Defined Under Namespace
Modules: ClassMethods, DSL, Platform Classes: Configuration, ConfigurationError, Meditate, PlatformError, TimeoutError
Constant Summary collapse
- VERSION =
'0.4.3'
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#_required_elements ⇒ Object
“Private” methods to avoid naming collision but remain helpful They can be messed with though, if you ever see fit.
-
#_waiting_polling ⇒ Object
“Private” methods to avoid naming collision but remain helpful They can be messed with though, if you ever see fit.
-
#_waiting_timeout ⇒ Object
“Private” methods to avoid naming collision but remain helpful They can be messed with though, if you ever see fit.
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#element_platform ⇒ Object
readonly
Returns the value of attribute element_platform.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(*args) ⇒ Object
- #loaded? ⇒ Boolean
-
#wait_for(opts = {}, &block) ⇒ Object
Generic waiting method Valid options: :timeout = Time to wait in seconds :polling = How often to poll :expecting = The expected result for the block to return :msg = The exception message if the timeout occurs.
-
#wait_for_element(sym, timeout = nil, polling = nil) ⇒ Object
Wait for an element to be present.
-
#wait_for_required_elements(timeout = nil, polling = nil) ⇒ Object
Waits for all elements specified by .required to be present.
-
#wait_for_transition_to(page, timeout = nil, polling = nil) ⇒ Object
Wait for a transition to another page.
Class Attribute Details
.config ⇒ Object
15 16 17 |
# File 'lib/pagetience.rb', line 15 def config @config ||= Configuration.new end |
Instance Attribute Details
#_required_elements ⇒ Object
“Private” methods to avoid naming collision but remain helpful They can be messed with though, if you ever see fit.
44 45 46 |
# File 'lib/pagetience.rb', line 44 def _required_elements @_required_elements end |
#_waiting_polling ⇒ Object
“Private” methods to avoid naming collision but remain helpful They can be messed with though, if you ever see fit.
44 45 46 |
# File 'lib/pagetience.rb', line 44 def _waiting_polling @_waiting_polling end |
#_waiting_timeout ⇒ Object
“Private” methods to avoid naming collision but remain helpful They can be messed with though, if you ever see fit.
44 45 46 |
# File 'lib/pagetience.rb', line 44 def _waiting_timeout @_waiting_timeout end |
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
46 47 48 |
# File 'lib/pagetience.rb', line 46 def browser @browser end |
#element_platform ⇒ Object (readonly)
Returns the value of attribute element_platform.
47 48 49 |
# File 'lib/pagetience.rb', line 47 def element_platform @element_platform end |
Class Method Details
.configure {|config| ... } ⇒ Object
19 20 21 |
# File 'lib/pagetience.rb', line 19 def configure yield config end |
.included(base) ⇒ Object
49 50 51 |
# File 'lib/pagetience.rb', line 49 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#initialize(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pagetience.rb', line 53 def initialize(*args) @browser = args[0] set_current_page @element_platform = Pagetience.config.platform.init self, args @loaded = false @_waiting_timeout = _waiting_timeout || Pagetience.config.timeout @_waiting_polling = _waiting_polling || Pagetience.config.polling @_required_elements = _required_elements || [] @_present_elements = [] @_missing_elements = [] wait_for_required_elements end |
#loaded? ⇒ Boolean
68 69 70 |
# File 'lib/pagetience.rb', line 68 def loaded? !!@loaded end |
#wait_for(opts = {}, &block) ⇒ Object
Generic waiting method Valid options: :timeout = Time to wait in seconds :polling = How often to poll :expecting = The expected result for the block to return :msg = The exception message if the timeout occurs
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pagetience.rb', line 129 def wait_for(opts={}, &block) opts = { timeout: @_waiting_timeout, polling: @_waiting_polling, expecting: true, msg: "Timed out after waiting for #{@_waiting_timeout}s, polling every #{@_waiting_polling}s." }.merge(opts) do |key, old, new| new.nil? ? old : new end Pagetience::Meditate.for(opts) { block.call } end |
#wait_for_element(sym, timeout = nil, polling = nil) ⇒ Object
Wait for an element to be present
99 100 101 102 103 104 105 106 |
# File 'lib/pagetience.rb', line 99 def wait_for_element(sym, timeout=nil, polling=nil) opts = { timeout: timeout, polling: polling, msg: "Timed out after waiting for the element #{sym} to be present." } wait_for(opts) { @element_platform.is_element_present? sym } end |
#wait_for_required_elements(timeout = nil, polling = nil) ⇒ Object
Waits for all elements specified by .required to be present
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/pagetience.rb', line 75 def wait_for_required_elements(timeout=nil, polling=nil) msg = -> do %{Timed out after polling every #{@_waiting_polling}s for #{@_waiting_timeout}s waiting for the page to be loaded. Elements present: #{@_present_elements} Elements missing: #{@_missing_elements}} end opts = { timeout: timeout, polling: polling, msg: msg } wait_for(opts) do @_missing_elements = [] @_required_elements.each do |e| if !@element_platform.is_element_present?(e) && !@_missing_elements.include?(e) @_missing_elements << e @_present_elements = @_required_elements - @_missing_elements end end @loaded = @_missing_elements.empty? end end |
#wait_for_transition_to(page, timeout = nil, polling = nil) ⇒ Object
Wait for a transition to another page
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/pagetience.rb', line 111 def wait_for_transition_to(page, timeout=nil, polling=nil) page = page.new browser opts = { timeout: timeout, polling: polling, msg: "Timed out after waiting for the page to transition to #{page}." } wait_for(opts) { page.loaded? } page end |