pouch 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pouch.rb +1 -1
- data/lib/pouch/elements.rb +14 -12
- data/lib/pouch/version.rb +1 -1
- data/spec/elements_spec.rb +16 -1
- data/spec/pouch_spec.rb +6 -6
- metadata +1 -1
data/lib/pouch.rb
CHANGED
data/lib/pouch/elements.rb
CHANGED
@@ -2,10 +2,10 @@ module Pouch
|
|
2
2
|
module Elements
|
3
3
|
|
4
4
|
def element tag, name, identifier, *args, &block
|
5
|
-
define_method name do
|
6
|
-
timer
|
5
|
+
define_method name, ->(time = nil) do
|
6
|
+
timer(time){ browser.element(tag, identifier).visible? }
|
7
7
|
return browser.element tag, identifier unless block_given?
|
8
|
-
block.call browser.send(:element, tag, identifier), *args
|
8
|
+
block.call browser.send(:element, tag, identifier), *args
|
9
9
|
end
|
10
10
|
|
11
11
|
define_waiting_methods tag, name, identifier, *args, &block
|
@@ -121,23 +121,23 @@ module Pouch
|
|
121
121
|
private
|
122
122
|
|
123
123
|
def define_waiting_methods tag, name, identifier, *args, &block
|
124
|
-
define_method "when_#{name}_not_visible" do
|
125
|
-
result = negative_timer
|
124
|
+
define_method "when_#{name}_not_visible", ->(time = nil) do
|
125
|
+
result = negative_timer(time){ !browser.element(tag, identifier).visible? }
|
126
126
|
unless result
|
127
127
|
raise VisibilityError, "#{name} element is still visible"
|
128
128
|
end
|
129
129
|
self
|
130
130
|
end
|
131
131
|
|
132
|
-
define_method "when_#{name}_present" do
|
133
|
-
timer
|
132
|
+
define_method "when_#{name}_present", ->(time = nil) do
|
133
|
+
timer(time){ browser.element(tag, identifier).present? }
|
134
134
|
html_element = browser.element tag, identifier
|
135
135
|
return located_element unless block_given?
|
136
136
|
block.call located_element, *args
|
137
137
|
end
|
138
138
|
|
139
|
-
define_method "when_#{name}_not_present" do
|
140
|
-
result = negative_timer
|
139
|
+
define_method "when_#{name}_not_present", ->(time = nil) do
|
140
|
+
result = negative_timer(time){ !browser.element(tag, identifier).present? }
|
141
141
|
unless result
|
142
142
|
raise PresenceError, "#{name} element is still present"
|
143
143
|
end
|
@@ -145,7 +145,8 @@ module Pouch
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
def timer &block
|
148
|
+
def timer n, &block
|
149
|
+
interval = n.nil? ? timeout : n
|
149
150
|
timed_out = Time.now + timeout
|
150
151
|
until Time.now > timed_out
|
151
152
|
result = yield block rescue false
|
@@ -153,8 +154,9 @@ module Pouch
|
|
153
154
|
end
|
154
155
|
end
|
155
156
|
|
156
|
-
def negative_timer &block
|
157
|
-
|
157
|
+
def negative_timer n, &block
|
158
|
+
interval = n.nil? ? timeout : n
|
159
|
+
timed_out = Time.now + interval
|
158
160
|
until Time.now > timed_out
|
159
161
|
result = yield block rescue false
|
160
162
|
return result if result
|
data/lib/pouch/version.rb
CHANGED
data/spec/elements_spec.rb
CHANGED
@@ -28,11 +28,16 @@ describe Pouch::Elements do
|
|
28
28
|
expect(page.blocked).to eq "www.test.com"
|
29
29
|
end
|
30
30
|
|
31
|
-
it "calls #timer to wait for
|
31
|
+
it "calls #timer to wait for default interval" do
|
32
32
|
expect(page).to receive(:timer)
|
33
33
|
page.generic
|
34
34
|
end
|
35
35
|
|
36
|
+
it "calls #timer with custom interval" do
|
37
|
+
expect(page).to receive(:timer).with(20)
|
38
|
+
page.generic 20
|
39
|
+
end
|
40
|
+
|
36
41
|
it "generates #when_generic_not_visible" do
|
37
42
|
expect(page).to respond_to :when_generic_not_visible
|
38
43
|
end
|
@@ -81,6 +86,11 @@ describe Pouch::Elements do
|
|
81
86
|
expect(page).to receive(:negative_timer).and_return(false)
|
82
87
|
expect{ page.when_invisible_not_visible }.to raise_error Pouch::VisibilityError, /invisible element/
|
83
88
|
end
|
89
|
+
|
90
|
+
it "accepts an optional interval for timeout" do
|
91
|
+
expect(page).to receive(:negative_timer).with(20).and_return(true)
|
92
|
+
page.when_invisible_not_visible 20
|
93
|
+
end
|
84
94
|
end
|
85
95
|
|
86
96
|
describe "#when_element_not_present" do
|
@@ -97,6 +107,11 @@ describe Pouch::Elements do
|
|
97
107
|
expect(page).to receive(:negative_timer).and_return(false)
|
98
108
|
expect{ page.when_gone_not_present }.to raise_error Pouch::PresenceError, /gone element/
|
99
109
|
end
|
110
|
+
|
111
|
+
it "accepts an optional interval for timeout" do
|
112
|
+
expect(page).to receive(:negative_timer).with(20).and_return(true)
|
113
|
+
page.when_gone_not_present 20
|
114
|
+
end
|
100
115
|
end
|
101
116
|
|
102
117
|
describe "#button" do
|
data/spec/pouch_spec.rb
CHANGED
@@ -21,13 +21,13 @@ describe Pouch do
|
|
21
21
|
|
22
22
|
it "creates @timeout variable" do
|
23
23
|
obj = Page2.new 'webdriver'
|
24
|
-
expect(obj.instance_variable_get :@timeout).to eq
|
24
|
+
expect(obj.instance_variable_get :@timeout).to eq 5
|
25
25
|
end
|
26
26
|
|
27
27
|
context "with :timeout option" do
|
28
28
|
it "creates @timeout variable" do
|
29
|
-
obj = Page2.new 'webdriver', timeout:
|
30
|
-
expect(obj.instance_variable_get :@timeout).to eq
|
29
|
+
obj = Page2.new 'webdriver', timeout: 10
|
30
|
+
expect(obj.instance_variable_get :@timeout).to eq 10
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -125,14 +125,14 @@ describe Pouch do
|
|
125
125
|
context "without setting a custom timeout interval" do
|
126
126
|
it "returns the page object default timeout" do
|
127
127
|
obj = Page.new 'webdriver'
|
128
|
-
expect(obj.timeout).to eq
|
128
|
+
expect(obj.timeout).to eq 5
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
context "after passing :timeout option to #initialize" do
|
133
133
|
it "returns the custom timeout" do
|
134
|
-
obj = Page.new 'webdriver', timeout:
|
135
|
-
expect(obj.timeout).to eq
|
134
|
+
obj = Page.new 'webdriver', timeout: 10
|
135
|
+
expect(obj.timeout).to eq 10
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|