ae_page_objects 1.0.2 → 1.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 +4 -4
- data/lib/ae_page_objects.rb +34 -2
- data/lib/ae_page_objects/core/application_router.rb +16 -0
- data/lib/ae_page_objects/document.rb +10 -12
- data/lib/ae_page_objects/document_loader.rb +30 -0
- data/lib/ae_page_objects/document_proxy.rb +47 -0
- data/lib/ae_page_objects/document_query.rb +68 -0
- data/lib/ae_page_objects/element.rb +8 -0
- data/lib/ae_page_objects/exceptions.rb +8 -3
- data/lib/ae_page_objects/multiple_windows/browser.rb +22 -0
- data/lib/ae_page_objects/multiple_windows/cross_window_loader_strategy.rb +49 -0
- data/lib/ae_page_objects/multiple_windows/window.rb +28 -0
- data/lib/ae_page_objects/multiple_windows/window_handle_manager.rb +50 -0
- data/lib/ae_page_objects/multiple_windows/window_list.rb +43 -0
- data/lib/ae_page_objects/single_window/browser.rb +11 -0
- data/lib/ae_page_objects/single_window/same_window_loader_strategy.rb +33 -0
- data/lib/ae_page_objects/single_window/window.rb +23 -0
- data/lib/ae_page_objects/version.rb +1 -1
- data/lib/ae_page_objects/window.rb +9 -116
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5334b6a4fd2514a439fa323284a5893cb21005ca
|
4
|
+
data.tar.gz: 64a263fd884d0e933ebf8000ad88ed689dc3f601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af8bd7d6c91c8865641f2673cba8244ccc4d5db142bc95591f70dc57fdc2ecec8f924dfc71fe6fc38627b36fc5e1a1e8007d970b06a65ff17113f5b7f915fe3
|
7
|
+
data.tar.gz: 2b3d973eb84a26923bd6db1dcbec1bcdc18a85a923f98e3f60dfeed2b44e7ffaffa886fb88c6bc9695f565baa12fc5a0ea7a3818e311ff004a299072388b1e6f
|
data/lib/ae_page_objects.rb
CHANGED
@@ -23,17 +23,49 @@ module AePageObjects
|
|
23
23
|
autoload :Staleable, 'ae_page_objects/concerns/staleable'
|
24
24
|
autoload :Visitable, 'ae_page_objects/concerns/visitable'
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
module MultipleWindows
|
28
|
+
autoload :Browser, 'ae_page_objects/multiple_windows/browser'
|
29
|
+
autoload :Window, 'ae_page_objects/multiple_windows/window'
|
30
|
+
autoload :CrossWindowLoaderStrategy, 'ae_page_objects/multiple_windows/cross_window_loader_strategy'
|
31
|
+
autoload :WindowList, 'ae_page_objects/multiple_windows/window_list'
|
32
|
+
autoload :WindowHandleManager, 'ae_page_objects/multiple_windows/window_handle_manager'
|
33
|
+
end
|
34
|
+
|
35
|
+
module SingleWindow
|
36
|
+
autoload :Browser, 'ae_page_objects/single_window/browser'
|
37
|
+
autoload :Window, 'ae_page_objects/single_window/window'
|
38
|
+
autoload :SameWindowLoaderStrategy, 'ae_page_objects/single_window/same_window_loader_strategy'
|
39
|
+
end
|
40
|
+
|
27
41
|
autoload :Window, 'ae_page_objects/window'
|
42
|
+
|
43
|
+
autoload :DocumentQuery, 'ae_page_objects/document_query'
|
44
|
+
autoload :DocumentLoader, 'ae_page_objects/document_loader'
|
45
|
+
|
28
46
|
autoload :Node, 'ae_page_objects/node'
|
29
47
|
autoload :Document, 'ae_page_objects/document'
|
48
|
+
autoload :DocumentProxy, 'ae_page_objects/document_proxy'
|
30
49
|
autoload :Element, 'ae_page_objects/element'
|
31
50
|
autoload :ElementProxy, 'ae_page_objects/element_proxy'
|
32
51
|
|
33
52
|
autoload :Collection, 'ae_page_objects/elements/collection'
|
34
53
|
autoload :Form, 'ae_page_objects/elements/form'
|
35
54
|
autoload :Select, 'ae_page_objects/elements/select'
|
36
|
-
autoload :Checkbox, 'ae_page_objects/elements/checkbox'
|
55
|
+
autoload :Checkbox, 'ae_page_objects/elements/checkbox'
|
56
|
+
|
57
|
+
def self.browser
|
58
|
+
@browser ||= begin
|
59
|
+
driver = Capybara.current_session.driver
|
60
|
+
|
61
|
+
case driver
|
62
|
+
when Capybara::Selenium::Driver then
|
63
|
+
MultipleWindows::Browser.new
|
64
|
+
else
|
65
|
+
SingleWindow::Browser.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
37
69
|
end
|
38
70
|
|
39
71
|
require 'ae_page_objects/core_ext/module'
|
@@ -93,6 +93,19 @@ module AePageObjects
|
|
93
93
|
[url, router]
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
class Rails4 < Rails32
|
98
|
+
|
99
|
+
private
|
100
|
+
def url_and_router(url)
|
101
|
+
require 'action_dispatch/journey'
|
102
|
+
url = ActionDispatch::Journey::Router::Utils.normalize_path(url) unless url =~ %r{://}
|
103
|
+
router = Rails.application.routes.router
|
104
|
+
|
105
|
+
[url, router]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
96
109
|
end
|
97
110
|
|
98
111
|
def path_recognizes_url?(path, url)
|
@@ -121,6 +134,9 @@ module AePageObjects
|
|
121
134
|
Recognizer::Rails3.new
|
122
135
|
elsif Rails.version =~ /\A3\.2/
|
123
136
|
Recognizer::Rails32.new
|
137
|
+
elsif Rails.version =~ /\A4\.[01]/
|
138
|
+
warn "[WARNING]: AePageObjects works but is not thoroughly tested against Rails 4. Caveat emptor."
|
139
|
+
Recognizer::Rails4.new
|
124
140
|
else
|
125
141
|
warn "[WARNING]: AePageObjects is not tested against Rails #{Rails.version} and may behave in an undefined manner."
|
126
142
|
Recognizer::Rails32.new
|
@@ -2,25 +2,23 @@ module AePageObjects
|
|
2
2
|
class Document < Node
|
3
3
|
include Concerns::Visitable
|
4
4
|
|
5
|
+
attr_reader :window
|
6
|
+
|
5
7
|
def initialize
|
6
8
|
super(Capybara.current_session)
|
7
|
-
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
super(Capybara.current_session)
|
10
|
+
@window = browser.current_window
|
11
|
+
@window.current_document = self
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
14
|
+
def browser
|
15
|
+
AePageObjects.browser
|
18
16
|
end
|
19
|
-
|
17
|
+
|
20
18
|
def document
|
21
19
|
self
|
22
20
|
end
|
23
|
-
|
21
|
+
|
24
22
|
class << self
|
25
23
|
private
|
26
24
|
def site
|
@@ -28,4 +26,4 @@ module AePageObjects
|
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
31
|
-
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
class DocumentLoader
|
3
|
+
def initialize(query, strategy)
|
4
|
+
@query = query
|
5
|
+
@strategy = strategy
|
6
|
+
end
|
7
|
+
|
8
|
+
def default_document_class
|
9
|
+
@default_document_class ||= @query.conditions.first.document_class
|
10
|
+
end
|
11
|
+
|
12
|
+
def permitted_types_dump
|
13
|
+
@permitted_types_dump ||= @query.conditions.map(&:document_class).map(&:name).inspect
|
14
|
+
end
|
15
|
+
|
16
|
+
def load
|
17
|
+
Waiter.wait_for do
|
18
|
+
@query.conditions.each do |document_condition|
|
19
|
+
if document = @strategy.load_document_with_condition(document_condition)
|
20
|
+
return document
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
raise @strategy.document_not_loaded_error(self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
class DocumentProxy
|
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?|instance_variable_get/
|
8
|
+
undef_method m
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(loaded_page, document_loader)
|
13
|
+
@loaded_page = loaded_page
|
14
|
+
@document_loader = document_loader
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_a?(document_class)
|
18
|
+
super || @loaded_page.is_a?(document_class)
|
19
|
+
end
|
20
|
+
|
21
|
+
def as_a(document_class)
|
22
|
+
if @loaded_page.is_a?(document_class)
|
23
|
+
return @loaded_page
|
24
|
+
end
|
25
|
+
|
26
|
+
raise DocumentLoadError, "#{document_class.name} not expected. Allowed types: #{@document_loader.permitted_types_dump}"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def implicit_document
|
32
|
+
@implicit_document ||= as_a(implicit_document_class)
|
33
|
+
end
|
34
|
+
|
35
|
+
def implicit_document_class
|
36
|
+
@implicit_document_class ||= @document_loader.default_document_class
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(name, *args, &block)
|
40
|
+
implicit_document.__send__(name, *args, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def respond_to?(*args)
|
44
|
+
super || implicit_document_class.allocate.respond_to?(*args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
class DocumentQuery
|
3
|
+
class Condition
|
4
|
+
attr_reader :document_class, :document_conditions
|
5
|
+
|
6
|
+
def initialize(document_class, document_conditions = {}, &block_condition)
|
7
|
+
@document_class = document_class
|
8
|
+
|
9
|
+
@document_conditions = document_conditions || {}
|
10
|
+
@document_conditions[:block] = block_condition if block_condition
|
11
|
+
end
|
12
|
+
|
13
|
+
def match?(document)
|
14
|
+
@document_conditions.each do |type, value|
|
15
|
+
case type
|
16
|
+
when :title then
|
17
|
+
return false unless Capybara.current_session.driver.browser.title.include?(value)
|
18
|
+
when :url then
|
19
|
+
return false unless document.current_url.include?(value)
|
20
|
+
when :block then
|
21
|
+
return false unless value.call(document)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :conditions
|
30
|
+
|
31
|
+
def initialize(*document_classes, &block)
|
32
|
+
@conditions = []
|
33
|
+
|
34
|
+
if document_classes.empty?
|
35
|
+
raise ArgumentError, "block expected" if block.nil?
|
36
|
+
block.call(self)
|
37
|
+
|
38
|
+
raise ArgumentError, "conditions expected" if @conditions.empty?
|
39
|
+
else
|
40
|
+
|
41
|
+
all_documents = document_classes.all? do |document_class|
|
42
|
+
document_class.is_a?(Class) && document_class < Document
|
43
|
+
end
|
44
|
+
|
45
|
+
if all_documents
|
46
|
+
if document_classes.size == 1
|
47
|
+
matches(document_classes.first, {}, &block)
|
48
|
+
else
|
49
|
+
raise ArgumentError, "block unexpected for multiple documents" unless block.nil?
|
50
|
+
|
51
|
+
document_classes.each do |document_class|
|
52
|
+
matches(document_class)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise ArgumentError, "Expected (Document, document_options)" unless document_classes.size == 2
|
57
|
+
raise ArgumentError, "Expected (Document, document_options)" unless (document_classes.first < Document) && document_classes.last.is_a?(Hash)
|
58
|
+
|
59
|
+
matches(document_classes.first, document_classes.last, &block)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def matches(document_class, conditions = {}, &block_condition)
|
65
|
+
@conditions << Condition.new(document_class, conditions, &block_condition)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -28,6 +28,14 @@ module AePageObjects
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def browser
|
32
|
+
@browser ||= document.browser
|
33
|
+
end
|
34
|
+
|
35
|
+
def window
|
36
|
+
@window ||= document.window
|
37
|
+
end
|
38
|
+
|
31
39
|
def __full_name__
|
32
40
|
if parent.respond_to?(:__full_name__)
|
33
41
|
name_parts = [ parent.__full_name__, __name__ ].compact
|
@@ -1,10 +1,15 @@
|
|
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 DocumentLoadError < Error
|
9
14
|
end
|
10
15
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module MultipleWindows
|
3
|
+
class Browser
|
4
|
+
attr_reader :windows
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@windows = WindowList.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_window
|
11
|
+
@windows.current_window
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_document(*document_classes, &block)
|
15
|
+
query = DocumentQuery.new(*document_classes, &block)
|
16
|
+
document_loader = DocumentLoader.new(query, CrossWindowLoaderStrategy.new(@windows))
|
17
|
+
|
18
|
+
DocumentProxy.new(document_loader.load, document_loader)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module MultipleWindows
|
3
|
+
class CrossWindowLoaderStrategy
|
4
|
+
|
5
|
+
def initialize(window_list)
|
6
|
+
@window_list = window_list
|
7
|
+
@original_window = window_list.current_window
|
8
|
+
|
9
|
+
@current_window_loader = SingleWindow::SameWindowLoaderStrategy.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_document_with_condition(condition)
|
13
|
+
# Look in the current window first unless told not to
|
14
|
+
unless condition.document_conditions[:ignore_current]
|
15
|
+
@original_window.switch_to
|
16
|
+
|
17
|
+
if document = @current_window_loader.load_document_with_condition(condition)
|
18
|
+
return document
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Loop through all the windows and attempt to instantiate the Document. Continue to loop around
|
23
|
+
# until finding a Document that can be instantiated or timing out.
|
24
|
+
@window_list.opened.each do |window|
|
25
|
+
next if window == @original_window
|
26
|
+
|
27
|
+
window.switch_to
|
28
|
+
|
29
|
+
if document = @current_window_loader.load_document_with_condition(condition)
|
30
|
+
return document
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@original_window.switch_to
|
35
|
+
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def document_not_loaded_error(document_loader)
|
40
|
+
all_windows = @window_list.opened.map do |window|
|
41
|
+
name = window.current_document && window.current_document.to_s || "<none>"
|
42
|
+
{:window_handle => window.handle, :document => name }
|
43
|
+
end
|
44
|
+
|
45
|
+
DocumentLoadError.new("Couldn't find document with type in #{document_loader.permitted_types_dump} in any of the open windows: #{all_windows.inspect}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module MultipleWindows
|
3
|
+
class Window < SingleWindow::Window
|
4
|
+
attr_reader :handle
|
5
|
+
|
6
|
+
def initialize(registry, handle)
|
7
|
+
@registry = registry
|
8
|
+
@handle = handle
|
9
|
+
|
10
|
+
@registry.add(self)
|
11
|
+
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
|
15
|
+
def switch_to
|
16
|
+
WindowHandleManager.switch_to(handle)
|
17
|
+
current_document
|
18
|
+
end
|
19
|
+
|
20
|
+
def close
|
21
|
+
if WindowHandleManager.close(@handle)
|
22
|
+
self.current_document = nil
|
23
|
+
@registry.remove(self)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module MultipleWindows
|
3
|
+
class WindowHandleManager
|
4
|
+
def self.all
|
5
|
+
browser.window_handles
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.current
|
9
|
+
# Accessing browser.window_handle tries to find an existing page, which will blow up
|
10
|
+
# if there isn't one. So... we look at the collection first as a guard.
|
11
|
+
if all.empty?
|
12
|
+
nil
|
13
|
+
else
|
14
|
+
browser.window_handle
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.switch_to(handle)
|
19
|
+
browser.switch_to.window(handle)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.browser
|
23
|
+
Capybara.current_session.driver.browser
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.close(handle)
|
27
|
+
all_handles_before_close = all()
|
28
|
+
more_than_one_window = (all_handles_before_close.size > 1)
|
29
|
+
|
30
|
+
# We must protect against closing the last window as doing so will quit the entire browser
|
31
|
+
# which would mess up subsequent tests.
|
32
|
+
# http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#close()
|
33
|
+
return false unless more_than_one_window
|
34
|
+
|
35
|
+
current_handle_before_switch = current
|
36
|
+
|
37
|
+
# switch to the window to close
|
38
|
+
switch_to(handle)
|
39
|
+
|
40
|
+
browser.close
|
41
|
+
|
42
|
+
# need to switch back to something. Use whatever was switched from originally unless we just
|
43
|
+
# closed that window, in which case just pick something else.
|
44
|
+
switch_to(current_handle_before_switch == handle ? all.first : current_handle_before_switch)
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module MultipleWindows
|
3
|
+
class WindowList
|
4
|
+
def initialize
|
5
|
+
@windows = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(window)
|
9
|
+
@windows[window.handle] = window
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove(window)
|
13
|
+
@windows.delete(window.handle)
|
14
|
+
end
|
15
|
+
|
16
|
+
def opened
|
17
|
+
WindowHandleManager.all.map do |handle|
|
18
|
+
find(handle)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def current_window
|
23
|
+
current_handle = WindowHandleManager.current
|
24
|
+
|
25
|
+
find(current_handle) if current_handle
|
26
|
+
end
|
27
|
+
|
28
|
+
def close_all
|
29
|
+
opened.each(&:close)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def find(handle)
|
35
|
+
@windows[handle] || create_window(handle)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_window(handle)
|
39
|
+
Window.new(self, handle)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module SingleWindow
|
3
|
+
class SameWindowLoaderStrategy
|
4
|
+
def load_document_with_condition(condition)
|
5
|
+
document = load_document(condition.document_class)
|
6
|
+
|
7
|
+
if document && condition_matches?(document, condition)
|
8
|
+
document
|
9
|
+
else
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def document_not_loaded_error(document_loader)
|
15
|
+
DocumentLoadError.new("Current window does not contain document with type in #{document_loader.permitted_types_dump}.")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def load_document(document_class)
|
21
|
+
document_class.new
|
22
|
+
rescue AePageObjects::LoadingFailed
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def condition_matches?(document, condition)
|
27
|
+
condition.match?(document)
|
28
|
+
rescue Capybara::ElementNotFound
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AePageObjects
|
2
|
+
module SingleWindow
|
3
|
+
class Window
|
4
|
+
attr_reader :current_document
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@current_document = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_document=(document)
|
11
|
+
@current_document.send(:stale!) if @current_document
|
12
|
+
@current_document = document
|
13
|
+
end
|
14
|
+
|
15
|
+
def change_to(*document_classes, &block)
|
16
|
+
query = DocumentQuery.new(*document_classes, &block)
|
17
|
+
document_loader = DocumentLoader.new(query, SameWindowLoaderStrategy.new)
|
18
|
+
|
19
|
+
DocumentProxy.new(document_loader.load, document_loader)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,125 +1,18 @@
|
|
1
|
+
unless AePageObjects.respond_to?(:browser)
|
2
|
+
raise "Deprecation warnings out of date."
|
3
|
+
end
|
4
|
+
|
1
5
|
module AePageObjects
|
2
6
|
class Window
|
3
|
-
|
4
|
-
class Registry < Hash
|
5
|
-
def [](window_or_handle)
|
6
|
-
if window_or_handle.is_a?(Window)
|
7
|
-
super(window_or_handle.handle)
|
8
|
-
else
|
9
|
-
super(window_or_handle)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def add(window)
|
14
|
-
self[window.handle] = window
|
15
|
-
end
|
16
|
-
|
17
|
-
def remove(window)
|
18
|
-
self.delete(window.handle)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class HandleManager
|
23
|
-
def self.all
|
24
|
-
browser.window_handles
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.current
|
28
|
-
# Accessing browser.window_handle tries to find an existing page, which will blow up
|
29
|
-
# if there isn't one. So... we look at the collection first as a guard.
|
30
|
-
if all.empty?
|
31
|
-
nil
|
32
|
-
else
|
33
|
-
browser.window_handle
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.switch_to(handle)
|
38
|
-
browser.switch_to.window(handle)
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.browser
|
42
|
-
Capybara.current_session.driver.browser
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.close(handle)
|
46
|
-
all_handles_before_close = all()
|
47
|
-
more_than_one_window = (all_handles_before_close.size > 1)
|
48
|
-
|
49
|
-
# We must protect against closing the last window as doing so will quit the entire browser
|
50
|
-
# which would mess up subsequent tests.
|
51
|
-
# http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#close()
|
52
|
-
return false unless more_than_one_window
|
53
|
-
|
54
|
-
current_handle_before_switch = current
|
55
|
-
|
56
|
-
# switch to the window to close
|
57
|
-
switch_to(handle)
|
58
|
-
|
59
|
-
browser.close
|
60
|
-
|
61
|
-
# need to switch back to something. Use whatever was switched from originally unless we just
|
62
|
-
# closed that window, in which case just pick something else.
|
63
|
-
switch_to(current_handle_before_switch == handle ? all.first : current_handle_before_switch)
|
64
|
-
|
65
|
-
true
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
7
|
class << self
|
70
|
-
def registry
|
71
|
-
@registry ||= Registry.new
|
72
|
-
end
|
73
|
-
|
74
|
-
def close_all
|
75
|
-
all.each(&:close)
|
76
|
-
end
|
77
|
-
|
78
8
|
def all
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def find(handle)
|
85
|
-
registry[handle] || create(handle)
|
86
|
-
end
|
87
|
-
|
88
|
-
def current
|
89
|
-
current_handle = HandleManager.current
|
90
|
-
|
91
|
-
find(current_handle) if current_handle
|
9
|
+
warn "[DEPRECATION WARNING]: AePageObjects::Window.all is deprecated. Use AePageObjects.browser.windows()"
|
10
|
+
AePageObjects.browser.windows
|
92
11
|
end
|
93
12
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
attr_reader :current_document, :handle
|
100
|
-
|
101
|
-
def initialize(registry, handle)
|
102
|
-
@registry = registry
|
103
|
-
@handle = handle
|
104
|
-
@current_document = nil
|
105
|
-
|
106
|
-
@registry.add(self)
|
107
|
-
end
|
108
|
-
|
109
|
-
def current_document=(document)
|
110
|
-
@current_document.send(:stale!) if @current_document
|
111
|
-
@current_document = document
|
112
|
-
end
|
113
|
-
|
114
|
-
def switch_to
|
115
|
-
HandleManager.switch_to(handle)
|
116
|
-
current_document
|
117
|
-
end
|
118
|
-
|
119
|
-
def close
|
120
|
-
if HandleManager.close(@handle)
|
121
|
-
self.current_document = nil
|
122
|
-
@registry.remove(self)
|
13
|
+
def close_all
|
14
|
+
warn "[DEPRECATION WARNING]: AePageObjects::Window.close_all is deprecated. Use AePageObjects.browser.windows.close_all()"
|
15
|
+
all.close_all
|
123
16
|
end
|
124
17
|
end
|
125
18
|
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: 1.0
|
4
|
+
version: 1.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: 2014-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -49,6 +49,9 @@ files:
|
|
49
49
|
- lib/ae_page_objects/core/universe.rb
|
50
50
|
- lib/ae_page_objects/core_ext/module.rb
|
51
51
|
- lib/ae_page_objects/document.rb
|
52
|
+
- lib/ae_page_objects/document_loader.rb
|
53
|
+
- lib/ae_page_objects/document_proxy.rb
|
54
|
+
- lib/ae_page_objects/document_query.rb
|
52
55
|
- lib/ae_page_objects/element.rb
|
53
56
|
- lib/ae_page_objects/element_proxy.rb
|
54
57
|
- lib/ae_page_objects/elements/checkbox.rb
|
@@ -56,7 +59,15 @@ files:
|
|
56
59
|
- lib/ae_page_objects/elements/form.rb
|
57
60
|
- lib/ae_page_objects/elements/select.rb
|
58
61
|
- lib/ae_page_objects/exceptions.rb
|
62
|
+
- lib/ae_page_objects/multiple_windows/browser.rb
|
63
|
+
- lib/ae_page_objects/multiple_windows/cross_window_loader_strategy.rb
|
64
|
+
- lib/ae_page_objects/multiple_windows/window.rb
|
65
|
+
- lib/ae_page_objects/multiple_windows/window_handle_manager.rb
|
66
|
+
- lib/ae_page_objects/multiple_windows/window_list.rb
|
59
67
|
- lib/ae_page_objects/node.rb
|
68
|
+
- lib/ae_page_objects/single_window/browser.rb
|
69
|
+
- lib/ae_page_objects/single_window/same_window_loader_strategy.rb
|
70
|
+
- lib/ae_page_objects/single_window/window.rb
|
60
71
|
- lib/ae_page_objects/util/hash_symbolizer.rb
|
61
72
|
- lib/ae_page_objects/util/inflector.rb
|
62
73
|
- lib/ae_page_objects/util/internal_helpers.rb
|