ae_page_objects 0.5.1 → 0.5.2.mw1
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.
data/lib/ae_page_objects.rb
CHANGED
@@ -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 :VariableDocument, 'ae_page_objects/variable_document'
|
29
30
|
autoload :Element, 'ae_page_objects/element'
|
30
31
|
autoload :ElementProxy, 'ae_page_objects/element_proxy'
|
31
32
|
|
@@ -2,6 +2,60 @@ module AePageObjects
|
|
2
2
|
class Document < Node
|
3
3
|
include Concerns::Visitable
|
4
4
|
|
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}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
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
|
+
def site
|
55
|
+
@site ||= AePageObjects::Site.from(self)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
5
59
|
attr_reader :window
|
6
60
|
|
7
61
|
def initialize
|
@@ -14,12 +68,5 @@ module AePageObjects
|
|
14
68
|
def document
|
15
69
|
self
|
16
70
|
end
|
17
|
-
|
18
|
-
class << self
|
19
|
-
private
|
20
|
-
def site
|
21
|
-
@site ||= AePageObjects::Site.from(self)
|
22
|
-
end
|
23
|
-
end
|
24
71
|
end
|
25
72
|
end
|
@@ -2,13 +2,11 @@ module AePageObjects
|
|
2
2
|
class Collection < Element
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
+
attr_reader :item_locator
|
6
|
+
|
5
7
|
class << self
|
6
8
|
attr_accessor :item_class
|
7
9
|
|
8
|
-
def default_item_locator
|
9
|
-
@default_item_locator ||= [:xpath, ".//*"]
|
10
|
-
end
|
11
|
-
|
12
10
|
private
|
13
11
|
def inherited(subclass)
|
14
12
|
subclass.item_class = self.item_class
|
@@ -21,10 +19,6 @@ module AePageObjects
|
|
21
19
|
self.class.item_class
|
22
20
|
end
|
23
21
|
|
24
|
-
def item_xpath
|
25
|
-
@item_xpath ||= Capybara::Selector.normalize(*eval_locator(@item_locator)).xpaths.first
|
26
|
-
end
|
27
|
-
|
28
22
|
def at(index, &block)
|
29
23
|
if index >= size || index < 0
|
30
24
|
nil
|
@@ -56,7 +50,7 @@ module AePageObjects
|
|
56
50
|
def configure(options)
|
57
51
|
super
|
58
52
|
|
59
|
-
@item_locator = options.delete(:item_locator) ||
|
53
|
+
@item_locator = options.delete(:item_locator) || default_item_locator
|
60
54
|
end
|
61
55
|
|
62
56
|
def item_at(index, &block)
|
@@ -67,8 +61,16 @@ module AePageObjects
|
|
67
61
|
item_class
|
68
62
|
end
|
69
63
|
|
64
|
+
def item_xpath
|
65
|
+
@item_xpath ||= Capybara::Selector.normalize(*eval_locator(@item_locator)).xpaths.first
|
66
|
+
end
|
67
|
+
|
70
68
|
def item_locator_at(index)
|
71
69
|
[:xpath, "#{item_xpath}[#{index + 1}]"]
|
72
70
|
end
|
71
|
+
|
72
|
+
def default_item_locator
|
73
|
+
@default_item_locator ||= [:xpath, ".//*"]
|
74
|
+
end
|
73
75
|
end
|
74
76
|
end
|
@@ -1,10 +1,19 @@
|
|
1
1
|
module AePageObjects
|
2
|
-
class
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class StalePageObject < Error
|
5
|
+
end
|
6
|
+
|
7
|
+
class LoadingFailed < Error
|
3
8
|
end
|
4
9
|
|
5
|
-
class
|
10
|
+
class PathNotResolvable < Error
|
6
11
|
end
|
7
12
|
|
8
|
-
class
|
13
|
+
class PageNotFound < Error
|
9
14
|
end
|
15
|
+
|
16
|
+
class CastError < Error; end
|
17
|
+
class InvalidCast < CastError; end
|
18
|
+
class IncorrectCast < CastError; end
|
10
19
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
class VariableDocument
|
3
|
+
|
4
|
+
# Remove all instance methods so even things like class()
|
5
|
+
# get handled by method_missing(). <lifted from activerecord>
|
6
|
+
instance_methods.each do |m|
|
7
|
+
unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to|is_a?/
|
8
|
+
undef_method m
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(*documents)
|
13
|
+
@documents = documents
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_a?(document_class)
|
17
|
+
super || !! as_a(document_class)
|
18
|
+
rescue AePageObjects::Error
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def as_a(document_class)
|
23
|
+
unless @documents.include?(document_class)
|
24
|
+
raise InvalidCast, "Cannot cast as #{document_class.name} from #{@documents.map(&:name).inspect}"
|
25
|
+
end
|
26
|
+
|
27
|
+
document_class.new
|
28
|
+
rescue AePageObjects::LoadingFailed => e
|
29
|
+
raise IncorrectCast, "Failed instantiating a #{document_class}: #{e.message}\nDocuments: #{@documents.map(&:name).inspect}"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def implicit_document_class
|
35
|
+
@implicit_document_class ||= @documents.first
|
36
|
+
end
|
37
|
+
|
38
|
+
def implicit_document
|
39
|
+
@implicit_document ||= implicit_document_class.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(name, *args, &block)
|
43
|
+
implicit_document.__send__(name, *args, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def respond_to?(*args)
|
47
|
+
super || implicit_document_class.allocate.respond_to?(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_page_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 807327821
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
+
- 2
|
10
|
+
- mw
|
9
11
|
- 1
|
10
|
-
version: 0.5.
|
12
|
+
version: 0.5.2.mw1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Donnie Tognazzini
|
@@ -15,7 +17,7 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2013-10-
|
20
|
+
date: 2013-10-29 00:00:00 Z
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
23
|
name: capybara
|
@@ -66,6 +68,7 @@ files:
|
|
66
68
|
- lib/ae_page_objects/util/inflector.rb
|
67
69
|
- lib/ae_page_objects/util/internal_helpers.rb
|
68
70
|
- lib/ae_page_objects/util/singleton.rb
|
71
|
+
- lib/ae_page_objects/variable_document.rb
|
69
72
|
- lib/ae_page_objects/version.rb
|
70
73
|
- lib/ae_page_objects/window.rb
|
71
74
|
homepage: http://github.com/appfolio/ae_page_objects
|