awetestlib 0.1.28 → 0.1.29pre1
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/.gitattributes +22 -22
- data/.gitignore +69 -69
- data/.yardopts +7 -7
- data/README.md +108 -108
- data/awetestlib.gemspec +57 -57
- data/awetestlib.windows.gemspec +41 -41
- data/awetestlib_notes.txt +4 -4
- data/awetestlib_osx.gemspec +47 -48
- data/bin/awetestlib +99 -99
- data/bin/awetestlib-android-setup.rb +26 -26
- data/bin/awetestlib-cucumber-setup.rb +28 -28
- data/bin/awetestlib-driver-setup.rb +21 -21
- data/bin/awetestlib-helpers.rb +41 -41
- data/bin/awetestlib-mobile-app-setup.rb +31 -31
- data/bin/awetestlib-netbeans-setup.rb +58 -58
- data/bin/awetestlib-regression-setup.rb +15 -15
- data/bin/awetestlib-rubymine-setup.rb +39 -39
- data/drivers/chromedriver.exe +0 -0
- data/ext/Rakefile +1 -1
- data/ext/mkrf_conf.rb +27 -27
- data/lib/awetestlib/html_report.rb +142 -142
- data/lib/awetestlib/logging.rb +366 -366
- data/lib/awetestlib/regression/browser.rb +1380 -1375
- data/lib/awetestlib/regression/drag_and_drop.rb +421 -420
- data/lib/awetestlib/regression/find.rb +345 -345
- data/lib/awetestlib/regression/legacy.rb +1187 -1187
- data/lib/awetestlib/regression/page_data.rb +191 -191
- data/lib/awetestlib/regression/runner.rb +307 -307
- data/lib/awetestlib/regression/tables.rb +627 -619
- data/lib/awetestlib/regression/user_input.rb +576 -576
- data/lib/awetestlib/regression/utilities.rb +1046 -988
- data/lib/awetestlib/regression/validations.rb +1093 -1074
- data/lib/awetestlib/regression/waits.rb +470 -470
- data/lib/awetestlib/runner.rb +18 -18
- data/lib/awetestlib.rb +41 -41
- data/lib/patches/README +2 -2
- data/lib/patches/firewatir.rb +106 -106
- data/lib/patches/watir.rb +175 -175
- data/lib/version.rb +2 -2
- data/license.txt +13 -13
- data/netbeans_setup.md +29 -29
- data/rdoc_test.bat +1 -1
- data/rubymine_setup.md +23 -23
- data/setup_samples/sample_android/features/dk.mejer.hansen.control.FlyingColorsPlayerAidActivity.apk +0 -0
- data/setup_samples/sample_android/features/sample_android.feature +5 -5
- data/setup_samples/sample_android/features/step_definitions/calabash_steps.rb +1 -1
- data/setup_samples/sample_android/features/support/app_installation_hooks.rb +36 -36
- data/setup_samples/sample_android/features/support/app_life_cycle_hooks.rb +14 -14
- data/setup_samples/sample_android/features/test_servers/8ba795a0288381ae346b67867b586881_0.3.2.apk +0 -0
- data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +76 -76
- data/setup_samples/sample_cucumber/features/yahoo_mail.feature +11 -11
- data/setup_samples/sample_mobile_app/features/my_first.feature +14 -14
- data/setup_samples/sample_mobile_app/features/step_definitions/predefined_webview_steps.rb +80 -80
- data/setup_samples/sample_mobile_app/features/support/env.rb +2 -2
- data/setup_samples/sample_netbeans/demo.rb +86 -86
- data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -2
- data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -1
- data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +2 -2
- data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -2
- data/setup_samples/sample_netbeans/nbproject/project.properties +5 -5
- data/setup_samples/sample_netbeans/nbproject/project.xml +13 -13
- data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -5
- data/setup_samples/sample_rubymine/.idea/misc.xml +5 -5
- data/setup_samples/sample_rubymine/.idea/modules.xml +9 -9
- data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -9
- data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +4 -4
- data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -7
- data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -213
- data/setup_samples/sample_rubymine/demo.rb +86 -86
- data/test/create_zoho.rb +66 -66
- data/test/create_zoho_account1.rb +68 -68
- data/test/create_zoho_account2.rb +72 -72
- data/test/demo.rb +87 -87
- data/test/google_search1.rb +16 -16
- data/test/google_search2.rb +19 -19
- data/test/login_1.rb +37 -37
- data/test/login_1a.rb +37 -37
- data/test/login_2.rb +32 -32
- data/test/zoho_exercise.rb +21 -21
- data/test/zoho_util.rb +487 -487
- data/tmp/placeholder.html +71 -71
- metadata +18 -49
@@ -1,470 +1,470 @@
|
|
1
|
-
module Awetestlib
|
2
|
-
module Regression
|
3
|
-
# Methods for waiting until something has happened, or waiting while a condition exists, in the browser or DOM.
|
4
|
-
# sleep_for() is the basic technique. Its disadvantage is that it needs to be set for the longest likely wait time.
|
5
|
-
# The wait methods take advantage of the Watir and Watir Webdriver wait functionality to pause only as long as necessary for
|
6
|
-
# the element in question to be in the state needed.
|
7
|
-
module Waits
|
8
|
-
|
9
|
-
# @!group Core
|
10
|
-
|
11
|
-
# Sleep for *seconds* seconds before continuing execution of the script.
|
12
|
-
# A message is logged (but not reported) which, by default, includes a trace showing where in the script the sleep was invoked.
|
13
|
-
# @param [Fixnum] seconds The number of seconds to wait.
|
14
|
-
# @param [Boolean] dbg If true, includes a trace in the message
|
15
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output.
|
16
|
-
def sleep_for(seconds, dbg = true, desc = '')
|
17
|
-
trace = "\n#{get_debug_list}" if dbg
|
18
|
-
msg = build_message("Sleeping for #{seconds} seconds.", desc, trace)
|
19
|
-
info_to_log(msg)
|
20
|
-
sleep(seconds)
|
21
|
-
end
|
22
|
-
|
23
|
-
# Wait while an element identified by attribute *how* with value *what* 1) exists, disappears, and exists again.
|
24
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
25
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
26
|
-
# Valid values depend on the kind of element.
|
27
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
28
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
29
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
30
|
-
# @param [Fixnum] timeout
|
31
|
-
# @return [Boolean] Returns true if disappears and reappears, each within the *timeout* limit
|
32
|
-
def wait_for_element_to_reappear(browser, how, what, desc = '', timeout = 20)
|
33
|
-
msg = "Element #{how}=#{what} exists. #{desc}"
|
34
|
-
wait_while(browser, "While: #{msg}", timeout) { browser.element(how, what).exists? }
|
35
|
-
wait_until(browser, "Until: #{msg}", timeout) { browser.element(how, what).exists? }
|
36
|
-
end
|
37
|
-
|
38
|
-
# Wait until element of type *element*, identified by attribute *how* with value *what* exists on the page.
|
39
|
-
# Timeout is the default used by watir (60 seconds)
|
40
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
41
|
-
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
42
|
-
# Some common values are :link, :button, :image, :div, :span.
|
43
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
44
|
-
# Valid values depend on the kind of element.
|
45
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
46
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
47
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
48
|
-
# @return [Boolean] True if element exists within timeout limit
|
49
|
-
def wait_until_exists(browser, element, how, what, desc = '')
|
50
|
-
msg = build_message("Wait until (:#{element} :#{how}=>'#{what}') exists.", desc)
|
51
|
-
start = Time.now.to_f
|
52
|
-
# TODO: try Watir::Wait.until { browser.element(how, what).exists? } instead of this (cumbersome) case statement
|
53
|
-
# TODO: above fails on frame
|
54
|
-
Watir::Wait.until { browser.exists? }
|
55
|
-
begin
|
56
|
-
case element
|
57
|
-
when :link
|
58
|
-
Watir::Wait.until { browser.link(how, what).exists? }
|
59
|
-
when :button
|
60
|
-
Watir::Wait.until { browser.button(how, what).exists? }
|
61
|
-
when :radio
|
62
|
-
Watir::Wait.until { browser.radio(how, what).exists? }
|
63
|
-
when :checkbox
|
64
|
-
Watir::Wait.until { browser.checkbox(how, what).exists? }
|
65
|
-
when :div
|
66
|
-
Watir::Wait.until { browser.div(how, what).exists? }
|
67
|
-
when :select_list
|
68
|
-
Watir::Wait.until { browser.select_list(how, what).exists? }
|
69
|
-
when :text_field
|
70
|
-
Watir::Wait.until { browser.text_field(how, what).exists? }
|
71
|
-
when :frame
|
72
|
-
Watir::Wait.until { browser.frame(how, what).exists? }
|
73
|
-
when :form
|
74
|
-
Watir::Wait.until { browser.form(how, what).exists? }
|
75
|
-
when :cell
|
76
|
-
Watir::Wait.until { browser.cell(how, what).exists? }
|
77
|
-
when :image
|
78
|
-
Watir::Wait.until { browser.image(how, what).exists? }
|
79
|
-
else
|
80
|
-
Watir::Wait.until { browser.element(how, what).exists? }
|
81
|
-
end
|
82
|
-
rescue => e
|
83
|
-
if e.class.to_s =~ /TimeOutException/
|
84
|
-
failed_to_log("#{msg}: '#{$!}'")
|
85
|
-
return false
|
86
|
-
elsif not rescue_me(e, __method__, rescue_me_command(element, how, what, :exists?), "#{browser.class}")
|
87
|
-
raise e
|
88
|
-
end
|
89
|
-
end
|
90
|
-
stop = Time.now.to_f
|
91
|
-
#debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
|
92
|
-
# sleep 1
|
93
|
-
passed_to_log("#{msg} (#{stop - start} seconds)")
|
94
|
-
true
|
95
|
-
rescue
|
96
|
-
failed_to_log("Unable to complete #{msg}: '#{$!}'")
|
97
|
-
end
|
98
|
-
|
99
|
-
# Wait _while_ expression in *&block* returns true.
|
100
|
-
# @example
|
101
|
-
# wait_while(browser, 'Textfield is enabled.', 10) { browser.text_field(:id, 'this text field').enabled?}
|
102
|
-
#
|
103
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
104
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
105
|
-
# @param [Fixnum] timeout Maximum time to wait, in seconds.
|
106
|
-
# @param [Proc] &block A ruby expression that evaluates to true or false. The expression
|
107
|
-
# is usually a watir or watir-webdriver command like .exists?, enabled?, etc. on a
|
108
|
-
# specific DOM element. Note that *&block* is listed as the last parameter inside the signature
|
109
|
-
# parentheses, but is passed in curly braces outside the signature parentheses in the call. This is
|
110
|
-
# the way Ruby works.
|
111
|
-
# @return [Boolean] True if condition returns false within time limit.
|
112
|
-
def wait_while(browser, desc, timeout = 45, &block)
|
113
|
-
#TODO: Would like to be able to see the block code in the log message instead of the identification
|
114
|
-
msg = "Wait while #{desc}:"
|
115
|
-
start = Time.now.to_f
|
116
|
-
Watir::Wait.until { browser.exists? }
|
117
|
-
begin
|
118
|
-
#Watir::Wait.until(timeout) { block.call(nil) }
|
119
|
-
if block.call(nil)
|
120
|
-
Watir::Wait.while(timeout) { block.call(nil) }
|
121
|
-
end
|
122
|
-
rescue => e
|
123
|
-
if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
|
124
|
-
failed_to_log("#{msg}: '#{$!}' ")
|
125
|
-
return false
|
126
|
-
elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
|
127
|
-
raise e
|
128
|
-
end
|
129
|
-
end
|
130
|
-
stop = Time.now.to_f
|
131
|
-
#debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
|
132
|
-
# sleep 1
|
133
|
-
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") # {#{block.to_s}}")
|
134
|
-
true
|
135
|
-
rescue
|
136
|
-
failed_to_log("Unable to complete #{msg}. '#{$!}'")
|
137
|
-
end
|
138
|
-
|
139
|
-
alias wait_while_true wait_while
|
140
|
-
|
141
|
-
# Wait _until_ expression in *&block* returns true.
|
142
|
-
# @example
|
143
|
-
# wait_until(browser, 'Textfield is enabled.', 10) { browser.text_field(:id, 'this text field').exists?}
|
144
|
-
#
|
145
|
-
# @param (see #wait_while)
|
146
|
-
# @return [Boolean] True if condition in *&block* returns true within time limit.
|
147
|
-
def wait_until(browser, desc, timeout = 45, skip_pass = false, &block)
|
148
|
-
#TODO: Would like to be able to see the block code in the log message instead of the identification
|
149
|
-
msg = "Wait until #{desc}"
|
150
|
-
start = Time.now.to_f
|
151
|
-
Watir::Wait.until { browser.exists? }
|
152
|
-
begin
|
153
|
-
Watir::Wait.until(timeout) { block.call(nil) }
|
154
|
-
rescue => e
|
155
|
-
if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
|
156
|
-
failed_to_log("#{msg} '#{$!}'")
|
157
|
-
return false
|
158
|
-
elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
|
159
|
-
raise e
|
160
|
-
end
|
161
|
-
end
|
162
|
-
stop = Time.now.to_f
|
163
|
-
#debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
|
164
|
-
# sleep 1
|
165
|
-
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless skip_pass # {#{block.to_s}}")
|
166
|
-
true
|
167
|
-
rescue
|
168
|
-
failed_to_log("Unable to complete #{msg} '#{$!}'")
|
169
|
-
end
|
170
|
-
|
171
|
-
alias wait_until_true wait_until
|
172
|
-
|
173
|
-
# Wait _until_ element, identified by attribute *how* and its value *what*, exists.
|
174
|
-
# If it exists within *timeout* seconds then wait _until_ it is enabled.
|
175
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
176
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
177
|
-
# Valid values depend on the kind of element.
|
178
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
179
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
180
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
181
|
-
# @param [Fixnum] timeout Maximum time to wait, in seconds.
|
182
|
-
# @param [Boolean] verbose When set to true, more debug information is written to the log and
|
183
|
-
# all steps return pass/fail messages in the report.
|
184
|
-
# @return [Boolean] True if condition returns false within time limit.
|
185
|
-
def wait_until_ready(browser, how, what, desc = '', timeout = 90, verbose = false)
|
186
|
-
msg = "#{__method__.to_s.titleize}: element: #{how}='#{what}'"
|
187
|
-
msg << " #{desc}" if desc.length > 0
|
188
|
-
proc_exists = Proc.new { browser.element(how, what).exists? }
|
189
|
-
proc_enabled = Proc.new { browser.element(how, what).enabled? }
|
190
|
-
case how
|
191
|
-
when :href
|
192
|
-
proc_exists = Proc.new { browser.link(how, what).exists? }
|
193
|
-
proc_enabled = Proc.new { browser.link(how, what).enabled? }
|
194
|
-
end
|
195
|
-
if verbose
|
196
|
-
if wait_until(browser, "#{msg} Element exists.", timeout) { proc_exists.call(nil) }
|
197
|
-
if wait_until(browser, "#{msg} Element enabled.", timeout) { proc_enabled.call(nil) }
|
198
|
-
passed_to_log(msg)
|
199
|
-
true
|
200
|
-
else
|
201
|
-
failed_to_log(msg)
|
202
|
-
end
|
203
|
-
else
|
204
|
-
failed_to_log(msg)
|
205
|
-
end
|
206
|
-
else
|
207
|
-
start = Time.now.to_f
|
208
|
-
Watir::Wait.until { browser.exists? }
|
209
|
-
if Watir::Wait.until(timeout) { proc_exists.call(nil) }
|
210
|
-
if Watir::Wait.until(timeout) { proc_enabled.call(nil) }
|
211
|
-
stop = Time.now.to_f
|
212
|
-
#debug_to_log("#{__method__}: start:#{"%.5f" % start} stop:#{"%.5f" % stop}")
|
213
|
-
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)")
|
214
|
-
true
|
215
|
-
else
|
216
|
-
failed_to_log(msg)
|
217
|
-
end
|
218
|
-
else
|
219
|
-
failed_to_log(msg)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
rescue
|
223
|
-
failed_to_log("Unable to #{msg}. '#{$!}'")
|
224
|
-
end
|
225
|
-
|
226
|
-
# Wait _until_ element, identified by attribute *how* and its value *what*, exists.
|
227
|
-
# If it exists within *timeout* seconds then wait _until_ it is enabled. Report only failures.
|
228
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
229
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
230
|
-
# Valid values depend on the kind of element.
|
231
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
232
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
233
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
234
|
-
# @param [Fixnum] timeout Maximum time to wait, in seconds.
|
235
|
-
# @param [Boolean] quiet When set to true, only fail messages are logged and reported.
|
236
|
-
# @return [Boolean] True if condition returns false within time limit.
|
237
|
-
def wait_until_ready_quiet(browser, how, what, desc = '', timeout = 45, quiet = true)
|
238
|
-
msg = "#{__method__.to_s.titleize}: element: #{how}='#{what}'"
|
239
|
-
msg << " #{desc}" if desc.length > 0
|
240
|
-
proc_exists = Proc.new { browser.element(how, what).exists? }
|
241
|
-
proc_enabled = Proc.new { browser.element(how, what).enabled? }
|
242
|
-
case how
|
243
|
-
when :href
|
244
|
-
proc_exists = Proc.new { browser.link(how, what).exists? }
|
245
|
-
proc_enabled = Proc.new { browser.link(how, what).enabled? }
|
246
|
-
end
|
247
|
-
start = Time.now.to_f
|
248
|
-
Watir::Wait.until { browser.exists? }
|
249
|
-
sleep_for(1)
|
250
|
-
if Watir::Wait.until(timeout) { proc_exists.call(nil) }
|
251
|
-
if Watir::Wait.until(timeout) { proc_enabled.call(nil) }
|
252
|
-
stop = Time.now.to_f
|
253
|
-
#debug_to_log("#{msg}: start:#{"%.5f" % start} stop:#{"%.5f" % stop}")
|
254
|
-
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless quiet
|
255
|
-
true
|
256
|
-
else
|
257
|
-
failed_to_log(msg)
|
258
|
-
end
|
259
|
-
else
|
260
|
-
failed_to_log(msg)
|
261
|
-
end
|
262
|
-
rescue
|
263
|
-
failed_to_log("Unable to #{msg}. '#{$!}'")
|
264
|
-
end
|
265
|
-
|
266
|
-
def wait_until_text(browser, strg, desc = '', timeout = 60)
|
267
|
-
if not strg.class.to_s.match('String')
|
268
|
-
raise "#{__method__} requires String for search target. #{strg.class} is not supported."
|
269
|
-
end
|
270
|
-
wait_until(browser, "'#{strg}' #{desc}", timeout) { browser.text.include? strg }
|
271
|
-
end
|
272
|
-
|
273
|
-
alias wait_until_by_text wait_until_text
|
274
|
-
|
275
|
-
def wait_until_enabled(browser, what, how, value, desc = '')
|
276
|
-
# TODO: This can be simplified
|
277
|
-
start = Time.now.to_f
|
278
|
-
Watir::Wait.until { browser.exists? }
|
279
|
-
sleep_for(1)
|
280
|
-
begin
|
281
|
-
case what
|
282
|
-
when :link
|
283
|
-
Watir::Wait.until { browser.link(how, value).enabled? }
|
284
|
-
when :button
|
285
|
-
Watir::Wait.until { browser.button(how, value).enabled? }
|
286
|
-
when :radio
|
287
|
-
Watir::Wait.until { browser.radio(how, value).enabled? }
|
288
|
-
when :checkbox
|
289
|
-
Watir::Wait.until { browser.checkbox(how, value).enabled? }
|
290
|
-
when :div
|
291
|
-
Watir::Wait.until { browser.div(how, value).enabled? }
|
292
|
-
when :select_list
|
293
|
-
Watir::Wait.until { browser.select_list(how, value).enabled? }
|
294
|
-
when :text_field
|
295
|
-
Watir::Wait.until { browser.text_field(how, value).enabled? }
|
296
|
-
when :table
|
297
|
-
Watir::Wait.until { browser.table(how, value).enabled? }
|
298
|
-
else
|
299
|
-
Watir::Wait.until { browser.element(how, value).enabled? }
|
300
|
-
end
|
301
|
-
rescue => e
|
302
|
-
if e.class.to_s =~ /TimeOutException/
|
303
|
-
failed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}' #{desc}")
|
304
|
-
return false
|
305
|
-
elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
|
306
|
-
raise e
|
307
|
-
end
|
308
|
-
end
|
309
|
-
stop = Time.now.to_f
|
310
|
-
#debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
|
311
|
-
# sleep 1
|
312
|
-
passed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc} (#{stop - start} seconds)")
|
313
|
-
true
|
314
|
-
rescue
|
315
|
-
failed_to_log("Unable to complete wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}'")
|
316
|
-
end
|
317
|
-
|
318
|
-
def wait_until_visible(browser, element, how, what, desc = '')
|
319
|
-
start = Time.now.to_f
|
320
|
-
Watir::Wait.until { browser.exists? }
|
321
|
-
sleep_for(1)
|
322
|
-
Watir::Wait.until(20) { browser.element(how, what).exists? }
|
323
|
-
begin
|
324
|
-
case element
|
325
|
-
when :link
|
326
|
-
Watir::Wait.until { browser.link(how, what).visible? }
|
327
|
-
when :button
|
328
|
-
Watir::Wait.until { browser.button(how, what).visible? }
|
329
|
-
when :radio
|
330
|
-
Watir::Wait.until { browser.radio(how, what).visible? }
|
331
|
-
when :checkbox
|
332
|
-
Watir::Wait.until { browser.checkbox(how, what).visible? }
|
333
|
-
when :div
|
334
|
-
Watir::Wait.until { browser.div(how, what).visible? }
|
335
|
-
when :select_list
|
336
|
-
Watir::Wait.until { browser.select_list(how, what).visible? }
|
337
|
-
when :text_field
|
338
|
-
Watir::Wait.until { browser.text_field(how, what).visible? }
|
339
|
-
else
|
340
|
-
Watir::Wait.until { browser.element(how, what).visible? }
|
341
|
-
# raise "#{__method__}: Element #{what} not supported."
|
342
|
-
end
|
343
|
-
rescue => e
|
344
|
-
if e.class.to_s =~ /TimeOutException/
|
345
|
-
failed_to_log("Wait until (#{what} :#{how}=>#{what}) visible. #{desc}: '#{$!}' #{desc}")
|
346
|
-
return false
|
347
|
-
elsif not rescue_me(e, __method__, rescue_me_command(element, how, what, :visible?), "#{browser.class}")
|
348
|
-
raise e
|
349
|
-
end
|
350
|
-
end
|
351
|
-
stop = Time.now.to_f
|
352
|
-
#debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
|
353
|
-
# sleep 1
|
354
|
-
passed_to_log("Wait until (#{element} :#{how}=>#{what}) visible. #{desc} (#{stop - start} seconds)")
|
355
|
-
true
|
356
|
-
rescue
|
357
|
-
failed_to_log("Unable to complete wait until (#{element} :#{how}=>#{what}) visible. #{desc}: '#{$!}'")
|
358
|
-
end
|
359
|
-
|
360
|
-
# @!endgroup Core
|
361
|
-
|
362
|
-
# @!group Altenatives
|
363
|
-
|
364
|
-
# Wait for a specific text to appear in the *browser*.
|
365
|
-
# @note This is a last resort method when other wait or wait until avenues have been exhausted.
|
366
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
367
|
-
# @param [String, Regexp] text A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
368
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
369
|
-
# @param [Fixnum] threshold The number of seconds after which a warning is added to the report message.
|
370
|
-
# @param [Fixnum] interval The time between checks that the text exists.
|
371
|
-
# @return [Boolean] Returns true if the text appears before *how_long* has expired.
|
372
|
-
def hold_for_text(browser, how_long, text, desc = '', threshold = 20, interval = 0.25)
|
373
|
-
countdown = how_long
|
374
|
-
Watir::Wait.until { browser.exists? }
|
375
|
-
sleep_for(1)
|
376
|
-
while ((not browser.contains_text(text)) and countdown > 0)
|
377
|
-
sleep(interval)
|
378
|
-
countdown = countdown - interval
|
379
|
-
end
|
380
|
-
if countdown < how_long
|
381
|
-
waittime = how_long - countdown
|
382
|
-
passed_to_log("#{__method__} '#{text}' found after #{waittime} second(s) #{desc}")
|
383
|
-
if waittime > threshold
|
384
|
-
failed_to_log("#{__method__} '#{text}' took #{waittime} second(s). (threshold: #{threshold} seconds) #{desc}")
|
385
|
-
end
|
386
|
-
true
|
387
|
-
else
|
388
|
-
failed_to_log("#{__method__} '#{text}' not found after #{how_long} second(s) #{desc}")
|
389
|
-
false
|
390
|
-
end
|
391
|
-
rescue
|
392
|
-
failed_to_log("Unable to #{__method__} '#{text}'. '#{$!}' #{desc}")
|
393
|
-
end
|
394
|
-
|
395
|
-
alias wait_for_text hold_for_text
|
396
|
-
|
397
|
-
# Wait up to *how_long* seconds for DOM element *what_for* to exist in the page.
|
398
|
-
# @note This is a last resort method when other wait or wait until avenues have been exhausted.
|
399
|
-
# @param [Fixnum] how_long Timeout limit
|
400
|
-
# @param [Watir::Element] what_for A reference to a Dom element to wait for.
|
401
|
-
def wait_for_exists(how_long, what_for)
|
402
|
-
wait_for(how_long, what_for)
|
403
|
-
end
|
404
|
-
|
405
|
-
# Wait up to *how_long* seconds for DOM element *what_for* to exist in the page.
|
406
|
-
# @note This is a last resort method when other wait or wait until avenues have
|
407
|
-
# been exhausted.
|
408
|
-
# @param [Fixnum] how_long Timeout limit
|
409
|
-
# @param [Watir::Element] what_for A reference to a Dom element to wait for.
|
410
|
-
def wait_for(how_long, what_for, interval = 0.25)
|
411
|
-
countdown = how_long
|
412
|
-
while ((not what_for.exists?) and countdown > 0)
|
413
|
-
sleep(interval)
|
414
|
-
puts what_for.inspect+':'+countdown.to_s
|
415
|
-
countdown = countdown - interval
|
416
|
-
end
|
417
|
-
if countdown
|
418
|
-
puts 'found '+what_for.inspect
|
419
|
-
passed_tolog("wait_for (#{how_long} found "+what_for.inspect)
|
420
|
-
else
|
421
|
-
puts 'Did not find '+what_for.inspect
|
422
|
-
failed_tolog("wait_for (#{how_long} did not find "+what_for.inspect)
|
423
|
-
end
|
424
|
-
countdown
|
425
|
-
end
|
426
|
-
|
427
|
-
# Wait up to *how_long* seconds for DOM element identified by attribute *how* and its value
|
428
|
-
# *what* to exist in the page.
|
429
|
-
# @note This is a last resort method when other wait or wait until avenues have been exhausted.
|
430
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
431
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
432
|
-
# Valid values depend on the kind of element.
|
433
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
434
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
435
|
-
# @param [Fixnum] wait Timeout limit.
|
436
|
-
# @param [Fixnum] interval How long to wait before checking again.
|
437
|
-
# @return [Boolean] True if element exists within *wait* time
|
438
|
-
def wait_the_hard_way(browser, how, what, wait = 6, interval = 0.25)
|
439
|
-
count = (wait / interval).to_i + 1
|
440
|
-
tally = 0
|
441
|
-
ok = (1 / interval).to_i + 1
|
442
|
-
debug_to_log("#{__method__}: wait: #{wait} secs; interval: #{interval} secs; count; #{count}; thresh: #{ok}")
|
443
|
-
Watir::Wait.until { browser.exists? }
|
444
|
-
sleep_for(1)
|
445
|
-
(1..count).each do |x|
|
446
|
-
begin
|
447
|
-
if browser.element(how, what).exists?
|
448
|
-
tally += 1
|
449
|
-
debug_to_log("#{x}: #{(x - 1) * interval}: #{what} exists.")
|
450
|
-
else
|
451
|
-
tally = 0
|
452
|
-
debug_to_log("#{x}: #{(x - 1) * interval}: #{what} does not exist.")
|
453
|
-
end
|
454
|
-
rescue
|
455
|
-
tally = 0
|
456
|
-
debug_to_log("#{x}: #{(x - 1) * interval}: #{what} rescue: #{$!}")
|
457
|
-
end
|
458
|
-
if tally >= ok
|
459
|
-
return true
|
460
|
-
end
|
461
|
-
sleep(interval)
|
462
|
-
end
|
463
|
-
end
|
464
|
-
|
465
|
-
# @!endgroup Alternatives
|
466
|
-
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
1
|
+
module Awetestlib
|
2
|
+
module Regression
|
3
|
+
# Methods for waiting until something has happened, or waiting while a condition exists, in the browser or DOM.
|
4
|
+
# sleep_for() is the basic technique. Its disadvantage is that it needs to be set for the longest likely wait time.
|
5
|
+
# The wait methods take advantage of the Watir and Watir Webdriver wait functionality to pause only as long as necessary for
|
6
|
+
# the element in question to be in the state needed.
|
7
|
+
module Waits
|
8
|
+
|
9
|
+
# @!group Core
|
10
|
+
|
11
|
+
# Sleep for *seconds* seconds before continuing execution of the script.
|
12
|
+
# A message is logged (but not reported) which, by default, includes a trace showing where in the script the sleep was invoked.
|
13
|
+
# @param [Fixnum] seconds The number of seconds to wait.
|
14
|
+
# @param [Boolean] dbg If true, includes a trace in the message
|
15
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output.
|
16
|
+
def sleep_for(seconds, dbg = true, desc = '')
|
17
|
+
trace = "\n#{get_debug_list}" if dbg
|
18
|
+
msg = build_message("Sleeping for #{seconds} seconds.", desc, trace)
|
19
|
+
info_to_log(msg)
|
20
|
+
sleep(seconds)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Wait while an element identified by attribute *how* with value *what* 1) exists, disappears, and exists again.
|
24
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
25
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
26
|
+
# Valid values depend on the kind of element.
|
27
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
28
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
29
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
30
|
+
# @param [Fixnum] timeout
|
31
|
+
# @return [Boolean] Returns true if disappears and reappears, each within the *timeout* limit
|
32
|
+
def wait_for_element_to_reappear(browser, how, what, desc = '', timeout = 20)
|
33
|
+
msg = "Element #{how}=#{what} exists. #{desc}"
|
34
|
+
wait_while(browser, "While: #{msg}", timeout) { browser.element(how, what).exists? }
|
35
|
+
wait_until(browser, "Until: #{msg}", timeout) { browser.element(how, what).exists? }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Wait until element of type *element*, identified by attribute *how* with value *what* exists on the page.
|
39
|
+
# Timeout is the default used by watir (60 seconds)
|
40
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
41
|
+
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
42
|
+
# Some common values are :link, :button, :image, :div, :span.
|
43
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
44
|
+
# Valid values depend on the kind of element.
|
45
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
46
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
47
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
48
|
+
# @return [Boolean] True if element exists within timeout limit
|
49
|
+
def wait_until_exists(browser, element, how, what, desc = '')
|
50
|
+
msg = build_message("Wait until (:#{element} :#{how}=>'#{what}') exists.", desc)
|
51
|
+
start = Time.now.to_f
|
52
|
+
# TODO: try Watir::Wait.until { browser.element(how, what).exists? } instead of this (cumbersome) case statement
|
53
|
+
# TODO: above fails on frame
|
54
|
+
Watir::Wait.until { browser.exists? }
|
55
|
+
begin
|
56
|
+
case element
|
57
|
+
when :link
|
58
|
+
Watir::Wait.until { browser.link(how, what).exists? }
|
59
|
+
when :button
|
60
|
+
Watir::Wait.until { browser.button(how, what).exists? }
|
61
|
+
when :radio
|
62
|
+
Watir::Wait.until { browser.radio(how, what).exists? }
|
63
|
+
when :checkbox
|
64
|
+
Watir::Wait.until { browser.checkbox(how, what).exists? }
|
65
|
+
when :div
|
66
|
+
Watir::Wait.until { browser.div(how, what).exists? }
|
67
|
+
when :select_list
|
68
|
+
Watir::Wait.until { browser.select_list(how, what).exists? }
|
69
|
+
when :text_field
|
70
|
+
Watir::Wait.until { browser.text_field(how, what).exists? }
|
71
|
+
when :frame
|
72
|
+
Watir::Wait.until { browser.frame(how, what).exists? }
|
73
|
+
when :form
|
74
|
+
Watir::Wait.until { browser.form(how, what).exists? }
|
75
|
+
when :cell
|
76
|
+
Watir::Wait.until { browser.cell(how, what).exists? }
|
77
|
+
when :image
|
78
|
+
Watir::Wait.until { browser.image(how, what).exists? }
|
79
|
+
else
|
80
|
+
Watir::Wait.until { browser.element(how, what).exists? }
|
81
|
+
end
|
82
|
+
rescue => e
|
83
|
+
if e.class.to_s =~ /TimeOutException/
|
84
|
+
failed_to_log("#{msg}: '#{$!}'")
|
85
|
+
return false
|
86
|
+
elsif not rescue_me(e, __method__, rescue_me_command(element, how, what, :exists?), "#{browser.class}")
|
87
|
+
raise e
|
88
|
+
end
|
89
|
+
end
|
90
|
+
stop = Time.now.to_f
|
91
|
+
#debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
|
92
|
+
# sleep 1
|
93
|
+
passed_to_log("#{msg} (#{stop - start} seconds)")
|
94
|
+
true
|
95
|
+
rescue
|
96
|
+
failed_to_log("Unable to complete #{msg}: '#{$!}'")
|
97
|
+
end
|
98
|
+
|
99
|
+
# Wait _while_ expression in *&block* returns true.
|
100
|
+
# @example
|
101
|
+
# wait_while(browser, 'Textfield is enabled.', 10) { browser.text_field(:id, 'this text field').enabled?}
|
102
|
+
#
|
103
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
104
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
105
|
+
# @param [Fixnum] timeout Maximum time to wait, in seconds.
|
106
|
+
# @param [Proc] &block A ruby expression that evaluates to true or false. The expression
|
107
|
+
# is usually a watir or watir-webdriver command like .exists?, enabled?, etc. on a
|
108
|
+
# specific DOM element. Note that *&block* is listed as the last parameter inside the signature
|
109
|
+
# parentheses, but is passed in curly braces outside the signature parentheses in the call. This is
|
110
|
+
# the way Ruby works.
|
111
|
+
# @return [Boolean] True if condition returns false within time limit.
|
112
|
+
def wait_while(browser, desc, timeout = 45, &block)
|
113
|
+
#TODO: Would like to be able to see the block code in the log message instead of the identification
|
114
|
+
msg = "Wait while #{desc}:"
|
115
|
+
start = Time.now.to_f
|
116
|
+
Watir::Wait.until { browser.exists? }
|
117
|
+
begin
|
118
|
+
#Watir::Wait.until(timeout) { block.call(nil) }
|
119
|
+
if block.call(nil)
|
120
|
+
Watir::Wait.while(timeout) { block.call(nil) }
|
121
|
+
end
|
122
|
+
rescue => e
|
123
|
+
if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
|
124
|
+
failed_to_log("#{msg}: '#{$!}' ")
|
125
|
+
return false
|
126
|
+
elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
|
127
|
+
raise e
|
128
|
+
end
|
129
|
+
end
|
130
|
+
stop = Time.now.to_f
|
131
|
+
#debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
|
132
|
+
# sleep 1
|
133
|
+
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") # {#{block.to_s}}")
|
134
|
+
true
|
135
|
+
rescue
|
136
|
+
failed_to_log("Unable to complete #{msg}. '#{$!}'")
|
137
|
+
end
|
138
|
+
|
139
|
+
alias wait_while_true wait_while
|
140
|
+
|
141
|
+
# Wait _until_ expression in *&block* returns true.
|
142
|
+
# @example
|
143
|
+
# wait_until(browser, 'Textfield is enabled.', 10) { browser.text_field(:id, 'this text field').exists?}
|
144
|
+
#
|
145
|
+
# @param (see #wait_while)
|
146
|
+
# @return [Boolean] True if condition in *&block* returns true within time limit.
|
147
|
+
def wait_until(browser, desc, timeout = 45, skip_pass = false, &block)
|
148
|
+
#TODO: Would like to be able to see the block code in the log message instead of the identification
|
149
|
+
msg = "Wait until #{desc}"
|
150
|
+
start = Time.now.to_f
|
151
|
+
Watir::Wait.until { browser.exists? }
|
152
|
+
begin
|
153
|
+
Watir::Wait.until(timeout) { block.call(nil) }
|
154
|
+
rescue => e
|
155
|
+
if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
|
156
|
+
failed_to_log("#{msg} '#{$!}'")
|
157
|
+
return false
|
158
|
+
elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
|
159
|
+
raise e
|
160
|
+
end
|
161
|
+
end
|
162
|
+
stop = Time.now.to_f
|
163
|
+
#debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
|
164
|
+
# sleep 1
|
165
|
+
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless skip_pass # {#{block.to_s}}")
|
166
|
+
true
|
167
|
+
rescue
|
168
|
+
failed_to_log("Unable to complete #{msg} '#{$!}'")
|
169
|
+
end
|
170
|
+
|
171
|
+
alias wait_until_true wait_until
|
172
|
+
|
173
|
+
# Wait _until_ element, identified by attribute *how* and its value *what*, exists.
|
174
|
+
# If it exists within *timeout* seconds then wait _until_ it is enabled.
|
175
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
176
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
177
|
+
# Valid values depend on the kind of element.
|
178
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
179
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
180
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
181
|
+
# @param [Fixnum] timeout Maximum time to wait, in seconds.
|
182
|
+
# @param [Boolean] verbose When set to true, more debug information is written to the log and
|
183
|
+
# all steps return pass/fail messages in the report.
|
184
|
+
# @return [Boolean] True if condition returns false within time limit.
|
185
|
+
def wait_until_ready(browser, how, what, desc = '', timeout = 90, verbose = false)
|
186
|
+
msg = "#{__method__.to_s.titleize}: element: #{how}='#{what}'"
|
187
|
+
msg << " #{desc}" if desc.length > 0
|
188
|
+
proc_exists = Proc.new { browser.element(how, what).exists? }
|
189
|
+
proc_enabled = Proc.new { browser.element(how, what).enabled? }
|
190
|
+
case how
|
191
|
+
when :href
|
192
|
+
proc_exists = Proc.new { browser.link(how, what).exists? }
|
193
|
+
proc_enabled = Proc.new { browser.link(how, what).enabled? }
|
194
|
+
end
|
195
|
+
if verbose
|
196
|
+
if wait_until(browser, "#{msg} Element exists.", timeout) { proc_exists.call(nil) }
|
197
|
+
if wait_until(browser, "#{msg} Element enabled.", timeout) { proc_enabled.call(nil) }
|
198
|
+
passed_to_log(msg)
|
199
|
+
true
|
200
|
+
else
|
201
|
+
failed_to_log(msg)
|
202
|
+
end
|
203
|
+
else
|
204
|
+
failed_to_log(msg)
|
205
|
+
end
|
206
|
+
else
|
207
|
+
start = Time.now.to_f
|
208
|
+
Watir::Wait.until { browser.exists? }
|
209
|
+
if Watir::Wait.until(timeout) { proc_exists.call(nil) }
|
210
|
+
if Watir::Wait.until(timeout) { proc_enabled.call(nil) }
|
211
|
+
stop = Time.now.to_f
|
212
|
+
#debug_to_log("#{__method__}: start:#{"%.5f" % start} stop:#{"%.5f" % stop}")
|
213
|
+
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)")
|
214
|
+
true
|
215
|
+
else
|
216
|
+
failed_to_log(msg)
|
217
|
+
end
|
218
|
+
else
|
219
|
+
failed_to_log(msg)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
rescue
|
223
|
+
failed_to_log("Unable to #{msg}. '#{$!}'")
|
224
|
+
end
|
225
|
+
|
226
|
+
# Wait _until_ element, identified by attribute *how* and its value *what*, exists.
|
227
|
+
# If it exists within *timeout* seconds then wait _until_ it is enabled. Report only failures.
|
228
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
229
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
230
|
+
# Valid values depend on the kind of element.
|
231
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
232
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
233
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
234
|
+
# @param [Fixnum] timeout Maximum time to wait, in seconds.
|
235
|
+
# @param [Boolean] quiet When set to true, only fail messages are logged and reported.
|
236
|
+
# @return [Boolean] True if condition returns false within time limit.
|
237
|
+
def wait_until_ready_quiet(browser, how, what, desc = '', timeout = 45, quiet = true)
|
238
|
+
msg = "#{__method__.to_s.titleize}: element: #{how}='#{what}'"
|
239
|
+
msg << " #{desc}" if desc.length > 0
|
240
|
+
proc_exists = Proc.new { browser.element(how, what).exists? }
|
241
|
+
proc_enabled = Proc.new { browser.element(how, what).enabled? }
|
242
|
+
case how
|
243
|
+
when :href
|
244
|
+
proc_exists = Proc.new { browser.link(how, what).exists? }
|
245
|
+
proc_enabled = Proc.new { browser.link(how, what).enabled? }
|
246
|
+
end
|
247
|
+
start = Time.now.to_f
|
248
|
+
Watir::Wait.until { browser.exists? }
|
249
|
+
sleep_for(1)
|
250
|
+
if Watir::Wait.until(timeout) { proc_exists.call(nil) }
|
251
|
+
if Watir::Wait.until(timeout) { proc_enabled.call(nil) }
|
252
|
+
stop = Time.now.to_f
|
253
|
+
#debug_to_log("#{msg}: start:#{"%.5f" % start} stop:#{"%.5f" % stop}")
|
254
|
+
passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless quiet
|
255
|
+
true
|
256
|
+
else
|
257
|
+
failed_to_log(msg)
|
258
|
+
end
|
259
|
+
else
|
260
|
+
failed_to_log(msg)
|
261
|
+
end
|
262
|
+
rescue
|
263
|
+
failed_to_log("Unable to #{msg}. '#{$!}'")
|
264
|
+
end
|
265
|
+
|
266
|
+
def wait_until_text(browser, strg, desc = '', timeout = 60)
|
267
|
+
if not strg.class.to_s.match('String')
|
268
|
+
raise "#{__method__} requires String for search target. #{strg.class} is not supported."
|
269
|
+
end
|
270
|
+
wait_until(browser, "'#{strg}' #{desc}", timeout) { browser.text.include? strg }
|
271
|
+
end
|
272
|
+
|
273
|
+
alias wait_until_by_text wait_until_text
|
274
|
+
|
275
|
+
def wait_until_enabled(browser, what, how, value, desc = '')
|
276
|
+
# TODO: This can be simplified
|
277
|
+
start = Time.now.to_f
|
278
|
+
Watir::Wait.until { browser.exists? }
|
279
|
+
sleep_for(1)
|
280
|
+
begin
|
281
|
+
case what
|
282
|
+
when :link
|
283
|
+
Watir::Wait.until { browser.link(how, value).enabled? }
|
284
|
+
when :button
|
285
|
+
Watir::Wait.until { browser.button(how, value).enabled? }
|
286
|
+
when :radio
|
287
|
+
Watir::Wait.until { browser.radio(how, value).enabled? }
|
288
|
+
when :checkbox
|
289
|
+
Watir::Wait.until { browser.checkbox(how, value).enabled? }
|
290
|
+
when :div
|
291
|
+
Watir::Wait.until { browser.div(how, value).enabled? }
|
292
|
+
when :select_list
|
293
|
+
Watir::Wait.until { browser.select_list(how, value).enabled? }
|
294
|
+
when :text_field
|
295
|
+
Watir::Wait.until { browser.text_field(how, value).enabled? }
|
296
|
+
when :table
|
297
|
+
Watir::Wait.until { browser.table(how, value).enabled? }
|
298
|
+
else
|
299
|
+
Watir::Wait.until { browser.element(how, value).enabled? }
|
300
|
+
end
|
301
|
+
rescue => e
|
302
|
+
if e.class.to_s =~ /TimeOutException/
|
303
|
+
failed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}' #{desc}")
|
304
|
+
return false
|
305
|
+
elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
|
306
|
+
raise e
|
307
|
+
end
|
308
|
+
end
|
309
|
+
stop = Time.now.to_f
|
310
|
+
#debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
|
311
|
+
# sleep 1
|
312
|
+
passed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc} (#{stop - start} seconds)")
|
313
|
+
true
|
314
|
+
rescue
|
315
|
+
failed_to_log("Unable to complete wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}'")
|
316
|
+
end
|
317
|
+
|
318
|
+
def wait_until_visible(browser, element, how, what, desc = '')
|
319
|
+
start = Time.now.to_f
|
320
|
+
Watir::Wait.until { browser.exists? }
|
321
|
+
sleep_for(1)
|
322
|
+
Watir::Wait.until(20) { browser.element(how, what).exists? }
|
323
|
+
begin
|
324
|
+
case element
|
325
|
+
when :link
|
326
|
+
Watir::Wait.until { browser.link(how, what).visible? }
|
327
|
+
when :button
|
328
|
+
Watir::Wait.until { browser.button(how, what).visible? }
|
329
|
+
when :radio
|
330
|
+
Watir::Wait.until { browser.radio(how, what).visible? }
|
331
|
+
when :checkbox
|
332
|
+
Watir::Wait.until { browser.checkbox(how, what).visible? }
|
333
|
+
when :div
|
334
|
+
Watir::Wait.until { browser.div(how, what).visible? }
|
335
|
+
when :select_list
|
336
|
+
Watir::Wait.until { browser.select_list(how, what).visible? }
|
337
|
+
when :text_field
|
338
|
+
Watir::Wait.until { browser.text_field(how, what).visible? }
|
339
|
+
else
|
340
|
+
Watir::Wait.until { browser.element(how, what).visible? }
|
341
|
+
# raise "#{__method__}: Element #{what} not supported."
|
342
|
+
end
|
343
|
+
rescue => e
|
344
|
+
if e.class.to_s =~ /TimeOutException/
|
345
|
+
failed_to_log("Wait until (#{what} :#{how}=>#{what}) visible. #{desc}: '#{$!}' #{desc}")
|
346
|
+
return false
|
347
|
+
elsif not rescue_me(e, __method__, rescue_me_command(element, how, what, :visible?), "#{browser.class}")
|
348
|
+
raise e
|
349
|
+
end
|
350
|
+
end
|
351
|
+
stop = Time.now.to_f
|
352
|
+
#debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
|
353
|
+
# sleep 1
|
354
|
+
passed_to_log("Wait until (#{element} :#{how}=>#{what}) visible. #{desc} (#{stop - start} seconds)")
|
355
|
+
true
|
356
|
+
rescue
|
357
|
+
failed_to_log("Unable to complete wait until (#{element} :#{how}=>#{what}) visible. #{desc}: '#{$!}'")
|
358
|
+
end
|
359
|
+
|
360
|
+
# @!endgroup Core
|
361
|
+
|
362
|
+
# @!group Altenatives
|
363
|
+
|
364
|
+
# Wait for a specific text to appear in the *browser*.
|
365
|
+
# @note This is a last resort method when other wait or wait until avenues have been exhausted.
|
366
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
367
|
+
# @param [String, Regexp] text A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
368
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
369
|
+
# @param [Fixnum] threshold The number of seconds after which a warning is added to the report message.
|
370
|
+
# @param [Fixnum] interval The time between checks that the text exists.
|
371
|
+
# @return [Boolean] Returns true if the text appears before *how_long* has expired.
|
372
|
+
def hold_for_text(browser, how_long, text, desc = '', threshold = 20, interval = 0.25)
|
373
|
+
countdown = how_long
|
374
|
+
Watir::Wait.until { browser.exists? }
|
375
|
+
sleep_for(1)
|
376
|
+
while ((not browser.contains_text(text)) and countdown > 0)
|
377
|
+
sleep(interval)
|
378
|
+
countdown = countdown - interval
|
379
|
+
end
|
380
|
+
if countdown < how_long
|
381
|
+
waittime = how_long - countdown
|
382
|
+
passed_to_log("#{__method__} '#{text}' found after #{waittime} second(s) #{desc}")
|
383
|
+
if waittime > threshold
|
384
|
+
failed_to_log("#{__method__} '#{text}' took #{waittime} second(s). (threshold: #{threshold} seconds) #{desc}")
|
385
|
+
end
|
386
|
+
true
|
387
|
+
else
|
388
|
+
failed_to_log("#{__method__} '#{text}' not found after #{how_long} second(s) #{desc}")
|
389
|
+
false
|
390
|
+
end
|
391
|
+
rescue
|
392
|
+
failed_to_log("Unable to #{__method__} '#{text}'. '#{$!}' #{desc}")
|
393
|
+
end
|
394
|
+
|
395
|
+
alias wait_for_text hold_for_text
|
396
|
+
|
397
|
+
# Wait up to *how_long* seconds for DOM element *what_for* to exist in the page.
|
398
|
+
# @note This is a last resort method when other wait or wait until avenues have been exhausted.
|
399
|
+
# @param [Fixnum] how_long Timeout limit
|
400
|
+
# @param [Watir::Element] what_for A reference to a Dom element to wait for.
|
401
|
+
def wait_for_exists(how_long, what_for)
|
402
|
+
wait_for(how_long, what_for)
|
403
|
+
end
|
404
|
+
|
405
|
+
# Wait up to *how_long* seconds for DOM element *what_for* to exist in the page.
|
406
|
+
# @note This is a last resort method when other wait or wait until avenues have
|
407
|
+
# been exhausted.
|
408
|
+
# @param [Fixnum] how_long Timeout limit
|
409
|
+
# @param [Watir::Element] what_for A reference to a Dom element to wait for.
|
410
|
+
def wait_for(how_long, what_for, interval = 0.25)
|
411
|
+
countdown = how_long
|
412
|
+
while ((not what_for.exists?) and countdown > 0)
|
413
|
+
sleep(interval)
|
414
|
+
puts what_for.inspect+':'+countdown.to_s
|
415
|
+
countdown = countdown - interval
|
416
|
+
end
|
417
|
+
if countdown
|
418
|
+
puts 'found '+what_for.inspect
|
419
|
+
passed_tolog("wait_for (#{how_long} found "+what_for.inspect)
|
420
|
+
else
|
421
|
+
puts 'Did not find '+what_for.inspect
|
422
|
+
failed_tolog("wait_for (#{how_long} did not find "+what_for.inspect)
|
423
|
+
end
|
424
|
+
countdown
|
425
|
+
end
|
426
|
+
|
427
|
+
# Wait up to *how_long* seconds for DOM element identified by attribute *how* and its value
|
428
|
+
# *what* to exist in the page.
|
429
|
+
# @note This is a last resort method when other wait or wait until avenues have been exhausted.
|
430
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
431
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
432
|
+
# Valid values depend on the kind of element.
|
433
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
434
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
435
|
+
# @param [Fixnum] wait Timeout limit.
|
436
|
+
# @param [Fixnum] interval How long to wait before checking again.
|
437
|
+
# @return [Boolean] True if element exists within *wait* time
|
438
|
+
def wait_the_hard_way(browser, how, what, wait = 6, interval = 0.25)
|
439
|
+
count = (wait / interval).to_i + 1
|
440
|
+
tally = 0
|
441
|
+
ok = (1 / interval).to_i + 1
|
442
|
+
debug_to_log("#{__method__}: wait: #{wait} secs; interval: #{interval} secs; count; #{count}; thresh: #{ok}")
|
443
|
+
Watir::Wait.until { browser.exists? }
|
444
|
+
sleep_for(1)
|
445
|
+
(1..count).each do |x|
|
446
|
+
begin
|
447
|
+
if browser.element(how, what).exists?
|
448
|
+
tally += 1
|
449
|
+
debug_to_log("#{x}: #{(x - 1) * interval}: #{what} exists.")
|
450
|
+
else
|
451
|
+
tally = 0
|
452
|
+
debug_to_log("#{x}: #{(x - 1) * interval}: #{what} does not exist.")
|
453
|
+
end
|
454
|
+
rescue
|
455
|
+
tally = 0
|
456
|
+
debug_to_log("#{x}: #{(x - 1) * interval}: #{what} rescue: #{$!}")
|
457
|
+
end
|
458
|
+
if tally >= ok
|
459
|
+
return true
|
460
|
+
end
|
461
|
+
sleep(interval)
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
# @!endgroup Alternatives
|
466
|
+
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|