ae_page_objects 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37647af3548c32ece7a0c1097ea2f76cdadb9257
4
- data.tar.gz: bb6472c8b228dec715c2bab1b3d5ce8186eea420
3
+ metadata.gz: 545addc7d4b910134d2bbb7a29b6ec990cc190e5
4
+ data.tar.gz: 747b5268236901cc5cdf3bfadfa50ff2e9b6cd80
5
5
  SHA512:
6
- metadata.gz: 6324e07193b89af313304a1fa1847e308f0231551dea1748c579bb9461a0ab25799ed9f7c0f5b8dabc213773b1cd55a24f51d7d6a551d00a2a6cc3a4597c87ee
7
- data.tar.gz: 919e40103c069c3f2c7938afcdec2a15926b0a3ec5dc1fddd9bf7a57fd77391e9b73554fdece836ae93dc7780251cb0b7dbed2c6df0b01ff560423f1fe2d9edd
6
+ metadata.gz: ccff7683bc850c05d0e5f055fa39e92f4bee5f489e43cd1a01a97a90a931802ea493c5f9baa666bf89728f4c0f0a8e35ee281cd8eca869f7482cff47195ba289
7
+ data.tar.gz: eafb28c8a5e4ef4e3e450c4dc624064fcf1ecfee5ee7903dedade84853d71155c34687051ee08ecbb5027894c987e244fa102ec89368e9997bd95d5c2fcf7cd4
@@ -3,6 +3,7 @@ require 'capybara/dsl'
3
3
 
4
4
  require 'ae_page_objects/version'
5
5
  require 'ae_page_objects/exceptions'
6
+ require 'ae_page_objects/util/page_polling'
6
7
 
7
8
  module AePageObjects
8
9
  autoload :Node, 'ae_page_objects/node'
@@ -15,6 +16,8 @@ module AePageObjects
15
16
  autoload :Checkbox, 'ae_page_objects/elements/checkbox'
16
17
 
17
18
  class << self
19
+ include PagePolling
20
+
18
21
  attr_accessor :default_router
19
22
 
20
23
  def browser
@@ -50,8 +53,6 @@ module AePageObjects
50
53
  result
51
54
  end
52
55
 
53
- private
54
-
55
56
  def default_max_wait_time
56
57
  if Capybara.respond_to?(:default_max_wait_time)
57
58
  Capybara.default_max_wait_time
@@ -13,8 +13,12 @@ module AePageObjects
13
13
  begin
14
14
  poll_until do
15
15
  @query.conditions.each do |document_condition|
16
- if document = @strategy.load_document_with_condition(document_condition)
17
- return document
16
+ begin
17
+ if document = @strategy.load_document_with_condition(document_condition)
18
+ return document
19
+ end
20
+ rescue => e
21
+ raise unless catch_poll_util_error?(e)
18
22
  end
19
23
  end
20
24
 
@@ -127,21 +127,12 @@ module AePageObjects
127
127
  @loaded_element = nil
128
128
 
129
129
  true
130
- rescue => e
131
- if Capybara.current_session.driver.is_a?(Capybara::Selenium::Driver) &&
132
- e.is_a?(Selenium::WebDriver::Error::StaleElementReferenceError)
133
-
134
- # Inconclusive. Leave the handling up to the caller
135
- false
136
- else
137
- raise
138
- end
139
130
  end
140
131
 
141
132
  def with_reloaded_element(timeout)
142
133
  poll_until(timeout) do
143
- reload_conclusive = reload_element
144
- reload_conclusive && yield
134
+ reload_element
135
+ yield
145
136
  end
146
137
  end
147
138
  end
@@ -1,11 +1,52 @@
1
1
  module AePageObjects
2
2
  module PagePolling
3
+ # Quickly polls the block until it returns (as opposed to throwing an exception). Using poll
4
+ # is a safer alternative to,
5
+ #
6
+ # Capybara.using_wait_time(0) do
7
+ # has_content?('Admin')
8
+ # end
9
+ #
10
+ # where we want to determine whether 'Admin' is on the page (without waiting for it to appear).
11
+ # This is often used to switch login / functionality of page objects based on the state of the
12
+ # page.
13
+ #
14
+ # With poll, the above patterns becomes,
15
+ #
16
+ # AePageObjects.poll do
17
+ # has_content?('Admin')
18
+ # end
19
+ def poll(seconds_to_wait = nil, &block)
20
+ result = nil
21
+ poll_until(seconds_to_wait) do
22
+ result = block.call
23
+ true
24
+ end
25
+ result
26
+ end
3
27
 
4
- private
28
+ # Quickly polls the block until it returns something truthy. This is a helper function for
29
+ # special cases and probably NOT what you want to use. See AePageObjects#wait_until or
30
+ # #poll.
31
+ def poll_until(seconds_to_wait = nil, &block)
32
+ AePageObjects.wait_until(seconds_to_wait) do
33
+ # Capybara normally catches errors and retries. However, with the wait time of zero,
34
+ # capybara catches the errors and immediately reraises them. So we have to catch
35
+ # those errors in the similar fashion to capybara such that we properly can wait the
36
+ # whole seconds_to_wait.
37
+ begin
38
+ Capybara.using_wait_time(0, &block)
39
+ rescue => e
40
+ raise unless catch_poll_until_error?(e)
41
+ nil
42
+ end
43
+ end
44
+ end
5
45
 
6
- def poll_until(timeout = nil, &block)
7
- AePageObjects.wait_until(timeout) do
8
- Capybara.using_wait_time(0, &block)
46
+ def catch_poll_until_error?(error)
47
+ types = Capybara.current_session.driver.invalid_element_errors + [Capybara::ElementNotFound]
48
+ types.any? do |type|
49
+ error.is_a?(type)
9
50
  end
10
51
  end
11
52
  end
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donnie Tognazzini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara