ae_page_objects 0.5.2.mw1 → 0.5.2.mw2

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,7 @@ module AePageObjects
26
26
  autoload :Window, 'ae_page_objects/window'
27
27
  autoload :Node, 'ae_page_objects/node'
28
28
  autoload :Document, 'ae_page_objects/document'
29
+ autoload :DocumentFinder, 'ae_page_objects/document_finder'
29
30
  autoload :VariableDocument, 'ae_page_objects/variable_document'
30
31
  autoload :Element, 'ae_page_objects/element'
31
32
  autoload :ElementProxy, 'ae_page_objects/element_proxy'
@@ -3,54 +3,12 @@ module AePageObjects
3
3
  include Concerns::Visitable
4
4
 
5
5
  class << self
6
-
7
- def find(&extra_condition)
8
- original_window = AePageObjects::Window.current
9
-
10
- # Loop through all the windows and attempt to instantiate the Document. Continue to loop around
11
- # until finding a Document that can be instantiated or timing out.
12
- Capybara.wait_until do
13
- find_window(&extra_condition)
14
- end
15
-
16
- rescue Capybara::TimeoutError
17
- original_window.switch_to
18
-
19
- all_windows = AePageObjects::Window.all.map do |window|
20
- name = window.current_document && window.current_document.to_s || "<none>"
21
- {:window_handle => window.handle, :document => name }
22
- end
23
-
24
- raise PageNotFound, "Couldn't find page #{self.name} in any of the open windows: #{all_windows.inspect}"
6
+ def find(*args, &block)
7
+ DocumentFinder.new(self).find(*args, &block)
25
8
  end
26
9
 
27
10
  private
28
11
 
29
- def find_window(&extra_condition)
30
- AePageObjects::Window.all.each do |window|
31
- window.switch_to
32
-
33
- if inst = attempt_to_load(&extra_condition)
34
- return inst
35
- end
36
- end
37
-
38
- nil
39
- end
40
-
41
- def attempt_to_load(&extra_condition)
42
- inst = new
43
-
44
- if extra_condition.nil? || inst.instance_eval(&extra_condition)
45
- return inst
46
- end
47
-
48
- nil
49
- rescue AePageObjects::LoadingFailed
50
- # These will happen from the new() call above.
51
- nil
52
- end
53
-
54
12
  def site
55
13
  @site ||= AePageObjects::Site.from(self)
56
14
  end
@@ -69,4 +27,4 @@ module AePageObjects
69
27
  self
70
28
  end
71
29
  end
72
- end
30
+ end
@@ -0,0 +1,77 @@
1
+ module AePageObjects
2
+ class DocumentFinder
3
+
4
+ def initialize(document_class)
5
+ @document_class = document_class
6
+ end
7
+
8
+ class Conditions
9
+ def initialize(conditions, block_condition)
10
+ @conditions = conditions || {}
11
+ @conditions[:block] = block_condition if block_condition
12
+ end
13
+
14
+ def match?(page)
15
+ @conditions.each do |type, value|
16
+ case type
17
+ when :title then
18
+ return false unless browser.title.include?(value)
19
+ when :url then
20
+ return false unless page.current_url.include?(value)
21
+ when :block then
22
+ return false unless value.call(page)
23
+ end
24
+ end
25
+
26
+ true
27
+ end
28
+ end
29
+
30
+ def find(conditions = {}, &extra_condition)
31
+ original_window = AePageObjects::Window.current
32
+
33
+ # Loop through all the windows and attempt to instantiate the Document. Continue to loop around
34
+ # until finding a Document that can be instantiated or timing out.
35
+ Capybara.wait_until do
36
+ find_window(Conditions.new(conditions, extra_condition))
37
+ end
38
+
39
+ rescue Capybara::TimeoutError
40
+ original_window.switch_to
41
+
42
+ all_windows = AePageObjects::Window.all.map do |window|
43
+ name = window.current_document && window.current_document.to_s || "<none>"
44
+ {:window_handle => window.handle, :document => name }
45
+ end
46
+
47
+ raise PageNotFound, "Couldn't find page #{@document_class.name} in any of the open windows: #{all_windows.inspect}"
48
+ end
49
+
50
+ private
51
+
52
+ def find_window(conditions)
53
+ AePageObjects::Window.all.each do |window|
54
+ window.switch_to
55
+
56
+ if inst = attempt_to_load(conditions)
57
+ return inst
58
+ end
59
+ end
60
+
61
+ nil
62
+ end
63
+
64
+ def attempt_to_load(conditions)
65
+ inst = @document_class.new
66
+
67
+ if conditions.match?(inst)
68
+ return inst
69
+ end
70
+
71
+ nil
72
+ rescue AePageObjects::LoadingFailed
73
+ # These will happen from the new() call above.
74
+ nil
75
+ end
76
+ end
77
+ end
@@ -36,7 +36,7 @@ module AePageObjects
36
36
  end
37
37
 
38
38
  def implicit_document
39
- @implicit_document ||= implicit_document_class.new
39
+ @implicit_document ||= as_a(implicit_document_class)
40
40
  end
41
41
 
42
42
  def method_missing(name, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module AePageObjects
2
- VERSION = '0.5.2.mw1'.freeze
2
+ VERSION = '0.5.2.mw2'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_page_objects
3
3
  version: !ruby/object:Gem::Version
4
- hash: 807327821
4
+ hash: -4066462860
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
9
  - 2
10
10
  - mw
11
- - 1
12
- version: 0.5.2.mw1
11
+ - 2
12
+ version: 0.5.2.mw2
13
13
  platform: ruby
14
14
  authors:
15
15
  - Donnie Tognazzini
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2013-10-29 00:00:00 Z
20
+ date: 2013-11-08 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: capybara
@@ -56,6 +56,7 @@ files:
56
56
  - lib/ae_page_objects/core/universe.rb
57
57
  - lib/ae_page_objects/core_ext/module.rb
58
58
  - lib/ae_page_objects/document.rb
59
+ - lib/ae_page_objects/document_finder.rb
59
60
  - lib/ae_page_objects/element.rb
60
61
  - lib/ae_page_objects/element_proxy.rb
61
62
  - lib/ae_page_objects/elements/checkbox.rb