ae_page_objects 0.4.1.dt4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
data/lib/ae_page_objects.rb
CHANGED
@@ -23,7 +23,6 @@ module AePageObjects
|
|
23
23
|
autoload :Visitable, 'ae_page_objects/concerns/visitable'
|
24
24
|
end
|
25
25
|
|
26
|
-
autoload :Window, 'ae_page_objects/window'
|
27
26
|
autoload :Node, 'ae_page_objects/node'
|
28
27
|
autoload :Document, 'ae_page_objects/document'
|
29
28
|
autoload :Element, 'ae_page_objects/element'
|
@@ -1,16 +1,11 @@
|
|
1
1
|
module AePageObjects
|
2
2
|
class Document < Node
|
3
3
|
include Concerns::Visitable
|
4
|
-
|
5
|
-
attr_reader :window
|
6
4
|
|
7
5
|
def initialize
|
8
6
|
super(Capybara.current_session)
|
9
|
-
|
10
|
-
@window = Window.current
|
11
|
-
@window.current_document = self
|
12
7
|
end
|
13
|
-
|
8
|
+
|
14
9
|
def document
|
15
10
|
self
|
16
11
|
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
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: 13
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
9
|
- 1
|
10
|
-
|
11
|
-
- 4
|
12
|
-
version: 0.4.1.dt4
|
10
|
+
version: 0.4.1
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Donnie Tognazzini
|
@@ -20,6 +18,7 @@ cert_chain: []
|
|
20
18
|
date: 2013-07-19 00:00:00 Z
|
21
19
|
dependencies:
|
22
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
23
22
|
name: capybara
|
24
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
@@ -31,10 +30,10 @@ dependencies:
|
|
31
30
|
- 1
|
32
31
|
- 1
|
33
32
|
version: "1.1"
|
34
|
-
prerelease: false
|
35
|
-
type: :runtime
|
36
33
|
requirement: *id001
|
34
|
+
prerelease: false
|
37
35
|
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
38
37
|
name: appraisal
|
39
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
@@ -47,10 +46,10 @@ dependencies:
|
|
47
46
|
- 5
|
48
47
|
- 1
|
49
48
|
version: 0.5.1
|
50
|
-
prerelease: false
|
51
|
-
type: :development
|
52
49
|
requirement: *id002
|
50
|
+
prerelease: false
|
53
51
|
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
54
53
|
name: mocha
|
55
54
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
55
|
none: false
|
@@ -63,10 +62,10 @@ dependencies:
|
|
63
62
|
- 13
|
64
63
|
- 3
|
65
64
|
version: 0.13.3
|
66
|
-
prerelease: false
|
67
|
-
type: :development
|
68
65
|
requirement: *id003
|
66
|
+
prerelease: false
|
69
67
|
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
70
69
|
name: selenium-webdriver
|
71
70
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
71
|
none: false
|
@@ -77,9 +76,8 @@ dependencies:
|
|
77
76
|
segments:
|
78
77
|
- 0
|
79
78
|
version: "0"
|
80
|
-
prerelease: false
|
81
|
-
type: :development
|
82
79
|
requirement: *id004
|
80
|
+
prerelease: false
|
83
81
|
description: Capybara Page Objects pattern
|
84
82
|
email:
|
85
83
|
- engineering@appfolio.com
|
@@ -115,7 +113,6 @@ files:
|
|
115
113
|
- lib/ae_page_objects/util/internal_helpers.rb
|
116
114
|
- lib/ae_page_objects/util/singleton.rb
|
117
115
|
- lib/ae_page_objects/version.rb
|
118
|
-
- lib/ae_page_objects/window.rb
|
119
116
|
homepage: http://github.com/appfolio/ae_page_objects
|
120
117
|
licenses:
|
121
118
|
- MIT
|
@@ -1,126 +0,0 @@
|
|
1
|
-
module AePageObjects
|
2
|
-
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
|
-
class << self
|
70
|
-
def registry
|
71
|
-
@registry ||= Registry.new
|
72
|
-
end
|
73
|
-
|
74
|
-
def close_all
|
75
|
-
all.each(&:close)
|
76
|
-
end
|
77
|
-
|
78
|
-
def all
|
79
|
-
HandleManager.all.map do |handle|
|
80
|
-
find(handle)
|
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
|
92
|
-
end
|
93
|
-
|
94
|
-
def create(handle)
|
95
|
-
new(registry, handle)
|
96
|
-
end
|
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)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|