awetestlib 0.1.28 → 0.1.29pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/.gitattributes +22 -22
  2. data/.gitignore +69 -69
  3. data/.yardopts +7 -7
  4. data/README.md +108 -108
  5. data/awetestlib.gemspec +57 -57
  6. data/awetestlib.windows.gemspec +41 -41
  7. data/awetestlib_notes.txt +4 -4
  8. data/awetestlib_osx.gemspec +47 -48
  9. data/bin/awetestlib +99 -99
  10. data/bin/awetestlib-android-setup.rb +26 -26
  11. data/bin/awetestlib-cucumber-setup.rb +28 -28
  12. data/bin/awetestlib-driver-setup.rb +21 -21
  13. data/bin/awetestlib-helpers.rb +41 -41
  14. data/bin/awetestlib-mobile-app-setup.rb +31 -31
  15. data/bin/awetestlib-netbeans-setup.rb +58 -58
  16. data/bin/awetestlib-regression-setup.rb +15 -15
  17. data/bin/awetestlib-rubymine-setup.rb +39 -39
  18. data/drivers/chromedriver.exe +0 -0
  19. data/ext/Rakefile +1 -1
  20. data/ext/mkrf_conf.rb +27 -27
  21. data/lib/awetestlib/html_report.rb +142 -142
  22. data/lib/awetestlib/logging.rb +366 -366
  23. data/lib/awetestlib/regression/browser.rb +1380 -1375
  24. data/lib/awetestlib/regression/drag_and_drop.rb +421 -420
  25. data/lib/awetestlib/regression/find.rb +345 -345
  26. data/lib/awetestlib/regression/legacy.rb +1187 -1187
  27. data/lib/awetestlib/regression/page_data.rb +191 -191
  28. data/lib/awetestlib/regression/runner.rb +307 -307
  29. data/lib/awetestlib/regression/tables.rb +627 -619
  30. data/lib/awetestlib/regression/user_input.rb +576 -576
  31. data/lib/awetestlib/regression/utilities.rb +1046 -988
  32. data/lib/awetestlib/regression/validations.rb +1093 -1074
  33. data/lib/awetestlib/regression/waits.rb +470 -470
  34. data/lib/awetestlib/runner.rb +18 -18
  35. data/lib/awetestlib.rb +41 -41
  36. data/lib/patches/README +2 -2
  37. data/lib/patches/firewatir.rb +106 -106
  38. data/lib/patches/watir.rb +175 -175
  39. data/lib/version.rb +2 -2
  40. data/license.txt +13 -13
  41. data/netbeans_setup.md +29 -29
  42. data/rdoc_test.bat +1 -1
  43. data/rubymine_setup.md +23 -23
  44. data/setup_samples/sample_android/features/dk.mejer.hansen.control.FlyingColorsPlayerAidActivity.apk +0 -0
  45. data/setup_samples/sample_android/features/sample_android.feature +5 -5
  46. data/setup_samples/sample_android/features/step_definitions/calabash_steps.rb +1 -1
  47. data/setup_samples/sample_android/features/support/app_installation_hooks.rb +36 -36
  48. data/setup_samples/sample_android/features/support/app_life_cycle_hooks.rb +14 -14
  49. data/setup_samples/sample_android/features/test_servers/8ba795a0288381ae346b67867b586881_0.3.2.apk +0 -0
  50. data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +76 -76
  51. data/setup_samples/sample_cucumber/features/yahoo_mail.feature +11 -11
  52. data/setup_samples/sample_mobile_app/features/my_first.feature +14 -14
  53. data/setup_samples/sample_mobile_app/features/step_definitions/predefined_webview_steps.rb +80 -80
  54. data/setup_samples/sample_mobile_app/features/support/env.rb +2 -2
  55. data/setup_samples/sample_netbeans/demo.rb +86 -86
  56. data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -2
  57. data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -1
  58. data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +2 -2
  59. data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -2
  60. data/setup_samples/sample_netbeans/nbproject/project.properties +5 -5
  61. data/setup_samples/sample_netbeans/nbproject/project.xml +13 -13
  62. data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -5
  63. data/setup_samples/sample_rubymine/.idea/misc.xml +5 -5
  64. data/setup_samples/sample_rubymine/.idea/modules.xml +9 -9
  65. data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -9
  66. data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +4 -4
  67. data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -7
  68. data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -213
  69. data/setup_samples/sample_rubymine/demo.rb +86 -86
  70. data/test/create_zoho.rb +66 -66
  71. data/test/create_zoho_account1.rb +68 -68
  72. data/test/create_zoho_account2.rb +72 -72
  73. data/test/demo.rb +87 -87
  74. data/test/google_search1.rb +16 -16
  75. data/test/google_search2.rb +19 -19
  76. data/test/login_1.rb +37 -37
  77. data/test/login_1a.rb +37 -37
  78. data/test/login_2.rb +32 -32
  79. data/test/zoho_exercise.rb +21 -21
  80. data/test/zoho_util.rb +487 -487
  81. data/tmp/placeholder.html +71 -71
  82. metadata +18 -49
@@ -1,1074 +1,1093 @@
1
- module Awetestlib
2
- module Regression
3
- # Contains methods to verify content, accessibility, or appearance of page elements.
4
- module Validations
5
-
6
- # @!group Core
7
-
8
- # Verify that element style attribute contains expected value in style *type*.
9
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
10
- # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
11
- # Some common values are :link, :button, :image, :div, :span.
12
- # @param [Symbol] how The element attribute used to identify the specific element.
13
- # Valid values depend on the kind of element.
14
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
15
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
16
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
17
- # @param [String] type The name of the style type (sub-attribute) where *expected* is to be found.
18
- # @param [String] expected The value in *type* expected.
19
- # @return [Boolean] True if the style type contains the expected value
20
- #
21
- def validate_style_value(browser, element, how, what, type, expected, desc = '')
22
- #TODO: works only with watir-webdriver
23
- msg = build_message("Expected Style #{type} value '#{expected}' in #{element} with #{how} = #{what}", desc)
24
- case element
25
- when :link
26
- actual = browser.link(how => what).style type
27
- when :button
28
- actual = browser.button(how => what).style type
29
- when :image
30
- actual = browser.image(how => what).style type
31
- when :span
32
- actual = browser.span(how => what).style type
33
- when :div
34
- actual = browser.div(how => what).style type
35
- else
36
- if browser.element(how => what).responds_to?("style")
37
- actual = browser.element(how => what).style type
38
- else
39
- failed_to_log("#{msg}: Element #{element} does not repond to style command.")
40
- end
41
- end
42
- if expected == actual
43
- passed_to_log(msg)
44
- true
45
- else
46
- failed_to_log(msg)
47
- end
48
- rescue
49
- failed_to_log("Unable to verify that #{msg} '#{$!}'")
50
- end
51
-
52
- def validate_style_greater_than_value(browser, element, how, what, type, value, desc = '')
53
- case element
54
- when :link
55
- actual_value = browser.link(how => what).style type
56
- when :button
57
- actual_value = browser.button(how => what).style type
58
- when :image
59
- actual_value = browser.image(how => what).style type
60
- when :span
61
- actual_value = browser.span(how => what).style type
62
- when :div
63
- actual_value = browser.div(how => what).style type
64
- else
65
- actual_value = browser.element(how => what).style type
66
- end
67
- msg = build_message("The CSS value for style #{type} in #{element} :#{how}=>#{what}: '#{actual_value}' is greater than #{value}.", desc)
68
-
69
- if actual_value.to_i > value.to_i
70
- passed_to_log(msg)
71
- elsif actual_value.to_i >~ value.to_i
72
- passed_to_log(msg)
73
- else
74
- failed_to_log(msg)
75
- end
76
- rescue
77
- fail_to_log("Unable to verify #{msg} '#{$!}'")
78
- # sleep_for(1)
79
- end
80
-
81
- alias validate_style_greaterthan_value validate_style_greater_than_value
82
-
83
- def validate_style_less_than_value(browser, element, how, what, type, value, desc = '')
84
- case element
85
- when :link
86
- actual_value = browser.link(how => what).style type
87
- when :button
88
- actual_value = browser.button(how => what).style type
89
- when :image
90
- actual_value = browser.image(how => what).style type
91
- when :span
92
- actual_value = browser.span(how => what).style type
93
- when :div
94
- actual_value = browser.div(how => what).style type
95
- else
96
- actual_value = browser.element(how => what).style type
97
- end
98
- msg = build_message("The CSS value for style #{type} in #{element} :#{how}=>#{what}: '#{actual_value}' is greater than #{value}.", desc)
99
-
100
- if actual_value.to_i < value.to_i
101
- passed_to_log(msg)
102
- elsif actual_value.to_i <~ value.to_i
103
- passed_to_log(msg)
104
- else
105
- failed_to_log(msg)
106
- end
107
- rescue
108
- fail_to_log("Unable to verify #{msg} '#{$!}'")
109
- # sleep_for(1)
110
- end
111
-
112
- alias validate_style_lessthan_value validate_style_less_than_value
113
-
114
- # @todo Clarify and rename
115
- def arrays_match?(exp, act, dir, col, org = nil, desc = '')
116
- if exp == act
117
- passed_to_log("Click on #{dir} column '#{col}' produces expected sorted list. #{desc}")
118
- true
119
- else
120
- failed_to_log("Click on #{dir} column '#{col}' fails to produce expected sorted list. #{desc}")
121
- debug_to_log("Original order ['#{org.join("', '")}']") if org
122
- debug_to_log("Expected order ['#{exp.join("', '")}']")
123
- debug_to_log(" Actual order ['#{act.join("', '")}']")
124
- end
125
- end
126
-
127
- alias arrays_match arrays_match?
128
-
129
- # Verify that a DOM element is enabled.
130
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
131
- # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
132
- # Some common values are :link, :button, :image, :div, :span.
133
- # @param [Symbol] how The element attribute used to identify the specific element.
134
- # Valid values depend on the kind of element.
135
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
136
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
137
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
138
- # @return [Boolean] Returns true if the element is enabled.
139
- def enabled?(browser, element, how, what, desc = '')
140
- #TODO: handle identification of element with value as well as other attribute. see exists?
141
- msg = build_message("#{element.to_s.titlecase} by #{how}=>'#{what}' is enabled.}", desc)
142
- case element
143
- when :textfield, :textarea, :text_area, :text_field
144
- rtrn = browser.text_field(how, what).enabled? and not browser.text_field(how, what).readonly?
145
- when :select_list, :selectlist
146
- rtrn = browser.select_list(how, what).enabled?
147
- else
148
- rtrn = browser.element(how, what).enabled?
149
- end
150
- if rtrn
151
- passed_to_log("#{msg}")
152
- true
153
- else
154
- failed_to_log("#{msg}")
155
- end
156
- rtrn
157
- rescue
158
- failed_to_log("#Unable to verify that #{msg}': '#{$!}")
159
- end
160
-
161
- alias validate_enabled enabled?
162
-
163
- # Verify that a DOM element is disabled.
164
- # @param (see #enabled?)
165
- # @return [Boolean] Returns true if the element is disabled.
166
- def disabled?(browser, element, how, what, desc = '')
167
- #TODO: handle identification of element with value as well as other attribute. see exists?
168
- msg = build_message("#{element.to_s.titlecase} by #{how}=>'#{what}' is disabled.", desc)
169
- case element
170
- when :textfield, :textarea, :text_area, :text_field
171
- rtrn = browser.text_field(how, what).disabled? ||
172
- browser.text_field(how, what).readonly?
173
- when :select_list, :selectlist
174
- rtrn = browser.select_list(how, what).disabled?
175
- when :checkbox
176
- rtrn = browser.checkbox(how, what).disabled?
177
- when :radio
178
- rtrn = browser.radio(how, what).disabled?
179
- when :button
180
- rtrn = browser.button(how, what).disabled?
181
- else
182
- rtrn = browser.element(how, what).disabled?
183
- end
184
- if rtrn
185
- passed_to_log("#{msg}")
186
- true
187
- else
188
- failed_to_log("#{msg}")
189
- end
190
- rtrn
191
- rescue
192
- failed_to_log("#Unable to verify that #{msg}: '#{$!}'")
193
- end
194
-
195
- alias validate_not_enabled disabled?
196
- alias validate_disabled disabled?
197
-
198
- # Verify that a DOM element is visible.
199
- # @param (see #enabled?)
200
- # @return [Boolean] Returns true if the element is visible.
201
- def visible?(browser, element, how, what, desc = '')
202
- #TODO: handle identification of element with value as well as other attribute. see exists?
203
- msg = build_message("#{element.to_s.titlecase} #{how}=>'#{what}' is visible.", desc)
204
- rtrn = false
205
- case how
206
- when :index
207
- target = get_element(browser, element, how, what)
208
- if target.visible?
209
- rtrn = true
210
- end
211
- else
212
- if browser.element(how, what).visible?
213
- rtrn = true
214
- end
215
- end
216
- if rtrn
217
- passed_to_log("#{msg}")
218
- else
219
- failed_to_log("#{msg}")
220
- end
221
- rtrn
222
- rescue
223
- failed_to_log("Unable to verify that #{msg}': '#{$!}'")
224
- end
225
-
226
- alias validate_visible visible?
227
-
228
- # Verify that a DOM element is not visible.
229
- # @param (see #enabled?)
230
- # @return [Boolean] Returns true if the element is not visible.
231
- def not_visible?(browser, element, how, what, desc = '')
232
- #TODO: handle identification of element with value as well as other attribute. see exists?
233
- msg = build_message("#{element.to_s.titlecase} #{how}=>'#{what}' is not visible.", desc)
234
- rtrn = false
235
- case how
236
- when :index
237
- target = get_element(browser, element, how, what)
238
- if not target.visible?
239
- rtrn = true
240
- end
241
- else
242
- if not browser.element(how, what).visible?
243
- rtrn = true
244
- end
245
- end
246
- if rtrn
247
- passed_to_log("#{msg}")
248
- else
249
- failed_to_log("#{msg}")
250
- end
251
- rtrn
252
- rescue
253
- failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}")
254
- end
255
-
256
- alias validate_not_visible not_visible?
257
-
258
- # Verify that a checkbox is checked.
259
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
260
- # @param [Symbol] how The element attribute used to identify the specific element.
261
- # Valid values depend on the kind of element.
262
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
263
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
264
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
265
- # @return [Boolean] Returns true if the checkbox is checked.
266
- def checked?(browser, how, what, desc = '')
267
- #TODO: handle identification of element with value as well as other attribute. see exists?
268
- msg = build_message("Checkbox #{how}=>#{what} is checked.", desc)
269
- if browser.checkbox(how, what).checked?
270
- passed_to_log(msg)
271
- true
272
- else
273
- failed_to_log(msg)
274
- end
275
- rescue
276
- failed_to_log("Unable to verify that #{msg}: '#{$!}'")
277
- end
278
-
279
- alias checkbox_checked? checked?
280
- alias checkbox_set? checked?
281
-
282
- # Verify that a checkbox is not checked.
283
- # @param (see #checked?)
284
- # @return [Boolean] Returns true if the checkbox is not checked.
285
- def not_checked?(browser, how, what, desc = '')
286
- #TODO: handle identification of element with value as well as other attribute. see exists?
287
- msg = build_message("Checkbox #{how}=>#{what} is not checked.", desc)
288
- if not browser.checkbox(how, what).checked?
289
- passed_to_log(msg)
290
- true
291
- else
292
- failed_to_log(msg)
293
- end
294
- rescue
295
- failed_to_log("Unable to verify that #{msg}: '#{$!}'")
296
- end
297
-
298
- alias checkbox_checked? checked?
299
- alias checkbox_set? checked?
300
-
301
- # Verify that a DOM element exists on the page.
302
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
303
- # @param [Symbol] how The element attribute used to identify the specific element.
304
- # Valid values depend on the kind of element.
305
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
306
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
307
- # @param [String, Regexp] value A string or a regular expression to be found in the value attribute of the element.
308
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
309
- # @return [Boolean] True if the element exists.
310
- def exists?(browser, element, how, what, value = nil, desc = '')
311
- msg2 = "and value=>'#{value}' " if value
312
- msg = build_message("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'exists.', desc)
313
- case element
314
- when :link
315
- bool = browser.link(how, what).exists?
316
- else
317
- bool = browser.element(how, what).exists?
318
- end
319
- if bool
320
- passed_to_log("#{msg}? #{desc}")
321
- true
322
- else
323
- failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
324
- end
325
- rescue
326
- failed_to_log("Unable to verify that #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
327
- end
328
-
329
- # Verify that a DOM element does not exist on the page.
330
- # @param (see #exists?)
331
- # @return [Boolean] True if the element does not exist.
332
- def does_not_exist?(browser, element, how, what, value = nil, desc = '')
333
- msg2 = "and value=>'#{value}' " if value
334
- msg = build_message("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'does not exist.', desc)
335
- case element
336
- when :link
337
- bool = browser.link(how, what).exists?
338
- else
339
- bool = browser.element(how, what).exists?
340
- end
341
- if bool
342
- failed_to_log(msg)
343
- else
344
- passed_to_log(msg)
345
- true
346
- end
347
- rescue
348
- failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}")
349
- end
350
-
351
- alias not_exist? does_not_exist?
352
-
353
- # Verify that a radio button is set.
354
- # @param (see #checked?)
355
- # @return [Boolean] Returns true if the radio button is set.
356
- def set?(browser, how, what, desc = '', no_fail = false)
357
- #TODO: handle identification of element with value as well as other attribute. see radio_with_value_set?
358
- msg = build_message("Radio #{how}=>#{what} is selected.", desc)
359
- if browser.radio(how, what).set?
360
- passed_to_log(msg)
361
- true
362
- else
363
- if no_fail
364
- passed_to_log("Radio #{how}=>#{what} is not selected.")
365
- else
366
- failed_to_log(msg)
367
- end
368
- end
369
- rescue
370
- failed_to_log("Unable to verify taht #{msg}: '#{$!}'")
371
- end
372
-
373
- alias radio_set? set?
374
- alias radio_checked? set?
375
- alias radio_selected? set?
376
-
377
- # Verify that a radio button is not set.
378
- # @param (see #checked?)
379
- # @return [Boolean] Returns true if the radio button is not set.
380
- def not_set?(browser, how, what, desc = '', no_fail = false)
381
- #TODO: handle identification of element with value as well as other attribute. see radio_with_value_set?
382
- msg = build_message("Radio #{how}=>#{what} is not selected.", desc)
383
- if not browser.radio(how, what).set?
384
- passed_to_log(msg)
385
- true
386
- else
387
- if no_fail
388
- passed_to_log("Radio #{how}=>#{what} is not selected.")
389
- else
390
- failed_to_log(msg)
391
- end
392
- end
393
- rescue
394
- failed_to_log("Unable to verify that #{msg}: '#{$!}'")
395
- end
396
-
397
- alias radio_not_set? not_set?
398
- alias radio_not_checked? not_set?
399
- alias radio_not_selected? not_set?
400
-
401
- # Verify that a radio button, identified by both the value (*what*) in attribute *how*
402
- # and the *value* in its value attribute, is set.
403
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
404
- # @param [Symbol] how The element attribute used to identify the specific element.
405
- # Valid values depend on the kind of element.
406
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
407
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
408
- # @param [String, Regexp] value A string or a regular expression to be found in the value attribute of the element.
409
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
410
- # @return [Boolean] Returns true if the radio button is set.
411
- def radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false)
412
- msg2 = 'not' if no_fail
413
- msg = build_message("Radio #{how}=>#{what} :value=>#{value} is", msg2, 'selected.', desc)
414
- if browser.radio(how, what, value).set?
415
- passed_to_log(msg)
416
- true
417
- else
418
- if no_fail
419
- passed_to_log(msg)
420
- else
421
- failed_to_log(msg)
422
- end
423
- end
424
- rescue
425
- failed_to_log("Unable to verify that #{msg}: '#{$!}'")
426
- end
427
-
428
- alias radio_set_with_value? radio_with_value_set?
429
-
430
- # Verify that a select list, identified by the value (*what*) in attribute *how*, contains an option with the
431
- # value in *option*.
432
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
433
- # @param [Symbol] how The element attribute used to identify the specific element.
434
- # Valid values depend on the kind of element.
435
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
436
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
437
- # @param [String, Regexp] option A string or a regular expression to be found in the value attribute of the element.
438
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
439
- # @return [Boolean] Returns true if the option is found.
440
- def select_list_includes?(browser, how, what, option, desc = '')
441
- msg = build_message("Select list #{how}=>#{what} includes option '#{option}'.", desc)
442
- select_list = browser.select_list(how, what)
443
- options = select_list.options
444
- if option
445
- if options.include?(option)
446
- passed_to_log(msg)
447
- true
448
- else
449
- failed_to_log(msg)
450
- end
451
- end
452
- rescue
453
- failed_to_log("Unable to verify #{msg}. '#{$!}'")
454
- end
455
-
456
- alias validate_select_list_contains select_list_includes?
457
- alias select_list_contains? select_list_includes?
458
-
459
- # Verify that a select list, identified by the value (*what*) in attribute *how*, contains an option with the
460
- # value in *option*.
461
- # @param (see #select_list_includes?)
462
- # @return [Boolean] Returns true if the option is not found.
463
- def select_list_does_not_include?(browser, how, what, option, desc = '')
464
- msg = build_message("Select list #{how}=>#{what} does not include option '#{option}'.", desc)
465
- select_list = browser.select_list(how, what)
466
- options = select_list.options
467
- if option
468
- if not options.include?(option)
469
- passed_to_log(msg)
470
- true
471
- else
472
- failed_to_log(msg)
473
- nil
474
- end
475
- end
476
- rescue
477
- failed_to_log("Unable to verify #{msg}. '#{$!}'")
478
- end
479
-
480
- # Compare strings for exact match and log results
481
- # @param [String] actual The actual value as found in the application.
482
- # @param [String] expected The value expected to be found.
483
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
484
- # @return [Boolean] Returns true if actual exactly matches expected.
485
- def string_equals?(actual, expected, desc = '')
486
- msg = build_message("Actual string '#{actual}' equals expected '#{expected}'.", desc)
487
- if actual == expected
488
- passed_to_log("#{msg}")
489
- true
490
- else
491
- failed_to_log("#{msg}")
492
- end
493
- rescue
494
- failed_to_log("Unable to #{msg}. #{$!}")
495
- end
496
-
497
- alias validate_string_equal string_equals?
498
- alias validate_string_equals string_equals?
499
- alias text_equals string_equals?
500
- alias text_equals? string_equals?
501
-
502
- # Compare strings for no match and log results
503
- # @param (see #string_equals?)
504
- # @return [Boolean] Returns true if actual does not match expected.
505
- def string_does_not_equal?(actual, expected, desc = '')
506
- msg = build_message("Actual string '#{actual}' does not equal expected '#{expected}'.", desc)
507
- if actual == expected
508
- failed_to_log("#{msg} (#{__LINE__})")
509
- true
510
- else
511
- passed_to_log("#{msg} (#{__LINE__})")
512
- end
513
- end
514
-
515
- alias validate_string_not_equal string_does_not_equal?
516
- alias validate_string_does_not_equal string_does_not_equal?
517
-
518
- # Verify that date strings represent the same date, allowing for format differences.
519
- # Compare strings for no match and log results
520
- # @param (see #string_equals?)
521
- # @param [Boolean] fail_on_format If set to true method will fail if the formats differ
522
- # @return [Boolean] Returns true if actual does not match expected.
523
- def date_string_equals?(actual, expected, desc = '', fail_on_format = true)
524
- rtrn = false
525
- if actual == expected
526
- rtrn = true
527
- elsif DateTime.parse(actual).to_s == DateTime.parse(expected).to_s
528
- msg2 "with different formatting. "
529
- unless fail_on_format
530
- rtrn = true
531
- end
532
- end
533
- msg = build_message("Actual date '#{actual}' equals expected date '#{expected}'.", msg2, desc)
534
- if rtrn
535
- passed_to_log("#{msg}")
536
- else
537
- failed_to_log("#{msg}")
538
- end
539
- rtrn
540
- rescue
541
- failed_to_log("Unable to verify that #{msg}. #{$!}")
542
- end
543
-
544
- # Verify that a DOM element is in read-only state.
545
- # @param (see #enabled?)
546
- # @return [Boolean] Returns true if the element is in read-only state.
547
- def read_only?(browser, element, how, what, value = nil, desc = '')
548
- msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
549
- msg << "and value=>'#{value}' " if value
550
- msg << "read only"
551
- e = get_element(browser, element, how, what, value)
552
- if e
553
- if e.readonly?
554
- passed_to_log("#{msg}? #{desc}")
555
- true
556
- else
557
- failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
558
- end
559
- end
560
- rescue
561
- failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
562
- end
563
-
564
- # Verify that a DOM element is not in read-only state.
565
- # @param (see #enabled?)
566
- # @return [Boolean] Returns true if the element is not in read-only state.
567
- def not_read_only?(browser, element, how, what, value = nil, desc = '')
568
- msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
569
- msg << "and value=>'#{value}' " if value
570
- msg << "is not read only"
571
- e = get_element(browser, element, how, what, value)
572
- if e
573
- if e.readonly?
574
- failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
575
- else
576
- passed_to_log("#{msg}? #{desc}")
577
- true
578
- end
579
- end
580
- rescue
581
- failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
582
- end
583
-
584
- # Verify that a DOM element is ready, i.e., both exists and is enabled.
585
- # @param (see #exists?)
586
- # @return [Boolean] Returns true if the element is ready.
587
- def ready?(browser, element, how, what, value = '', desc = '')
588
- msg2 = "and value=>'#{value}' " if value
589
- msg = build_message("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'exists and is enabled.', desc)
590
- e = get_element(browser, element, how, what, value)
591
- if e and e.enabled?
592
- passed_to_log(msg)
593
- true
594
- else
595
- failed_to_log(msg)
596
- end
597
- rescue
598
- failed_to_log("Unable to determine if #{msg}. '#{$!}' [#{get_callers(1)}]")
599
- end
600
-
601
- # Verify that a text field (also text area), identified by *how* and *what*, contains only the exact string specified in *expected*.
602
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
603
- # @param [Symbol] how The element attribute used to identify the specific element.
604
- # Valid values depend on the kind of element.
605
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
606
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
607
- # @param [String] expected A string which the value attribute of the text field must equal.
608
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
609
- # @return [Boolean] Returns true if the *expected* and the value in the text field are identical.
610
- def textfield_equals?(browser, how, what, expected, desc = '')
611
- msg = build_message("Expected value to equal '#{expected}' in textfield #{how}=>'#{what}'.", desc)
612
- actual = browser.text_field(how, what).value
613
- if actual.is_a?(Array)
614
- actual = actual[0].to_s
615
- end
616
- if actual == expected
617
- passed_to_log(msg)
618
- true
619
- else
620
- act_s = actual.strip
621
- exp_s = expected.strip
622
- if act_s == exp_s
623
- passed_to_log("#{msg} (stripped)")
624
- true
625
- else
626
- debug_to_report(
627
- "#{__method__} (spaces underscored):\n "+
628
- "expected:[#{expected.gsub(' ', '_')}] (#{expected.length})\n "+
629
- "actual:[#{actual.gsub(' ', '_')}] (#{actual.length}) (spaces underscored)"
630
- )
631
- failed_to_log("#{msg}. Found: '#{actual}'")
632
- end
633
- end
634
- rescue
635
- failed_to_log("Unable to verify that #{msg}: '#{$!}")
636
- end
637
-
638
- alias validate_textfield_value textfield_equals?
639
- alias text_field_equals? textfield_equals?
640
-
641
- # Verify that a text field (also text area), identified by *how* and *what*, contains the string specified in *expected*.
642
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
643
- # @param [Symbol] how The element attribute used to identify the specific element.
644
- # Valid values depend on the kind of element.
645
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
646
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
647
- # @param [String, Regexp] expected A string or regular expression which must be matched in the value of the text field
648
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
649
- # @return [Boolean] Returns true if the *expected* is matched in the value of the text field.
650
- def textfield_contains?(browser, how, what, expected, desc = '')
651
- msg = build_message("Text field #{how}=>#{what} contains '#{expected}'.", desc)
652
- contents = browser.text_field(how, what).value
653
- if contents =~ /#{expected}/
654
- passed_to_log(msg)
655
- true
656
- else
657
- failed_to_log("#{msg} Contents: '#{contents}'")
658
- end
659
- rescue
660
- failed_to_log("Unable to verify that #{msg} '#{$!}'")
661
- end
662
-
663
- # Verify that a text field (also text area), identified by *how* and *what*, is empty.
664
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
665
- # @param [Symbol] how The element attribute used to identify the specific element.
666
- # Valid values depend on the kind of element.
667
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
668
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
669
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
670
- # @return [Boolean] Returns true if the text field is empty.
671
- def textfield_empty?(browser, how, what, desc = '')
672
- msg = "Text field #{how}=>#{what} is empty."
673
- msg << desc if desc.length > 0
674
- contents = browser.text_field(how, what).value
675
- if contents.to_s.length == 0
676
- passed_to_log(msg)
677
- true
678
- else
679
- failed_to_log("#{msg} Contents: '#{contents}'")
680
- end
681
- rescue
682
- failed_to_log("Unable to verify that #{msg} '#{$!}'")
683
- end
684
-
685
- alias validate_textfield_empty textfield_empty?
686
- alias text_field_empty? textfield_empty?
687
-
688
- # Verify that a text field (also text area), identified by *how* and *what*, contains the string specified in *expected*.
689
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
690
- # @param [Symbol] how The element attribute used to identify the specific element.
691
- # Valid values depend on the kind of element.
692
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
693
- # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
694
- # @param [String] expected A string in dollar formatting
695
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
696
- # @return [Boolean] Returns true if the *expected* is matched in the value of the text field.
697
- def validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '')
698
- target = expected.dup
699
- desc << " Dollar formatting"
700
- if with_cents
701
- target << '.00' if not expected =~ /\.00$/
702
- desc << " without cents. orig:(#{expected})"
703
- else
704
- target.gsub!(/\.00$/, '')
705
- desc << " with cents. orig:(#{expected})"
706
- end
707
- textfield_equals?(browser, how, what, target, desc)
708
- end
709
-
710
- # Verify that *browser* is set to a url that is matched by the string or rexexp in *url*.
711
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
712
- # @param [String, Regexp] url A string or a regular expression to match to the url of the browser..
713
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
714
- # @return [Boolean] Returns true if the *expected* is matched in the value of the text field.
715
- def validate_url(browser, url, desc = '')
716
- msg = build_message("Current URL matches #{url}.", desc)
717
- if browser.url.to_s.match(url)
718
- passed_to_log(msg)
719
- true
720
- else
721
- failed_to_log("#{msg} Actual: #{browser.url}")
722
- end
723
- rescue
724
- failed_to_log("Unable to validate that #{msg} '#{$!}'")
725
- end
726
-
727
- # @!endgroup Core
728
-
729
- # @!group AutoIT
730
-
731
- def window_exists?(title)
732
- title = translate_popup_title(title)
733
- if @ai.WinExists(title) == 1
734
- passed_to_log("Window title:'#{title}' exists")
735
- true
736
- else
737
- failed_to_log("Window title:'#{title}' does not exist")
738
- end
739
- end
740
-
741
- alias window_exists window_exists?
742
-
743
- def window_does_not_exist?(title)
744
- title = translate_popup_title(title)
745
- if @ai.WinExists(title) == 1
746
- failed_to_log("Window title:'#{title}' exists")
747
- else
748
- passed_to_log("Window title:'#{title}' does not exist")
749
- true
750
- end
751
- end
752
-
753
- alias window_no_exists window_does_not_exist?
754
-
755
- # @!endgroup AutoIT
756
-
757
- # @!group Core
758
-
759
- def popup_is_browser?(popup, desc = '')
760
- msg = build_message("Popup: #{popup.title} is a browser window.", desc)
761
- if is_browser?(popup)
762
- passed_to_log(msg)
763
- debug_to_log("\n"+popup.text+"\n")
764
- true
765
- else
766
- failed_to_log(msg)
767
- end
768
- rescue
769
- failed_to_log("Unable to verify that #{msg}: '#{$!}'. (#{__LINE__})")
770
- end
771
-
772
- alias popup_exist popup_is_browser?
773
- alias popup_exists popup_is_browser?
774
- alias popup_exist? popup_is_browser?
775
- alias popup_exists? popup_is_browser?
776
- alias iepopup_exist popup_is_browser?
777
- alias iepopup_exist? popup_is_browser?
778
- alias iepopup_exists popup_is_browser?
779
- alias iepopup_exists? popup_is_browser?
780
-
781
- # Verify that select list, identified by the value *what* in the attribute :id, contains text and select it if present.
782
- def validate_list_by_id(browser, what, option, desc = '', select_if_present = true)
783
- if select_list_includes?(browser, :id, what, option, desc)
784
- if select_if_present
785
- select_option(browser, :id, what, :text, option, desc, false)
786
- else
787
- passed_to_log(message)
788
- true
789
- end
790
- end
791
- end
792
-
793
- # Verify that select list contains text
794
- def validate_list_by_name(browser, what, option, desc = '', select_if_present = true)
795
- if select_list_includes?(browser, :name, what, option, desc)
796
- if select_if_present
797
- select_option(browser, :name, what, :text, option, desc, false)
798
- else
799
- passed_to_log(message)
800
- true
801
- end
802
- end
803
- end
804
-
805
- def validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false)
806
- cls = browser.class.to_s
807
- cls.gsub!('Watir::', '')
808
- cls.gsub!('IE', 'Browser')
809
- msg = build_message("#{cls} text contains '#{ptrn}'.", desc)
810
- if ptrn.is_a?(Regexp)
811
- target = ptrn
812
- else
813
- target = Regexp.new(Regexp.escape(ptrn))
814
- end
815
- sleep_for(2) unless skip_sleep
816
- myText = browser.text
817
- if not myText.match(target)
818
- sleep_for(2) unless skip_sleep #TODO try a wait_until here?
819
- myText = browser.text
820
- end
821
- if myText.match(target)
822
- #if myText.match(ptrn)
823
- passed_to_log("#{msg}")
824
- true
825
- else
826
- if skip_fail
827
- debug_to_log("#{cls} text does not contain the text: '#{ptrn}'. #{desc}")
828
- else
829
- failed_to_log("#{msg}")
830
- end
831
- #debug_to_log("\n#{myText}")
832
- end
833
- rescue
834
- failed_to_log("Unable to verify that #{msg} '#{$!}'")
835
- end
836
-
837
- alias validate_link validate_text
838
-
839
- def text_in_element_equals?(browser, element, how, what, expected, desc = '')
840
- msg = build_message("Expected exact text '#{expected}' in #{element} :#{how}=>#{what}.", desc)
841
- text = ''
842
- who = browser.element(how, what)
843
- if who
844
- text = who.text
845
- if text == expected
846
- passed_to_log(msg)
847
- true
848
- else
849
- debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
850
- debug_to_log("act: [#{text.gsub(' ', '^')}]")
851
- failed_to_log("#{msg} Found '#{text}'.")
852
- end
853
- end
854
- rescue
855
- failed_to_log("Unable to verify #{msg} '#{$!}'")
856
- end
857
-
858
- def element_contains_text?(browser, element, how, what, expected, desc = '')
859
- msg = build_message("Element #{element} :{how}=>#{what} contains text '#{expected}'.", desc)
860
- case how
861
- when :href
862
- who = browser.element(how, what)
863
- else
864
- who = browser.link(how, what)
865
- end
866
- if who
867
- text = who.text
868
- if expected and expected.length > 0
869
- rgx = Regexp.new(Regexp.escape(expected))
870
- if text =~ rgx
871
- passed_to_log(msg)
872
- true
873
- else
874
- debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
875
- debug_to_log("act: [#{text.gsub(' ', '^')}]")
876
- failed_to_log("#{msg} Found '#{text}'. #{desc}")
877
- end
878
- else
879
- if text.length > 0
880
- debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
881
- debug_to_log("act: [#{text.gsub(' ', '^')}]")
882
- failed_to_log("#{msg} Found '#{text}'. #{desc}")
883
- else
884
- passed_to_log(msg)
885
- true
886
- end
887
- end
888
- end
889
- rescue
890
- failed_to_log("Unable to verify #{msg} '#{$!}'")
891
- end
892
-
893
- def validate_select_list(browser, how, what, opt_type, list = nil, multiple = false, ignore = ['Select One'], limit = 5)
894
- mark_testlevel("#{__method__.to_s.titleize} (#{how}=>#{what})", 0)
895
- ok = true
896
- select_list = browser.select_list(how, what)
897
- options = select_list.options
898
- if list
899
- if options == list
900
- passed_to_log("Select list options list equals expected list #{list}")
901
- else
902
- debug_to_report("actual:\n#{nice_array(options, true)}")
903
- debug_to_report("expected:\n#{nice_array(list, true)}")
904
- failed_to_log("Select list options list #{nice_array(options, true)} "+
905
- "does not equal expected list #{nice_array(list, true)}")
906
- end
907
- end
908
-
909
- #single selections
910
- cnt = 0
911
- options.each do |opt|
912
- if not ignore.include?(opt)
913
- cnt += 1
914
- ok = select_option(select_list, opt_type, opt)
915
- break if not ok
916
- select_list.clear
917
- break if limit > 0 and cnt >= limit
918
- end
919
- end
920
-
921
- sleep_for(0.5)
922
- select_list.clear
923
- if ok and multiple
924
- if options.length > 2
925
- targets = list.slice(1, 2)
926
- select_option(select_list, opt_type, options[1])
927
- select_option(select_list, opt_type, options[2])
928
- selected = select_list.selected_options
929
- if selected == targets
930
- passed_to_log("Select list selected options equals expected #{targets}")
931
- else
932
- failed_to_log("Select list selected options #{selected} does not equal expected list #{targets.to_a}")
933
- end
934
- else
935
- debug_to_log("Too few options to test multiple selection (need 2 or more): '#{options}", __LINE__)
936
- end
937
- end
938
- rescue
939
- failed_to_log("Unable to validate select_list: '#{$!}'", __LINE__)
940
- end
941
-
942
- def validate_select_list_contents(browser, how, what, list)
943
- mark_testlevel("#{__method__.to_s.titleize} (#{what})", 2)
944
- select_list = browser.select_list(how, what)
945
- options = select_list.options
946
- if list
947
- if options == list
948
- passed_to_log("Select list options list equals expected list #{list}")
949
- options
950
- else
951
- failed_to_log("Select list options list #{options} does not equal expected list #{list}")
952
- nil
953
- end
954
- end
955
- rescue
956
- failed_to_log("Unable to validate select_list contents: '#{$!}'", __LINE__)
957
- end
958
-
959
- def validate_selected_options(browser, how, what, list, desc = '')
960
- select_list = browser.select_list(how, what)
961
- selected = select_list.selected_options.sort
962
- if list.is_a?(Array)
963
- if selected == list.sort
964
- passed_to_log("Expected options [#{list.sort}] are selected [#{selected}]. #{desc}")
965
- else
966
- failed_to_log("Selected options [#{selected}] do not match expected [#{list.sort}]. #{desc}")
967
- true
968
- end
969
- else
970
- if selected.length == 1
971
- if selected[0] =~ /#{list}/
972
- passed_to_log("Expected option [#{list}] was selected. #{desc}")
973
- true
974
- else
975
- failed_to_log("Expected option [#{list}] was not selected. Found [#{selected}]. #{desc}")
976
- end
977
- else
978
- if selected.include?(list)
979
- failed_to_log("Expected option [#{list}] was found among multiple selections [#{selected}]. #{desc}")
980
- else
981
- failed_to_log("Expected option [#{list}] was not found among multiple selections [#{selected}]. #{desc}")
982
- end
983
- end
984
- end
985
-
986
- rescue
987
- failed_to_log("Unable to validate selected option(s): '#{$!}' #{desc}", __LINE__)
988
- end
989
-
990
- alias validate_selections validate_selected_options
991
- alias validate_select_list_selections validate_selected_options
992
-
993
- def string_contains?(strg, target, desc = '')
994
- msg = build_message("String '#{strg}' contains '#{target}'.", desc)
995
- if strg.match(target)
996
- passed_to_log("#{msg} (#{__LINE__})")
997
- true
998
- else
999
- failed_to_log("#{msg} (#{__LINE__})")
1000
- end
1001
- end
1002
-
1003
- alias validate_string string_contains?
1004
- alias validate_string_contains string_contains?
1005
-
1006
- def string_does_not_contain?(strg, target, desc = '')
1007
- msg = build_message("String '#{strg}' does not contain '#{target}'.", desc)
1008
- if strg.match(target)
1009
- failed_to_log("#{msg} (#{__LINE__})")
1010
- true
1011
- else
1012
- passed_to_log("#{msg} (#{__LINE__})")
1013
- end
1014
- end
1015
-
1016
- alias validate_string_not_contains string_does_not_contain?
1017
- alias validate_string_not_contain string_does_not_contain?
1018
- alias validate_string_does_not_contain string_does_not_contain?
1019
-
1020
- def validate_no_text(browser, ptrn, desc = '')
1021
- cls = browser.class.to_s
1022
- cls.gsub!('Watir::', '')
1023
- cls.gsub!('IE', 'Browser')
1024
- msg = "#{cls} does not contain text '#{ptrn}'."
1025
- msg << " #{desc}" if desc.length > 0
1026
- if ptrn.is_a?(Regexp)
1027
- target = ptrn
1028
- else
1029
- target = Regexp.new(Regexp.escape(ptrn))
1030
- end
1031
- browser_text = browser.text
1032
- if browser_text.match(target)
1033
- failed_to_log("#{msg} [#{browser_text.match(target)[0]}]")
1034
- else
1035
- passed_to_log(msg)
1036
- true
1037
- end
1038
- rescue
1039
- failed_to_log("Unable to verify that #{msg}: '#{$!}'")
1040
- end
1041
-
1042
- def textfield_does_not_equal?(browser, how, what, expected, desc = '')
1043
- msg = build_message("Text field #{how}=>#{what} does not equal '#{expected}'", desc)
1044
- if not browser.text_field(how, what).value == expected
1045
- passed_to_log(msg)
1046
- true
1047
- else
1048
- failed_to_log(msg)
1049
- end
1050
- rescue
1051
- failed_to_log("Unable to validate that #{msg}: '#{$!}'")
1052
- end
1053
-
1054
- alias validate_textfield_not_value textfield_does_not_equal?
1055
-
1056
- # @!endgroup Core
1057
-
1058
- # @!group Deprecated
1059
- # @deprecated
1060
- def self.included(mod)
1061
- # puts "RegressionSupport::Validations extended by #{mod}"
1062
- end
1063
-
1064
- # @deprecated Use #message_to_log
1065
- def validate_message(browser, message)
1066
- message_to_log(message)
1067
- end
1068
-
1069
- # @!endgroup Deprecated
1070
-
1071
- end
1072
- end
1073
- end
1074
-
1
+ module Awetestlib
2
+ module Regression
3
+ # Contains methods to verify content, accessibility, or appearance of page elements.
4
+ module Validations
5
+
6
+ # @!group Core
7
+
8
+ # Verify that element style attribute contains expected value in style *type*.
9
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
10
+ # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
11
+ # Some common values are :link, :button, :image, :div, :span.
12
+ # @param [Symbol] how The element attribute used to identify the specific element.
13
+ # Valid values depend on the kind of element.
14
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
15
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
16
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
17
+ # @param [String] type The name of the style type (sub-attribute) where *expected* is to be found.
18
+ # @param [String] expected The value in *type* expected.
19
+ # @return [Boolean] True if the style type contains the expected value
20
+ #
21
+ def validate_style_value(browser, element, how, what, type, expected, desc = '')
22
+ #TODO: works only with watir-webdriver
23
+ msg = build_message("Expected Style #{type} value '#{expected}' in #{element} with #{how} = #{what}", desc)
24
+ case element
25
+ when :link
26
+ actual = browser.link(how, what).style type
27
+ when :button
28
+ actual = browser.button(how, what).style type
29
+ when :image
30
+ actual = browser.image(how, what).style type
31
+ when :span
32
+ actual = browser.span(how, what).style type
33
+ when :div
34
+ actual = browser.div(how, what).style type
35
+ else
36
+ if browser.element(how, what).responds_to?("style")
37
+ actual = browser.element(how, what).style type
38
+ else
39
+ failed_to_log("#{msg}: Element #{element} does not repond to style command.")
40
+ end
41
+ end
42
+ if expected == actual
43
+ passed_to_log(msg)
44
+ true
45
+ else
46
+ failed_to_log(msg)
47
+ end
48
+ rescue
49
+ failed_to_log(unable_to(msg, false, true))
50
+ end
51
+
52
+ def validate_style_greater_than_value(browser, element, how, what, type, value, desc = '')
53
+ case element
54
+ when :link
55
+ actual_value = browser.link(how, what).style type
56
+ when :button
57
+ actual_value = browser.button(how, what).style type
58
+ when :image
59
+ actual_value = browser.image(how, what).style type
60
+ when :span
61
+ actual_value = browser.span(how, what).style type
62
+ when :div
63
+ actual_value = browser.div(how, what).style type
64
+ else
65
+ actual_value = browser.element(how, what).style type
66
+ end
67
+ msg = build_message("The CSS value for style #{type} in #{element} :#{how}=>#{what}: '#{actual_value}' is greater than #{value}.", desc)
68
+
69
+ if actual_value.to_i > value.to_i
70
+ passed_to_log(msg)
71
+ elsif actual_value.to_i >~ value.to_i
72
+ passed_to_log(msg)
73
+ else
74
+ failed_to_log(msg)
75
+ end
76
+ rescue
77
+ failed_to_log(unable_to(msg, false, true))
78
+ # sleep_for(1)
79
+ end
80
+
81
+ alias validate_style_greaterthan_value validate_style_greater_than_value
82
+
83
+ def validate_style_less_than_value(browser, element, how, what, type, value, desc = '')
84
+ case element
85
+ when :link
86
+ actual_value = browser.link(how, what).style type
87
+ when :button
88
+ actual_value = browser.button(how, what).style type
89
+ when :image
90
+ actual_value = browser.image(how, what).style type
91
+ when :span
92
+ actual_value = browser.span(how, what).style type
93
+ when :div
94
+ actual_value = browser.div(how, what).style type
95
+ else
96
+ actual_value = browser.element(how, what).style type
97
+ end
98
+ msg = build_message("The CSS value for style #{type} in #{element} :#{how}=>#{what}: '#{actual_value}' is greater than #{value}.", desc)
99
+
100
+ if actual_value.to_i < value.to_i
101
+ passed_to_log(msg)
102
+ elsif actual_value.to_i <~ value.to_i
103
+ passed_to_log(msg)
104
+ else
105
+ failed_to_log(msg)
106
+ end
107
+ rescue
108
+ failed_to_log(unable_to(msg, false, true))
109
+ # sleep_for(1)
110
+ end
111
+
112
+ alias validate_style_lessthan_value validate_style_less_than_value
113
+
114
+ # @todo Clarify and rename
115
+ def arrays_match?(exp, act, dir, col, org = nil, desc = '')
116
+ if exp == act
117
+ passed_to_log("Click on #{dir} column '#{col}' produces expected sorted list. #{desc}")
118
+ true
119
+ else
120
+ failed_to_log("Click on #{dir} column '#{col}' fails to produce expected sorted list. #{desc}")
121
+ debug_to_log("Original order ['#{org.join("', '")}']") if org
122
+ debug_to_log("Expected order ['#{exp.join("', '")}']")
123
+ debug_to_log(" Actual order ['#{act.join("', '")}']")
124
+ end
125
+ end
126
+
127
+ alias arrays_match arrays_match?
128
+
129
+ # Verify that a DOM element is enabled.
130
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
131
+ # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
132
+ # Some common values are :link, :button, :image, :div, :span.
133
+ # @param [Symbol] how The element attribute used to identify the specific element.
134
+ # Valid values depend on the kind of element.
135
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
136
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
137
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
138
+ # @return [Boolean] Returns true if the element is enabled.
139
+ def enabled?(browser, element, how, what, desc = '')
140
+ #TODO: handle identification of element with value as well as other attribute. see exists?
141
+ msg = build_message("#{element.to_s.titlecase} by #{how}=>'#{what}' is enabled.}", desc)
142
+ case element
143
+ when :textfield, :textarea, :text_area, :text_field
144
+ rtrn = browser.text_field(how, what).enabled? and not browser.text_field(how, what).readonly?
145
+ when :select_list, :selectlist
146
+ rtrn = browser.select_list(how, what).enabled?
147
+ else
148
+ rtrn = browser.element(how, what).enabled?
149
+ end
150
+ if rtrn
151
+ passed_to_log("#{msg}")
152
+ true
153
+ else
154
+ failed_to_log("#{msg}")
155
+ end
156
+ rtrn
157
+ rescue
158
+ failed_to_log(unable_to(msg, false, true))
159
+ end
160
+
161
+ alias validate_enabled enabled?
162
+
163
+ # Verify that a DOM element is disabled.
164
+ # @param (see #enabled?)
165
+ # @return [Boolean] Returns true if the element is disabled.
166
+ def disabled?(browser, element, how, what, desc = '')
167
+ #TODO: handle identification of element with value as well as other attribute. see exists?
168
+ msg = build_message("#{element.to_s.titlecase} by #{how}=>'#{what}' is disabled.", desc)
169
+ case element
170
+ when :textfield, :textarea, :text_area, :text_field
171
+ rtrn = browser.text_field(how, what).disabled? ||
172
+ browser.text_field(how, what).readonly?
173
+ when :select_list, :selectlist
174
+ rtrn = browser.select_list(how, what).disabled?
175
+ when :checkbox
176
+ rtrn = browser.checkbox(how, what).disabled?
177
+ when :radio
178
+ rtrn = browser.radio(how, what).disabled?
179
+ when :button
180
+ rtrn = browser.button(how, what).disabled?
181
+ else
182
+ rtrn = browser.element(how, what).disabled?
183
+ end
184
+ if rtrn
185
+ passed_to_log("#{msg}")
186
+ true
187
+ else
188
+ failed_to_log("#{msg}")
189
+ end
190
+ rtrn
191
+ rescue
192
+ failed_to_log(unable_to(msg, false, true))
193
+ end
194
+
195
+ alias validate_not_enabled disabled?
196
+ alias validate_disabled disabled?
197
+
198
+ # Verify that a DOM element is visible.
199
+ # @param (see #enabled?)
200
+ # @return [Boolean] Returns true if the element is visible.
201
+ def visible?(browser, element, how, what, desc = '')
202
+ #TODO: handle identification of element with value as well as other attribute. see exists?
203
+ msg = build_message("#{element.to_s.titlecase} #{how}=>'#{what}' is visible.", desc)
204
+ rtrn = false
205
+ case how
206
+ when :index
207
+ target = get_element(browser, element, how, what)
208
+ if target.visible?
209
+ rtrn = true
210
+ end
211
+ else
212
+ if browser.element(how, what).visible?
213
+ rtrn = true
214
+ end
215
+ end
216
+ if rtrn
217
+ passed_to_log("#{msg}")
218
+ else
219
+ failed_to_log("#{msg}")
220
+ end
221
+ rtrn
222
+ rescue
223
+ failed_to_log(unable_to(msg, false, true))
224
+ end
225
+
226
+ alias validate_visible visible?
227
+
228
+ # Verify that a DOM element is not visible.
229
+ # @param (see #enabled?)
230
+ # @return [Boolean] Returns true if the element is not visible.
231
+ def not_visible?(browser, element, how, what, desc = '')
232
+ #TODO: handle identification of element with value as well as other attribute. see exists?
233
+ msg = build_message("#{element.to_s.titlecase} #{how}=>'#{what}' is not visible.", desc)
234
+ rtrn = false
235
+ case how
236
+ when :index
237
+ target = get_element(browser, element, how, what)
238
+ if not target.visible?
239
+ rtrn = true
240
+ end
241
+ else
242
+ if not browser.element(how, what).visible?
243
+ rtrn = true
244
+ end
245
+ end
246
+ if rtrn
247
+ passed_to_log("#{msg}")
248
+ else
249
+ failed_to_log("#{msg}")
250
+ end
251
+ rtrn
252
+ rescue
253
+ failed_to_log(unable_to(msg, false, true))
254
+ end
255
+
256
+ alias validate_not_visible not_visible?
257
+
258
+ # Verify that a checkbox is checked.
259
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
260
+ # @param [Symbol] how The element attribute used to identify the specific element.
261
+ # Valid values depend on the kind of element.
262
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
263
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
264
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
265
+ # @return [Boolean] Returns true if the checkbox is checked.
266
+ def checked?(browser, how, what, desc = '')
267
+ #TODO: handle identification of element with value as well as other attribute. see exists?
268
+ msg = build_message("Checkbox #{how}=>#{what} is checked.", desc)
269
+ if browser.checkbox(how, what).checked?
270
+ passed_to_log(msg)
271
+ true
272
+ else
273
+ failed_to_log(msg)
274
+ end
275
+ rescue
276
+ failed_to_log(unable_to(msg, false, true))
277
+ end
278
+
279
+ alias checkbox_checked? checked?
280
+ alias checkbox_set? checked?
281
+
282
+ # Verify that a checkbox is not checked.
283
+ # @param (see #checked?)
284
+ # @return [Boolean] Returns true if the checkbox is not checked.
285
+ def not_checked?(browser, how, what, desc = '')
286
+ #TODO: handle identification of element with value as well as other attribute. see exists?
287
+ msg = build_message("Checkbox #{how}=>#{what} is not checked.", desc)
288
+ if not browser.checkbox(how, what).checked?
289
+ passed_to_log(msg)
290
+ true
291
+ else
292
+ failed_to_log(msg)
293
+ end
294
+ rescue
295
+ failed_to_log(unable_to(msg, false, true))
296
+ end
297
+
298
+ alias checkbox_checked? checked?
299
+ alias checkbox_set? checked?
300
+
301
+ # Verify that a DOM element exists on the page.
302
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
303
+ # @param [Symbol] how The element attribute used to identify the specific element.
304
+ # Valid values depend on the kind of element.
305
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
306
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
307
+ # @param [String, Regexp] value A string or a regular expression to be found in the value attribute of the element.
308
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
309
+ # @return [Boolean] True if the element exists.
310
+ def exists?(browser, element, how, what, value = nil, desc = '')
311
+ msg2 = "and value=>'#{value}' " if value
312
+ msg = build_message("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'exists.', desc)
313
+ case element
314
+ when :link
315
+ bool = browser.link(how, what).exists?
316
+ else
317
+ bool = browser.element(how, what).exists?
318
+ end
319
+ if bool
320
+ passed_to_log("#{msg}? #{desc}")
321
+ true
322
+ else
323
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
324
+ end
325
+ rescue
326
+ failed_to_log(unable_to(msg, false, true))
327
+ end
328
+
329
+ # Verify that a DOM element does not exist on the page.
330
+ # @param (see #exists?)
331
+ # @return [Boolean] True if the element does not exist.
332
+ def does_not_exist?(browser, element, how, what, value = nil, desc = '')
333
+ msg2 = "and value=>'#{value}' " if value
334
+ msg = build_message("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'does not exist.', desc)
335
+ case element
336
+ when :link
337
+ bool = browser.link(how, what).exists?
338
+ else
339
+ bool = browser.element(how, what).exists?
340
+ end
341
+ if bool
342
+ failed_to_log(msg)
343
+ else
344
+ passed_to_log(msg)
345
+ true
346
+ end
347
+ rescue
348
+ failed_to_log(unable_to(msg, false, true))
349
+ end
350
+
351
+ alias not_exist? does_not_exist?
352
+
353
+ # Verify that a radio button is set.
354
+ # @param (see #checked?)
355
+ # @return [Boolean] Returns true if the radio button is set.
356
+ def set?(browser, how, what, desc = '', no_fail = false)
357
+ #TODO: handle identification of element with value as well as other attribute. see radio_with_value_set?
358
+ msg = build_message("Radio #{how}=>#{what} is set.", desc)
359
+ if browser.radio(how, what).set?
360
+ passed_to_log(msg)
361
+ true
362
+ else
363
+ if no_fail
364
+ passed_to_log("#{msg}. (Fail suppressed)")
365
+ else
366
+ failed_to_log(msg)
367
+ end
368
+ end
369
+ rescue
370
+ failed_to_log(unable_to(msg, false, true))
371
+ end
372
+
373
+ alias radio_set? set?
374
+ alias radio_checked? set?
375
+ alias radio_selected? set?
376
+
377
+ # Verify that a radio button is not set.
378
+ # @param (see #checked?)
379
+ # @return [Boolean] Returns true if the radio button is not set.
380
+ def not_set?(browser, how, what, desc = '', no_fail = false)
381
+ #TODO: handle identification of element with value as well as other attribute. see radio_with_value_set?
382
+ msg = build_message("Radio #{how}=>#{what} is not set.", desc)
383
+ if not browser.radio(how, what).set?
384
+ passed_to_log(msg)
385
+ true
386
+ else
387
+ if no_fail
388
+ passed_to_log("#{msg} (Fail suppressed")
389
+ else
390
+ failed_to_log(msg)
391
+ end
392
+ end
393
+ rescue
394
+ failed_to_log(unable_to(msg, false, true))
395
+ end
396
+
397
+ alias radio_not_set? not_set?
398
+ alias radio_not_checked? not_set?
399
+ alias radio_not_selected? not_set?
400
+
401
+ # Verify that a radio button, identified by both the value (*what*) in attribute *how*
402
+ # and the *value* in its value attribute, is set.
403
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
404
+ # @param [Symbol] how The element attribute used to identify the specific element.
405
+ # Valid values depend on the kind of element.
406
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
407
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
408
+ # @param [String, Regexp] value A string or a regular expression to be found in the value attribute of the element.
409
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
410
+ # @return [Boolean] Returns true if the radio button is set.
411
+ def radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false)
412
+ msg2 = 'not' if no_fail
413
+ msg = build_message("Radio #{how}=>#{what} :value=>#{value} is", msg2, 'selected.', desc)
414
+ if browser.radio(how, what, value).set?
415
+ passed_to_log(msg)
416
+ true
417
+ else
418
+ if no_fail
419
+ passed_to_log(msg)
420
+ else
421
+ failed_to_log(msg)
422
+ end
423
+ end
424
+ rescue
425
+ failed_to_log("Unable to verify that #{msg}: '#{$!}'")
426
+ end
427
+
428
+ alias radio_set_with_value? radio_with_value_set?
429
+
430
+ # Verify that a select list, identified by the value (*what*) in attribute *how*, contains an option with the
431
+ # value in *option*.
432
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
433
+ # @param [Symbol] how The element attribute used to identify the specific element.
434
+ # Valid values depend on the kind of element.
435
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
436
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
437
+ # @param [String, Regexp] option A string or a regular expression to be found in the value attribute of the element.
438
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
439
+ # @return [Boolean] Returns true if the option is found.
440
+ def select_list_includes?(browser, how, what, option, desc = '')
441
+ msg = build_message("Select list #{how}=>#{what} includes option '#{option}'.", desc)
442
+ select_list = browser.select_list(how, what)
443
+ options = select_list.options
444
+ if option
445
+ if options.include?(option)
446
+ passed_to_log(msg)
447
+ true
448
+ else
449
+ failed_to_log(msg)
450
+ end
451
+ end
452
+ rescue
453
+ failed_to_log("Unable to verify #{msg}. '#{$!}'")
454
+ end
455
+
456
+ alias validate_select_list_contains select_list_includes?
457
+ alias select_list_contains? select_list_includes?
458
+
459
+ # Verify that a select list, identified by the value (*what*) in attribute *how*, contains an option with the
460
+ # value in *option*.
461
+ # @param (see #select_list_includes?)
462
+ # @return [Boolean] Returns true if the option is not found.
463
+ def select_list_does_not_include?(browser, how, what, option, desc = '')
464
+ msg = build_message("Select list #{how}=>#{what} does not include option '#{option}'.", desc)
465
+ select_list = browser.select_list(how, what)
466
+ options = select_list.options
467
+ if option
468
+ if not options.include?(option)
469
+ passed_to_log(msg)
470
+ true
471
+ else
472
+ failed_to_log(msg)
473
+ nil
474
+ end
475
+ end
476
+ rescue
477
+ failed_to_log("Unable to verify #{msg}. '#{$!}'")
478
+ end
479
+
480
+ # Compare strings for exact match and log results
481
+ # @param [String] actual The actual value as found in the application.
482
+ # @param [String] expected The value expected to be found.
483
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
484
+ # @return [Boolean] Returns true if actual exactly matches expected.
485
+ def string_equals?(actual, expected, desc = '')
486
+ msg = build_message("Actual string '#{actual}' equals expected '#{expected}'.", desc)
487
+ if actual == expected
488
+ passed_to_log("#{msg}")
489
+ true
490
+ else
491
+ failed_to_log("#{msg}")
492
+ end
493
+ rescue
494
+ failed_to_log("Unable to verify #{msg}. #{$!}")
495
+ end
496
+
497
+ alias validate_string_equal string_equals?
498
+ alias validate_string_equals string_equals?
499
+ alias text_equals string_equals?
500
+ alias text_equals? string_equals?
501
+
502
+ # Compare strings for no match and log results
503
+ # @param (see #string_equals?)
504
+ # @return [Boolean] Returns true if actual does not match expected.
505
+ def string_does_not_equal?(actual, expected, desc = '')
506
+ msg = build_message("Actual string '#{actual}' does not equal expected '#{expected}'.", desc)
507
+ if actual == expected
508
+ failed_to_log("#{msg} (#{__LINE__})")
509
+ true
510
+ else
511
+ passed_to_log("#{msg} (#{__LINE__})")
512
+ end
513
+ end
514
+
515
+ alias validate_string_not_equal string_does_not_equal?
516
+ alias validate_string_does_not_equal string_does_not_equal?
517
+
518
+ # Verify that date strings represent the same date, allowing for format differences.
519
+ # Compare strings for no match and log results
520
+ # @param (see #string_equals?)
521
+ # @param [Boolean] fail_on_format If set to true method will fail if the formats differ
522
+ # @return [Boolean] Returns true if actual does not match expected.
523
+ def date_string_equals?(actual, expected, desc = '', fail_on_format = true)
524
+ rtrn = false
525
+ if actual == expected
526
+ rtrn = true
527
+ elsif DateTime.parse(actual).to_s == DateTime.parse(expected).to_s
528
+ msg2 "with different formatting. "
529
+ unless fail_on_format
530
+ rtrn = true
531
+ end
532
+ end
533
+ msg = build_message("Actual date '#{actual}' equals expected date '#{expected}'.", msg2, desc)
534
+ if rtrn
535
+ passed_to_log("#{msg}")
536
+ else
537
+ failed_to_log("#{msg}")
538
+ end
539
+ rtrn
540
+ rescue
541
+ failed_to_log("Unable to verify that #{msg}. #{$!}")
542
+ end
543
+
544
+ # Verify that a DOM element is in read-only state.
545
+ # @param (see #enabled?)
546
+ # @return [Boolean] Returns true if the element is in read-only state.
547
+ def read_only?(browser, element, how, what, value = nil, desc = '')
548
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
549
+ msg << "and value=>'#{value}' " if value
550
+ msg << "read only"
551
+ e = get_element(browser, element, how, what, value)
552
+ if e
553
+ if e.readonly?
554
+ passed_to_log("#{msg}? #{desc}")
555
+ true
556
+ else
557
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
558
+ end
559
+ end
560
+ rescue
561
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
562
+ end
563
+
564
+ # Verify that a DOM element is not in read-only state.
565
+ # @param (see #enabled?)
566
+ # @return [Boolean] Returns true if the element is not in read-only state.
567
+ def not_read_only?(browser, element, how, what, value = nil, desc = '')
568
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
569
+ msg << "and value=>'#{value}' " if value
570
+ msg << "is not read only"
571
+ e = get_element(browser, element, how, what, value)
572
+ if e
573
+ if e.readonly?
574
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
575
+ else
576
+ passed_to_log("#{msg}? #{desc}")
577
+ true
578
+ end
579
+ end
580
+ rescue
581
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
582
+ end
583
+
584
+ # Verify that a DOM element is ready, i.e., both exists and is enabled.
585
+ # @param (see #exists?)
586
+ # @return [Boolean] Returns true if the element is ready.
587
+ #TODO: Watir-webdriver support
588
+ def ready?(browser, element, how, what, value = '', desc = '')
589
+ msg2 = "and value=>'#{value}' " if value
590
+ msg = build_message("#{element.to_s.titlecase} with #{how}=>'#{what}' ", msg2, 'exists and is enabled.', desc)
591
+ e = get_element(browser, element, how, what, value)
592
+ if e and e.enabled?
593
+ passed_to_log(msg)
594
+ true
595
+ else
596
+ failed_to_log(msg)
597
+ end
598
+ rescue
599
+ failed_to_log("Unable to determine if #{msg}. '#{$!}' [#{get_callers(1)}]")
600
+ end
601
+
602
+ # Verify that a text field (also text area), identified by *how* and *what*, contains only the exact string specified in *expected*.
603
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
604
+ # @param [Symbol] how The element attribute used to identify the specific element.
605
+ # Valid values depend on the kind of element.
606
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
607
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
608
+ # @param [String] expected A string which the value attribute of the text field must equal.
609
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
610
+ # @return [Boolean] Returns true if the *expected* and the value in the text field are identical.
611
+ def textfield_equals?(browser, how, what, expected, desc = '')
612
+ msg = build_message("Expected value to equal '#{expected}' in textfield #{how}=>'#{what}'.", desc)
613
+ actual = browser.text_field(how, what).value
614
+ if actual.is_a?(Array)
615
+ actual = actual[0].to_s
616
+ end
617
+ if actual == expected
618
+ passed_to_log(msg)
619
+ true
620
+ else
621
+ act_s = actual.strip
622
+ exp_s = expected.strip
623
+ if act_s == exp_s
624
+ passed_to_log("#{msg} (stripped)")
625
+ true
626
+ else
627
+ debug_to_report(
628
+ "#{__method__} (spaces underscored):\n "+
629
+ "expected:[#{expected.gsub(' ', '_')}] (#{expected.length})\n "+
630
+ "actual:[#{actual.gsub(' ', '_')}] (#{actual.length}) (spaces underscored)"
631
+ )
632
+ failed_to_log("#{msg}. Found: '#{actual}'")
633
+ end
634
+ end
635
+ rescue
636
+ failed_to_log(unable_to)
637
+ end
638
+
639
+ alias validate_textfield_value textfield_equals?
640
+ alias text_field_equals? textfield_equals?
641
+
642
+ # Verify that a text field (also text area), identified by *how* and *what*, contains the string specified in *expected*.
643
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
644
+ # @param [Symbol] how The element attribute used to identify the specific element.
645
+ # Valid values depend on the kind of element.
646
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
647
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
648
+ # @param [String, Regexp] expected A string or regular expression which must be matched in the value of the text field
649
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
650
+ # @return [Boolean] Returns true if the *expected* is matched in the value of the text field.
651
+ def textfield_contains?(browser, how, what, expected, desc = '')
652
+ msg = build_message("Text field #{how}=>#{what} contains '#{expected}'.", desc)
653
+ contents = browser.text_field(how, what).value
654
+ if contents =~ /#{expected}/
655
+ passed_to_log(msg)
656
+ true
657
+ else
658
+ failed_to_log("#{msg} Contents: '#{contents}'")
659
+ end
660
+ rescue
661
+ failed_to_log(unable_to)
662
+ end
663
+
664
+ # Verify that a text field (also text area), identified by *how* and *what*, is empty.
665
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
666
+ # @param [Symbol] how The element attribute used to identify the specific element.
667
+ # Valid values depend on the kind of element.
668
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
669
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
670
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
671
+ # @return [Boolean] Returns true if the text field is empty.
672
+ def textfield_empty?(browser, how, what, desc = '')
673
+ msg = "Text field #{how}=>#{what} is empty."
674
+ msg << desc if desc.length > 0
675
+ contents = browser.text_field(how, what).value
676
+ if contents.to_s.length == 0
677
+ passed_to_log(msg)
678
+ true
679
+ else
680
+ failed_to_log("#{msg} Contents: '#{contents}'")
681
+ end
682
+ rescue
683
+ failed_to_log(unable_to)
684
+ end
685
+
686
+ alias validate_textfield_empty textfield_empty?
687
+ alias text_field_empty? textfield_empty?
688
+
689
+ # Verify that a text field (also text area), identified by *how* and *what*, contains the string specified in *expected*.
690
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
691
+ # @param [Symbol] how The element attribute used to identify the specific element.
692
+ # Valid values depend on the kind of element.
693
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
694
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
695
+ # @param [String] expected A string in dollar formatting
696
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
697
+ # @return [Boolean] Returns true if the *expected* is matched in the value of the text field.
698
+ def validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '')
699
+ target = expected.dup
700
+ desc << " Dollar formatting"
701
+ if with_cents
702
+ target << '.00' if not expected =~ /\.00$/
703
+ desc << " without cents. orig:(#{expected})"
704
+ else
705
+ target.gsub!(/\.00$/, '')
706
+ desc << " with cents. orig:(#{expected})"
707
+ end
708
+ textfield_equals?(browser, how, what, target, desc)
709
+ end
710
+
711
+ # Verify that *browser* is set to a url that is matched by the string or rexexp in *url*.
712
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
713
+ # @param [String, Regexp] url A string or a regular expression to match to the url of the browser..
714
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
715
+ # @return [Boolean] Returns true if the *expected* is matched in the value of the text field.
716
+ def validate_url(browser, url, desc = '')
717
+ msg = build_message("Current URL matches #{url}.", desc)
718
+ if browser.url.to_s.match(url)
719
+ passed_to_log(msg)
720
+ true
721
+ else
722
+ failed_to_log("#{msg} Actual: #{browser.url}")
723
+ end
724
+ rescue
725
+ failed_to_log(unable_to)
726
+ end
727
+
728
+ # @!endgroup Core
729
+
730
+ # @!group AutoIT
731
+
732
+ def window_exists?(title)
733
+ title = translate_popup_title(title)
734
+ if @ai.WinExists(title) == 1
735
+ passed_to_log("Window title:'#{title}' exists")
736
+ true
737
+ else
738
+ failed_to_log("Window title:'#{title}' does not exist")
739
+ end
740
+ end
741
+
742
+ alias window_exists window_exists?
743
+
744
+ def window_does_not_exist?(title)
745
+ title = translate_popup_title(title)
746
+ if @ai.WinExists(title) == 1
747
+ failed_to_log("Window title:'#{title}' exists")
748
+ else
749
+ passed_to_log("Window title:'#{title}' does not exist")
750
+ true
751
+ end
752
+ end
753
+
754
+ alias window_no_exists window_does_not_exist?
755
+
756
+ # @!endgroup AutoIT
757
+
758
+ # @!group Core
759
+
760
+ def popup_is_browser?(popup, desc = '')
761
+ msg = build_message("Popup: #{popup.title} is a browser window.", desc)
762
+ if is_browser?(popup)
763
+ passed_to_log(msg)
764
+ debug_to_log("\n"+popup.text+"\n")
765
+ true
766
+ else
767
+ failed_to_log(msg)
768
+ end
769
+ rescue
770
+ failed_to_log(unable_to)
771
+ end
772
+
773
+ alias popup_exist popup_is_browser?
774
+ alias popup_exists popup_is_browser?
775
+ alias popup_exist? popup_is_browser?
776
+ alias popup_exists? popup_is_browser?
777
+ alias iepopup_exist popup_is_browser?
778
+ alias iepopup_exist? popup_is_browser?
779
+ alias iepopup_exists popup_is_browser?
780
+ alias iepopup_exists? popup_is_browser?
781
+
782
+ # Verify that select list, identified by the value *what* in the attribute :id, contains text and select it if present.
783
+ def validate_list_by_id(browser, what, option, desc = '', select_if_present = true)
784
+ if select_list_includes?(browser, :id, what, option, desc)
785
+ if select_if_present
786
+ select_option(browser, :id, what, :text, option, desc, false)
787
+ else
788
+ passed_to_log(message)
789
+ true
790
+ end
791
+ end
792
+ end
793
+
794
+ # Verify that select list contains text
795
+ def validate_list_by_name(browser, what, option, desc = '', select_if_present = true)
796
+ if select_list_includes?(browser, :name, what, option, desc)
797
+ if select_if_present
798
+ select_option(browser, :name, what, :text, option, desc, false)
799
+ else
800
+ passed_to_log(message)
801
+ true
802
+ end
803
+ end
804
+ end
805
+
806
+ def validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false)
807
+ cls = browser.class.to_s
808
+ cls.gsub!('Watir::', '')
809
+ cls.gsub!('IE', 'Browser')
810
+ msg = build_message("#{cls} text contains '#{ptrn}'.", desc)
811
+ if ptrn.is_a?(Regexp)
812
+ target = ptrn
813
+ else
814
+ target = Regexp.new(Regexp.escape(ptrn))
815
+ end
816
+ sleep_for(2) unless skip_sleep
817
+ myText = browser.text
818
+ if not myText.match(target)
819
+ sleep_for(2) unless skip_sleep #TODO try a wait_until here?
820
+ myText = browser.text
821
+ end
822
+ if myText.match(target)
823
+ passed_to_log("#{msg}")
824
+ true
825
+ else
826
+ if skip_fail
827
+ debug_to_log("#{cls} text does not contain the text: '#{ptrn}'. #{desc} (Fail suppressed)")
828
+ else
829
+ failed_to_log("#{msg}")
830
+ end
831
+ #debug_to_log("\n#{myText}")
832
+ end
833
+ rescue
834
+ failed_to_log(unable_to)
835
+ end
836
+
837
+ alias validate_link validate_text
838
+
839
+ def text_in_element_equals?(browser, element, how, what, expected, desc = '')
840
+ msg = build_message("Expected exact text '#{expected}' in #{element} :#{how}=>#{what}.", desc)
841
+ text = ''
842
+ who = browser.element(how, what)
843
+ if who
844
+ text = who.text
845
+ if text == expected
846
+ passed_to_log(msg)
847
+ true
848
+ else
849
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
850
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
851
+ failed_to_log("#{msg} Found '#{text}'.")
852
+ end
853
+ end
854
+ rescue
855
+ failed_to_log(unable_to)
856
+ end
857
+
858
+ def element_contains_text?(browser, element, how, what, expected, desc = '')
859
+ msg = build_message("Element #{element} :{how}=>#{what} contains text '#{expected}'.", desc)
860
+ case how
861
+ when :href
862
+ who = browser.link(how, what)
863
+ else
864
+ who = browser.element(how, what)
865
+ end
866
+ if who
867
+ text = who.text
868
+ if expected and expected.length > 0
869
+ rgx = Regexp.new(Regexp.escape(expected))
870
+ if text =~ rgx
871
+ passed_to_log(msg)
872
+ true
873
+ else
874
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
875
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
876
+ failed_to_log("#{msg} Found '#{text}'. #{desc}")
877
+ end
878
+ else
879
+ if text.length > 0
880
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
881
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
882
+ failed_to_log("#{msg} Found '#{text}'. #{desc}")
883
+ else
884
+ passed_to_log(msg)
885
+ true
886
+ end
887
+ end
888
+ end
889
+ rescue
890
+ failed_to_log(unable_to)
891
+ end
892
+
893
+ def validate_select_list(browser, how, what, opt_type, list = nil, desc= '', multiple = false, ignore = ['Select One'], limit = 5)
894
+ mark_testlevel("(#{how}=>#{what})")
895
+ msg = "Select list #{how}=>#{what}"
896
+ ok = true
897
+ select_list = browser.select_list(how, what)
898
+ options = select_list.options
899
+ if list
900
+ if options == list
901
+ passed_to_log(build_message(msg, ": options list equals expected list #{list}"))
902
+ else
903
+ debug_to_report("actual:\n#{nice_array(options, true)}")
904
+ debug_to_report("expected:\n#{nice_array(list, true)}")
905
+ failed_to_log(build_message(
906
+ msg,
907
+ ": options list #{nice_array(options, true)}",
908
+ "does not equal expected list #{nice_array(list, true)}")
909
+ )
910
+ end
911
+ end
912
+
913
+ #single selections
914
+ cnt = 0
915
+ options.each do |opt|
916
+ if not ignore.include?(opt)
917
+ cnt += 1
918
+ ok = select_option(select_list, opt_type, opt)
919
+ break if not ok
920
+ select_list.clear
921
+ break if limit > 0 and cnt >= limit
922
+ end
923
+ end
924
+
925
+ sleep_for(0.5)
926
+ select_list.clear
927
+ if ok and multiple
928
+ if options.length > 2
929
+ targets = list.slice(1, 2)
930
+ select_option(select_list, opt_type, options[1])
931
+ select_option(select_list, opt_type, options[2])
932
+ selected = select_list.selected_options
933
+ msg1 = "#{msg}: selected options equals expected #{nice_array(targets)}."
934
+ if selected == targets
935
+ passed_to_log(msg1)
936
+ else
937
+ failed_to_log("#{msg} Found #{nice_array(selected)}")
938
+ end
939
+ else
940
+ debug_to_log("#{msg}: Too few options to test multiple selection (need 2 or more): '#{options}")
941
+ end
942
+ end
943
+ rescue
944
+ failed_to_log(unable_to)
945
+ end
946
+
947
+ def validate_select_list_contents(browser, how, what, list, desc = '')
948
+ mark_testlevel("#{how}=>#{what}", 2)
949
+ msg = build_message("Select list #{how}=>#{what} options list equals", nice_array(list), desc)
950
+ select_list = browser.select_list(how, what)
951
+ options = select_list.options
952
+ if list
953
+ if options == list
954
+ passed_to_log(msg)
955
+ options
956
+ else
957
+ failed_to_log("#{msg}. Found #{nice_array(options)}")
958
+ nil
959
+ end
960
+ end
961
+ rescue
962
+ failed_to_log(unable_to)
963
+ end
964
+
965
+ def validate_selected_options(browser, how, what, list, desc = '')
966
+ select_list = browser.select_list(how, what)
967
+ selected = select_list.selected_options.sort
968
+ if list.is_a?(Array)
969
+ if selected == list.sort
970
+ passed_to_log("Expected options [#{list.sort}] are selected [#{selected}]. #{desc}")
971
+ else
972
+ failed_to_log("Selected options [#{selected}] do not match expected [#{list.sort}]. #{desc}")
973
+ true
974
+ end
975
+ else
976
+ if selected.length == 1
977
+ if selected[0] =~ /#{list}/
978
+ passed_to_log("Expected option [#{list}] was selected. #{desc}")
979
+ true
980
+ else
981
+ failed_to_log("Expected option [#{list}] was not selected. Found [#{selected}]. #{desc}")
982
+ end
983
+ else
984
+ if selected.include?(list)
985
+ failed_to_log("Expected option [#{list}] was found among multiple selections [#{selected}]. #{desc}")
986
+ else
987
+ failed_to_log("Expected option [#{list}] was not found among multiple selections [#{selected}]. #{desc}")
988
+ end
989
+ end
990
+ end
991
+
992
+ rescue
993
+ failed_to_log(unable_to)
994
+ end
995
+
996
+ alias validate_selections validate_selected_options
997
+ alias validate_select_list_selections validate_selected_options
998
+
999
+ def string_contains?(strg, target, desc = '')
1000
+ msg = build_message("String '#{strg}' contains '#{target}'.", desc)
1001
+ if strg.match(target)
1002
+ passed_to_log("#{msg} (#{__LINE__})")
1003
+ true
1004
+ else
1005
+ failed_to_log("#{msg} (#{__LINE__})")
1006
+ end
1007
+ end
1008
+
1009
+ alias validate_string string_contains?
1010
+ alias validate_string_contains string_contains?
1011
+
1012
+ def string_does_not_contain?(strg, target, desc = '')
1013
+ msg = build_message("String '#{strg}' does not contain '#{target}'.", desc)
1014
+ if strg.match(target)
1015
+ failed_to_log("#{msg} (#{__LINE__})")
1016
+ true
1017
+ else
1018
+ passed_to_log("#{msg} (#{__LINE__})")
1019
+ end
1020
+ end
1021
+
1022
+ alias validate_string_not_contains string_does_not_contain?
1023
+ alias validate_string_not_contain string_does_not_contain?
1024
+ alias validate_string_does_not_contain string_does_not_contain?
1025
+
1026
+ def validate_no_text(browser, ptrn, desc = '')
1027
+ cls = browser.class.to_s
1028
+ cls.gsub!('Watir::', '')
1029
+ cls.gsub!('IE', 'Browser')
1030
+ msg = "#{cls} does not contain text '#{ptrn}'."
1031
+ msg << " #{desc}" if desc.length > 0
1032
+ if ptrn.is_a?(Regexp)
1033
+ target = ptrn
1034
+ else
1035
+ target = Regexp.new(Regexp.escape(ptrn))
1036
+ end
1037
+ browser_text = browser.text
1038
+ if browser_text.match(target)
1039
+ failed_to_log("#{msg} [#{browser_text.match(target)[0]}]")
1040
+ else
1041
+ passed_to_log(msg)
1042
+ true
1043
+ end
1044
+ rescue
1045
+ failed_to_log(unable_to)
1046
+ end
1047
+
1048
+ def textfield_does_not_equal?(browser, how, what, expected, desc = '')
1049
+ msg = build_message("Text field #{how}=>#{what} does not equal '#{expected}'", desc)
1050
+ if not browser.text_field(how, what).value == expected
1051
+ passed_to_log(msg)
1052
+ true
1053
+ else
1054
+ failed_to_log(msg)
1055
+ end
1056
+ rescue
1057
+ failed_to_log(unable_to)
1058
+ end
1059
+
1060
+ alias validate_textfield_not_value textfield_does_not_equal?
1061
+
1062
+ def verify_class(browser, element, how, what, strg, desc = '')
1063
+ msg = build_message("#{element} :#{how}=>#{what} :class contains '#{strg}'", desc)
1064
+ class_strg = browser.element(how, what).class_name
1065
+ if class_strg =~ /#{strg}/
1066
+ passed_to_log(msg)
1067
+ true
1068
+ else
1069
+ failed_to_log(msg)
1070
+ end
1071
+ rescue
1072
+ failed_to_log(unable_to)
1073
+ end
1074
+
1075
+ # @!endgroup Core
1076
+
1077
+ # @!group Deprecated
1078
+ # @deprecated
1079
+ def self.included(mod)
1080
+ # puts "RegressionSupport::Validations extended by #{mod}"
1081
+ end
1082
+
1083
+ # @deprecated Use #message_to_log
1084
+ def validate_message(browser, message)
1085
+ message_to_log(message)
1086
+ end
1087
+
1088
+ # @!endgroup Deprecated
1089
+
1090
+ end
1091
+ end
1092
+ end
1093
+