awetestlib 0.1.3-x86-mingw32 → 0.1.5-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/awetestlib.windows.gemspec +1 -1
  2. data/bin/awetestlib +11 -4
  3. data/bin/awetestlib-helpers.rb +28 -1
  4. data/bin/awetestlib-netbeans-setup.rb +39 -0
  5. data/bin/awetestlib-rubymine-setup.rb +33 -0
  6. data/images/logo.png +0 -0
  7. data/lib/awetestlib/html_report.rb +171 -0
  8. data/lib/{regression → awetestlib}/logging.rb +10 -43
  9. data/lib/awetestlib/regression/browser.rb +1233 -0
  10. data/lib/awetestlib/regression/drag_and_drop.rb +379 -0
  11. data/lib/awetestlib/regression/find.rb +431 -0
  12. data/lib/awetestlib/regression/legacy.rb +45 -0
  13. data/lib/awetestlib/regression/page_data.rb +190 -0
  14. data/lib/awetestlib/regression/runner.rb +306 -0
  15. data/lib/awetestlib/regression/tables.rb +491 -0
  16. data/lib/awetestlib/regression/user_input.rb +1256 -0
  17. data/lib/awetestlib/regression/utilities.rb +895 -0
  18. data/lib/awetestlib/regression/validations.rb +1184 -0
  19. data/lib/awetestlib/regression/waits.rb +391 -0
  20. data/lib/awetestlib/runner.rb +16 -0
  21. data/lib/awetestlib.rb +4 -4
  22. data/lib/version.rb +2 -2
  23. data/setup_samples/sample_netbeans/demo.rb +86 -0
  24. data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -0
  25. data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -0
  26. data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +1 -0
  27. data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -0
  28. data/setup_samples/sample_netbeans/nbproject/project.properties +5 -0
  29. data/setup_samples/sample_netbeans/nbproject/project.xml +13 -0
  30. data/setup_samples/sample_rubymine/.idea/.name +1 -0
  31. data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -0
  32. data/setup_samples/sample_rubymine/.idea/misc.xml +5 -0
  33. data/setup_samples/sample_rubymine/.idea/modules.xml +9 -0
  34. data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -0
  35. data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +5 -0
  36. data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -0
  37. data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -0
  38. data/setup_samples/sample_rubymine/demo.rb +86 -0
  39. metadata +44 -19
  40. data/lib/regression/browser.rb +0 -1259
  41. data/lib/regression/drag_and_drop.rb +0 -374
  42. data/lib/regression/find.rb +0 -426
  43. data/lib/regression/legacy.rb +0 -40
  44. data/lib/regression/page_data.rb +0 -185
  45. data/lib/regression/runner.rb +0 -278
  46. data/lib/regression/tables.rb +0 -486
  47. data/lib/regression/user_input.rb +0 -1255
  48. data/lib/regression/utilities.rb +0 -891
  49. data/lib/regression/validations.rb +0 -1179
  50. data/lib/regression/waits.rb +0 -387
@@ -0,0 +1,1184 @@
1
+ module Awetestlib
2
+ module Regression
3
+ module Validations
4
+
5
+ def self.included(mod)
6
+ # puts "RegressionSupport::Validations extended by #{mod}"
7
+ end
8
+
9
+ def modal_exists?(browser, button = nil)
10
+ rtrn = nil
11
+ if @browserAbbrev == 'IE'
12
+ Timeout::timeout(2) do
13
+ begin
14
+ if browser.enabled_popup
15
+ hwnd = browser.enabled_popup(5)
16
+ debug_to_log("Modal popup with handle #{hwnd} found. (#{__LINE__})")
17
+ wc = WinClicker.new
18
+ wc.makeWindowActive(hwnd)
19
+ rtrn = wc.getWindowTitle(hwnd)
20
+ if button
21
+ wc.clickWindowsButton_hWnd(hwnd, button)
22
+ end
23
+ wc = nil
24
+ end
25
+ rescue Timeout::Error
26
+ debug_to_log("No Modal popup found. (#{__LINE__})")
27
+ return rtrn
28
+ end
29
+ return rtrn
30
+ end
31
+ rtrn
32
+ else
33
+ rtrn
34
+ end
35
+ end
36
+
37
+ def validate_message(browser, message)
38
+ if validate(browser, @myName, __LINE__)
39
+ message_to_log(message)
40
+ end
41
+ end
42
+
43
+ def validate_style_value(browser, element, how, what, type, expected, desc = '')
44
+ #TODO: works only with watir-webdriver
45
+ msg = "Expected CSS style #{type} value '#{expected}' in #{element} with #{how} = #{what}"
46
+ msg << " #{desc}" if desc.length > 0
47
+ case element
48
+ when :link
49
+ actual = browser.link(how => what).style type
50
+ when :button
51
+ actual = browser.button(how => what).style type
52
+ when :image
53
+ actual = browser.image(how => what).style type
54
+ when :span
55
+ actual = browser.span(how => what).style type
56
+ when :div
57
+ actual = browser.div(how => what).style type
58
+ end
59
+ if expected == actual
60
+ passed_to_log(msg)
61
+ else
62
+ failed_to_log(msg)
63
+ end
64
+ rescue
65
+ failed_to_log( "Unable to validate #{msg} '#{$!}'")
66
+ end
67
+
68
+ ##### begin core validation methods #####
69
+
70
+ def arrays_match?(exp, act, dir, col, org = nil)
71
+ if exp == act
72
+ passed_to_log("Click on #{dir} column '#{col}' produces expected sorted list.")
73
+ true
74
+ else
75
+ failed_to_log("Click on #{dir} column '#{col}' fails to produce expected sorted list.")
76
+ debug_to_log("Original order ['#{org.join("', '")}']") if org
77
+ debug_to_log("Expected order ['#{exp.join("', '")}']")
78
+ debug_to_log(" Actual order ['#{act.join("', '")}']")
79
+ end
80
+ end
81
+
82
+ alias arrays_match arrays_match?
83
+
84
+ def enabled?(browser, element, how, what, desc = '')
85
+ msg = "#{element.to_s.titlecase} by #{how}=>'#{what}' is enabled.}"
86
+ msg << " #{desc}" if desc.length > 0
87
+ case element
88
+ when :textfield, :textarea, :text_area, :text_field
89
+ rtrn = browser.text_field(how, what).enabled? and not browser.text_field(how, what).readonly?
90
+ when :select_list, :selectlist
91
+ rtrn = browser.select_list(how, what).enabled?
92
+ else
93
+ rtrn = browser.element(how, what).enabled?
94
+ end
95
+ if rtrn
96
+ passed_to_log("#{msg}")
97
+ true
98
+ else
99
+ failed_to_log("#{msg}")
100
+ end
101
+ rtrn
102
+ rescue
103
+ failed_to_log("#Unable to verify that #{msg}': '#{$!}")
104
+ end
105
+
106
+ alias validate_enabled enabled?
107
+
108
+ def date_string_equals?(actual, expected, desc = '', fail_on_format = true)
109
+ rtrn = false
110
+ msg = "Assert actual date '#{actual}' equals expected date '#{expected}'. #{desc} "
111
+ if actual == expected
112
+ rtrn = true
113
+ elsif DateTime.parse(actual).to_s == DateTime.parse(expected).to_s
114
+ msg << " with different formatting. "
115
+ if not fail_on_format
116
+ rtrn = true
117
+ end
118
+ end
119
+ msg << " #{desc}" if desc.length > 0
120
+ if rtrn
121
+ passed_to_log("#{msg}")
122
+ else
123
+ failed_to_log("#{msg}")
124
+ end
125
+ rtrn
126
+ rescue
127
+ failed_to_log("Unable to #{msg}. #{$!}")
128
+ end
129
+
130
+ def disabled?(browser, element, how, what, desc = '')
131
+ msg = "#{element.to_s.titlecase} by #{how}=>'#{what}' is disabled. #{desc}"
132
+ case element
133
+ when :textfield, :textarea, :text_area, :text_field
134
+ rtrn = browser.text_field(how, what).disabled? ||
135
+ browser.text_field(how, what).readonly?
136
+ when :select_list, :selectlist
137
+ rtrn = browser.select_list(how, what).disabled?
138
+ when :checkbox
139
+ rtrn = browser.checkbox(how, what).disabled?
140
+ when :radio
141
+ rtrn = browser.radio(how, what).disabled?
142
+ when :button
143
+ rtrn = browser.button(how, value).disabled?
144
+ else
145
+ msg = "#{__method__} does not yet support '#{element}'. #{desc}"
146
+ debug_to_log(msg)
147
+ raise msg
148
+ end
149
+ if rtrn
150
+ passed_to_log("#{msg}")
151
+ true
152
+ else
153
+ failed_to_log("#{msg}")
154
+ end
155
+ rtrn
156
+ rescue
157
+ failed_to_log("#Unable to verify that #{msg}: '#{$!}'")
158
+ end
159
+
160
+ alias validate_not_enabled disabled?
161
+ alias validate_disabled disabled?
162
+
163
+ def verify_text_in_table_with_text(table, text, value)
164
+ #TODO This needs clarification, renaming
165
+ msg = "Table :id=>#{table.id} with text '#{text} contains '#{value}."
166
+ index = get_index_of_row_with_text(table, text)
167
+ if table[index].text =~ value
168
+ passed_to_log(msg)
169
+ true
170
+ else
171
+ failed_to_log(msg)
172
+ end
173
+ end
174
+
175
+ def visible?(browser, element, how, what, desc = '')
176
+ msg = "#{element.to_s.titlecase} #{how}=>'#{what}' is visible. #{desc}"
177
+ rtrn = false
178
+ case how
179
+ when :index
180
+ target = get_element(browser, element, how, what)
181
+ if target.visible?
182
+ rtrn = true
183
+ end
184
+ else
185
+ if browser.element(how, what).visible?
186
+ rtrn = true
187
+ end
188
+ end
189
+ if rtrn
190
+ passed_to_log("#{msg}")
191
+ else
192
+ failed_to_log("#{msg}")
193
+ end
194
+ rtrn
195
+ rescue
196
+ failed_to_log("Unable to verify that #{msg}': '#{$!}'")
197
+ end
198
+
199
+ alias validate_visible visible?
200
+
201
+ def not_visible?(browser, element, how, what, desc = '')
202
+ msg = "#{element.to_s.titlecase} #{how}=>'#{what}' is not visible. #{desc}"
203
+ rtrn = false
204
+ case how
205
+ when :index
206
+ target = get_element(browser, element, how, what)
207
+ if not target.visible?
208
+ rtrn = true
209
+ end
210
+ else
211
+ if not browser.element(how, what).visible?
212
+ rtrn = true
213
+ end
214
+ end
215
+ if rtrn
216
+ passed_to_log("#{msg}")
217
+ else
218
+ failed_to_log("#{msg}")
219
+ end
220
+ rtrn
221
+ rescue
222
+ failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}")
223
+ end
224
+
225
+ alias validate_not_visible not_visible?
226
+
227
+ def checked?(browser, how, what, desc = '')
228
+ msg = "Checkbox #{how}=>#{what} is checked."
229
+ msg << " #{desc}" if desc.length > 0
230
+ if browser.checkbox(how, what).checked?
231
+ if validate(browser, @myName, __LINE__)
232
+ passed_to_log(msg)
233
+ true
234
+ end
235
+ else
236
+ failed_to_log(msg)
237
+ end
238
+ rescue
239
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
240
+ end
241
+
242
+ alias checkbox_checked? checked?
243
+ alias checkbox_set? checked?
244
+
245
+ def not_checked?(browser, how, what, desc = '')
246
+ msg = "Checkbox #{how}=>#{what} is not checked."
247
+ msg << " #{desc}" if desc.length > 0
248
+ if not browser.checkbox(how, what).checked?
249
+ if validate(browser, @myName, __LINE__)
250
+ passed_to_log(msg)
251
+ true
252
+ end
253
+ else
254
+ failed_to_log(msg)
255
+ end
256
+ rescue
257
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
258
+ end
259
+
260
+ alias checkbox_checked? checked?
261
+ alias checkbox_set? checked?
262
+
263
+ def exists?(browser, element, how, what, value = nil, desc = '')
264
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
265
+ msg << "and value=>'#{value}' " if value
266
+ msg << "exists"
267
+ e = get_element(browser, element, how, what, value)
268
+ if e
269
+ passed_to_log("#{msg}? #{desc}")
270
+ true
271
+ else
272
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
273
+ end
274
+ rescue
275
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
276
+ end
277
+
278
+ def does_not_exist?(browser, element, how, what, value = nil, desc = '')
279
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
280
+ msg << "and value=>'#{value}' " if value
281
+ msg << "does not exist."
282
+ msg << " #{desc}" if desc.length > 0
283
+ if browser.element(how, what).exists?
284
+ failed_to_log(msg)
285
+ else
286
+ passed_to_log(msg)
287
+ true
288
+ end
289
+ rescue
290
+ failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}")
291
+ end
292
+
293
+ alias not_exist? does_not_exist?
294
+
295
+ def set?(browser, how, what, desc = '', no_fail = false)
296
+ #TODO Needs to handle radio value as well
297
+ msg = "Radio #{how}=>#{what} is selected."
298
+ msg << " #{desc}" if desc.length > 0
299
+ if browser.radio(how, what).set?
300
+ if validate(browser, @myName, __LINE__)
301
+ passed_to_log(msg)
302
+ true
303
+ end
304
+ else
305
+ if no_fail
306
+ passed_to_log("Radio #{how}=>#{what} is not selected.")
307
+ else
308
+ failed_to_log(msg)
309
+ end
310
+ end
311
+ rescue
312
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
313
+ end
314
+
315
+ alias radio_set? set?
316
+ alias radio_checked? set?
317
+ alias radio_selected? set?
318
+
319
+ def not_set?(browser, how, what, desc = '', no_fail = false)
320
+ #TODO Needs to handle radio value as well
321
+ msg = "Radio #{how}=>#{what} is not selectedd."
322
+ msg << " #{desc}" if desc.length > 0
323
+ if not browser.radio(how, what).set?
324
+ if validate(browser, @myName, __LINE__)
325
+ passed_to_log(msg)
326
+ true
327
+ end
328
+ else
329
+ if no_fail
330
+ passed_to_log("Radio #{how}=>#{what} is not selected.")
331
+ else
332
+ failed_to_log(msg)
333
+ end
334
+ end
335
+ rescue
336
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
337
+ end
338
+
339
+ alias radio_not_set? not_set?
340
+ alias radio_not_checked? not_set?
341
+ alias radio_not_selected? not_set?
342
+
343
+ def radio_with_value_set?(browser, how, what, value, desc = '', no_fail = false)
344
+ msg = "Radio #{how}=>#{what} :value=>#{value} is selected."
345
+ msg << " #{desc}" if desc.length > 0
346
+ if browser.radio(how, what, value).set?
347
+ if validate(browser, @myName, __LINE__)
348
+ passed_to_log(msg)
349
+ true
350
+ end
351
+ else
352
+ if no_fail
353
+ passed_to_log("Radio #{how}=>#{what} :value=>#{value} is not selected.")
354
+ else
355
+ failed_to_log(msg)
356
+ end
357
+ end
358
+ rescue
359
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
360
+ end
361
+
362
+ alias radio_set_with_value? radio_with_value_set?
363
+
364
+ def select_list_includes?(browser, how, what, option, desc = '')
365
+ msg = "Select list #{how}=>#{what} includes option '#{option}'."
366
+ msg << " #{desc}" if desc.length > 0
367
+ select_list = browser.select_list(how, what)
368
+ options = select_list.options
369
+ if option
370
+ if options.include?(option)
371
+ passed_to_log(msg)
372
+ true
373
+ else
374
+ failed_to_log(msg)
375
+ nil
376
+ end
377
+ end
378
+ rescue
379
+ failed_to_log("Unable to verify #{msg}. '#{$!}'")
380
+ end
381
+
382
+ alias validate_select_list_contains select_list_includes?
383
+ alias select_list_contains? select_list_includes?
384
+
385
+ def select_list_does_not_include?(browser, how, what, option, desc = '')
386
+ msg = "Select list #{how}=>#{what} does not include option '#{option}'."
387
+ msg << " #{desc}" if desc.length > 0
388
+ select_list = browser.select_list(how, what)
389
+ options = select_list.options
390
+ if option
391
+ if not options.include?(option)
392
+ passed_to_log(msg)
393
+ true
394
+ else
395
+ failed_to_log(msg)
396
+ nil
397
+ end
398
+ end
399
+ rescue
400
+ failed_to_log("Unable to verify #{msg}. '#{$!}'")
401
+ end
402
+
403
+ def string_equals?(actual, target, desc = '')
404
+ msg = "Assert actual '#{actual}' equals expected '#{target}'. #{desc} "
405
+ if actual == target
406
+ passed_to_log("#{msg}")
407
+ true
408
+ else
409
+ failed_to_log("#{msg}")
410
+ end
411
+ rescue
412
+ failed_to_log("Unable to #{msg}. #{$!}")
413
+ end
414
+
415
+ alias validate_string_equal string_equals?
416
+ alias validate_string_equals string_equals?
417
+ alias text_equals string_equals?
418
+ alias text_equals? string_equals?
419
+
420
+ def string_does_not_equal?(strg, target, desc = '')
421
+ msg = "String '#{strg}' does not equal '#{target}'."
422
+ msg << " '#{desc}' " if desc.length > 0
423
+ if strg == target
424
+ failed_to_log("#{msg} (#{__LINE__})")
425
+ true
426
+ else
427
+ passed_to_log("#{msg} (#{__LINE__})")
428
+ end
429
+ end
430
+
431
+ alias validate_string_not_equal string_does_not_equal?
432
+ alias validate_string_does_not_equal string_does_not_equal?
433
+
434
+ def read_only?(browser, element, how, what, value = nil, desc = '')
435
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
436
+ msg << "and value=>'#{value}' " if value
437
+ msg << "read only"
438
+ e = get_element(browser, element, how, what, value)
439
+ if e
440
+ if e.readonly?
441
+ passed_to_log("#{msg}? #{desc}")
442
+ true
443
+ else
444
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
445
+ end
446
+ end
447
+ rescue
448
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
449
+ end
450
+
451
+ def not_read_only?(browser, element, how, what, value = nil, desc = '')
452
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
453
+ msg << "and value=>'#{value}' " if value
454
+ msg << "is not read only"
455
+ e = get_element(browser, element, how, what, value)
456
+ if e
457
+ if e.readonly?
458
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
459
+ else
460
+ passed_to_log("#{msg}? #{desc}")
461
+ true
462
+ end
463
+ end
464
+ rescue
465
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
466
+ end
467
+
468
+ def ready?(browser, element, how, what, value = '', desc = '')
469
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
470
+ msg << "and value=>'#{value}' " if value
471
+ e = get_element(browser, element, how, what, value)
472
+ if e and e.enabled?
473
+ passed_to_log("#{msg}? #{desc}")
474
+ true
475
+ else
476
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
477
+ end
478
+ rescue
479
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
480
+ end
481
+
482
+ ##### end core validation methods #####
483
+
484
+ ##### begin methods using @ai #####
485
+
486
+ def window_exists?(title)
487
+ title = translate_popup_title(title)
488
+ if @ai.WinExists(title) == 1
489
+ passed_to_log("Window title:'#{title}' exists")
490
+ true
491
+ else
492
+ failed_to_log("Window title:'#{title}' does not exist")
493
+ end
494
+ end
495
+
496
+ alias window_exists window_exists?
497
+
498
+ def window_does_not_exist?(title)
499
+ title = translate_popup_title(title)
500
+ if @ai.WinExists(title) == 1
501
+ failed_to_log("Window title:'#{title}' exists")
502
+ else
503
+ passed_to_log("Window title:'#{title}' does not exist")
504
+ true
505
+ end
506
+ end
507
+
508
+ alias window_no_exists window_does_not_exist?
509
+
510
+ ##### end methods using @ai #####
511
+
512
+ ##### backward compatible methods #####
513
+
514
+ def validate_link_exist(browser, link, logit = true, desc = '')
515
+ exists?(browser, :link, :text, link, nil, desc)
516
+ end
517
+
518
+ def link_not_exist?(browser, link, desc = '')
519
+ does_not_exist?(browser, :link, :text, link, nil, desc)
520
+ end
521
+
522
+ alias validate_link_not_exist link_not_exist?
523
+
524
+ def validate_div_visible_by_id(browser, strg)
525
+ visible?(browser, :div, :id, strg)
526
+ end
527
+
528
+ def validate_div_not_visible_by_id(browser, strg, desc = '')
529
+ not_visible?(browser, :div, :id, strg, desc)
530
+ end
531
+
532
+ ##### end backward compatible methods #####
533
+
534
+
535
+ def link_enabled?(browser, strg)
536
+ #TODO Use enabled?()
537
+ count = string_count_in_string(browser.text, strg)
538
+ if count > 0
539
+ if browser.link(:text, strg).enabled?
540
+ if validate(browser, @myName, __LINE__)
541
+ passed_to_log(strg + " is enabled. (#{__LINE__})")
542
+ true
543
+ end
544
+ else
545
+ failed_to_log(strg + " is not enabled.")
546
+ end
547
+ else
548
+ failed_to_log("Link '#{strg.to_s}' (by :text) not found. Cannot validate if enabled. (#{__LINE__}) " + desc)
549
+ end
550
+ rescue
551
+ failed_to_log("Unable to validate that link with :text '#{text}' is enabled: '#{$!}'. (#{__LINE__})")
552
+ debug_to_log("#{strg} appears #{count} times in browser.text.")
553
+ end
554
+
555
+ alias validate_link_enabled link_enabled?
556
+
557
+ def link_disabled?(browser, strg)
558
+ #TODO use disabled?()
559
+ count = string_count_in_string(browser.text, strg)
560
+ if count > 0
561
+ if browser.link(:text, strg).enabled?
562
+ if validate(browser, @myName, __LINE__)
563
+ failed_to_log(strg + " is enabled. (#{__LINE__})")
564
+ end
565
+ else
566
+ passed_to_log(strg + " is not enabled.")
567
+ true
568
+ end
569
+ else
570
+ failed_to_log("Link '#{strg.to_s}' (by :text) not found. Cannot validate if disabled. (#{__LINE__}) " + desc)
571
+ end
572
+ rescue
573
+ failed_to_log("Unable to validate that link with :text '#{text}' is enabled: '#{$!}'. (#{__LINE__})")
574
+ debug_to_log("#{strg} appears #{count} times in browser.text.")
575
+ end
576
+
577
+ alias validate_link_not_enabled link_disabled?
578
+
579
+ def popup_exists?(popup, message=nil)
580
+ if not message
581
+ message = "Popup: #{popup.title}"
582
+ end
583
+ if is_browser?(popup)
584
+ passed_to_log("#{message}: found.")
585
+ debug_to_log("\n"+popup.text+"\n")
586
+ true
587
+ else
588
+ failed_to_log("#{message}: not found." + " (#{__LINE__})")
589
+ end
590
+ rescue
591
+ failed_to_log("Unable to validate existence of popup: '#{$!}'. (#{__LINE__})")
592
+ end
593
+
594
+ alias popup_exist popup_exists?
595
+ alias popup_exists popup_exists?
596
+ alias popup_exist? popup_exists?
597
+ alias iepopup_exist popup_exists?
598
+ alias iepopup_exist? popup_exists?
599
+ alias iepopup_exists popup_exists?
600
+ alias iepopup_exists? popup_exists?
601
+
602
+ def validate_drag_drop(err, tol, exp, act)
603
+ ary = [false, "failed, expected: #{exp}, actual: #{act}, err: #{err}"]
604
+ if err == 0
605
+ ary = [true, 'succeeded ']
606
+ elsif err.abs <= tol
607
+ ary = [true, "within tolerance (+-#{tol}px) "]
608
+ end
609
+ ary
610
+ end
611
+
612
+ def validate_list(browser, listId, text, message)
613
+ message_to_log("Method validate_list() is deprecated: use validate_list_by_xxx instead")
614
+ validate_list_by_id(browser, listId, text, message)
615
+ end
616
+
617
+ #Validate select list contains text
618
+ def validate_list_by_id(browser, strg, text, message, select_if_present=true)
619
+ #TODO Use select_list_includes?() ?
620
+ if browser.select_list(:id, strg).exists?
621
+ select_list = browser.select_list(:id, strg)
622
+ if select_list.include?(text)
623
+ if select_if_present
624
+ if select_option_by_id_and_option_text(browser, strg, text)
625
+ if validate(browser, @myName, __LINE__)
626
+ passed_to_log(message)
627
+ true
628
+ end
629
+ else
630
+ failed_to_log(message + " (#{__LINE__})")
631
+ end
632
+ else
633
+ if validate(browser, @myName, __LINE__)
634
+ passed_to_log(message)
635
+ true
636
+ end
637
+ end
638
+ else
639
+ failed_to_log(message + " Not found. (#{__LINE__})")
640
+ end
641
+ else
642
+ failed_to_log("Select list with id='#{strg} not found. (#{__LINE__})")
643
+ end
644
+ rescue
645
+ failed_to_log("Unable to validate selectlist with id='#{strg}: '#{$!}'. (#{__LINE__})")
646
+ end
647
+
648
+ #Validate select list contains text
649
+ def validate_list_by_name(browser, strg, text, message, select_if_present=true)
650
+ #TODO Use select_list_includes?() ?
651
+ if browser.select_list(:name, strg).exists?
652
+ select_list = browser.select_list(:name, strg)
653
+ if select_list.include?(text)
654
+ if select_if_present
655
+ if select_option_by_name_and_option_text(browser, strg, text)
656
+ if validate(browser, @myName, __LINE__)
657
+ passed_to_log(message)
658
+ true
659
+ end
660
+ else
661
+ failed_to_log(message + " (#{__LINE__})")
662
+ end
663
+ else
664
+ if validate(browser, @myName, __LINE__)
665
+ passed_to_log(message)
666
+ true
667
+ end
668
+ end
669
+ else
670
+ failed_to_log(message + " Not found. (#{__LINE__})")
671
+ end
672
+ else
673
+ failed_to_log("Select list with name='#{strg} not found. (#{__LINE__})")
674
+ end
675
+ rescue
676
+ failed_to_log("Unable to validate that '#{text}' appeared in select list with name='#{strg}: '#{$!}'. (#{__LINE__})")
677
+ end
678
+
679
+ #Validate select list does not contain text
680
+ def validate_no_list(browser, id, text, desc = '')
681
+ select_list_does_not_include?(browser, :id, id, text, desc)
682
+ end
683
+
684
+ def validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false)
685
+ cls = browser.class.to_s
686
+ cls.gsub!('Watir::', '')
687
+ cls.gsub!('IE', 'Browser')
688
+ msg = "#{cls} text contains '#{ptrn}'."
689
+ msg << " #{desc}" if desc.length > 0
690
+ if ptrn.is_a?(Regexp)
691
+ target = ptrn
692
+ else
693
+ target = Regexp.new(Regexp.escape(ptrn))
694
+ end
695
+ sleep_for(2) unless skip_sleep
696
+ myText = browser.text
697
+ if not myText.match(target)
698
+ sleep_for(2) unless skip_sleep #TODO try a wait_until here
699
+ myText = browser.text
700
+ end
701
+ if myText.match(target)
702
+ #if myText.match(ptrn)
703
+ if validate(browser, @myName, __LINE__)
704
+ passed_to_log("#{msg}")
705
+ true
706
+ end
707
+ else
708
+ if skip_fail
709
+ debug_to_log("#{cls} text does not contain the text: '#{ptrn}'. #{desc}")
710
+ else
711
+ failed_to_log("#{msg}")
712
+ end
713
+ #debug_to_log("\n#{myText}")
714
+ end
715
+ rescue
716
+ failed_to_log("Unable to validate #{msg} '#{$!}'")
717
+ end
718
+
719
+ alias validate_link validate_text
720
+
721
+ def text_in_element_equals?(browser, element, how, what, expected, desc = '')
722
+ msg = "Expected exact text '#{expected}' in #{element} :#{how}=>#{what}."
723
+ msg << " #{desc}" if desc.length > 0
724
+ text = ''
725
+ who = browser.element(how, what)
726
+ if who
727
+ text = who.text
728
+ if text == expected
729
+ passed_to_log(msg)
730
+ true
731
+ else
732
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
733
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
734
+ failed_to_log("#{msg} Found '#{text}'.")
735
+ end
736
+ end
737
+ rescue
738
+ failed_to_log("Unable to verify #{msg} '#{$!}'")
739
+ end
740
+
741
+ def text_in_span_equals?(browser, how, what, expected, desc = '')
742
+ text_in_element_equals?(browser, :span, how, what, expected, desc)
743
+ end
744
+
745
+ def element_contains_text?(browser, element, how, what, expected, desc = '')
746
+ msg = "Element #{element} :{how}=>#{what} contains text '#{expected}'."
747
+ msg << " #{desc}" if desc.length > 0
748
+ who = browser.element(how, what)
749
+ if who
750
+ text = who.text
751
+ if expected and expected.length > 0
752
+ rgx = Regexp.new(Regexp.escape(expected))
753
+ if text =~ rgx
754
+ passed_to_log(msg)
755
+ true
756
+ else
757
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
758
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
759
+ failed_to_log("#{msg} Found '#{text}'. #{desc}")
760
+ end
761
+ else
762
+ if text.length > 0
763
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
764
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
765
+ failed_to_log("#{msg} Found '#{text}'. #{desc}")
766
+ else
767
+ passed_to_log(msg)
768
+ true
769
+ end
770
+ end
771
+ end
772
+ rescue
773
+ failed_to_log("Unable to verify #{msg} '#{$!}'")
774
+ end
775
+
776
+ def span_contains_text?(browser, how, what, expected, desc = '')
777
+ element_contains_text?(browser, :span, how, what, expected, desc)
778
+ end
779
+
780
+ alias valid_text_in_span span_contains_text?
781
+
782
+ def validate_text_in_span_by_id(browser, id, strg = '', desc = '')
783
+ element_contains_text?(browser, :span, :id, id, strg, desc)
784
+ end
785
+
786
+ def validate_url(browser, url, message = '')
787
+ if browser.url.to_s.match(url)
788
+ if validate(browser, @myName, __LINE__)
789
+ passed_to_log('Found "'+url.to_s+'" ' + message)
790
+ true
791
+ end
792
+ else
793
+ failed_to_log('Did not find "'+url.to_s+'" ' + message + " (#{__LINE__})")
794
+ end
795
+ rescue
796
+ failed_to_log("Unable to validate that current url is '#{url}': '#{$!}'. (#{__LINE__})")
797
+ end
798
+
799
+ def validate_select_list(browser, how, what, opt_type, list = nil, multiple = false, ignore = ['Select One'], limit = 5)
800
+ mark_testlevel("#{__method__.to_s.titleize} (#{how}=>#{what})", 2)
801
+ ok = true
802
+ select_list = browser.select_list(how, what)
803
+ options = select_list.options
804
+ if list
805
+ if options == list
806
+ passed_to_log("Select list options list equals expected list #{list}")
807
+ else
808
+ debug_to_report("actual:\n#{nice_array(options, true)}")
809
+ debug_to_report("expected:\n#{nice_array(list, true)}")
810
+ failed_to_log("Select list options list #{nice_array(options, true)} "+
811
+ "does not equal expected list #{nice_array(list, true)}")
812
+ end
813
+ end
814
+
815
+ #single selections
816
+ cnt = 0
817
+ options.each do |opt|
818
+ if not ignore.include?(opt)
819
+ cnt += 1
820
+ ok = select_option(select_list, opt_type, opt)
821
+ break if not ok
822
+ select_list.clear
823
+ break if limit > 0 and cnt >= limit
824
+ end
825
+ end
826
+
827
+ sleep_for(0.5)
828
+ select_list.clear
829
+ if ok and multiple
830
+ if options.length > 2
831
+ targets = list.slice(1, 2)
832
+ select_option(select_list, opt_type, options[1])
833
+ select_option(select_list, opt_type, options[2])
834
+ selected = select_list.selected_options
835
+ if selected == targets
836
+ passed_to_log("Select list selected options equals expected #{targets}")
837
+ else
838
+ failed_to_log("Select list selected options #{selected} does not equal expected list #{targets.to_a}")
839
+ end
840
+ else
841
+ debug_to_log("Too few options to test multiple selection (need 2 or more): '#{options}", __LINE__)
842
+ end
843
+ end
844
+ rescue
845
+ failed_to_log("Unable to validate select_list: '#{$!}'", __LINE__)
846
+ end
847
+
848
+ def validate_select_list_contents(browser, how, what, list)
849
+ mark_testlevel("#{__method__.to_s.titleize} (#{what})", 2)
850
+ select_list = browser.select_list(how, what)
851
+ options = select_list.options
852
+ if list
853
+ if options == list
854
+ passed_to_log("Select list options list equals expected list #{list}")
855
+ options
856
+ else
857
+ failed_to_log("Select list options list #{options} does not equal expected list #{list}")
858
+ nil
859
+ end
860
+ end
861
+ rescue
862
+ failed_to_log("Unable to validate select_list contents: '#{$!}'", __LINE__)
863
+ end
864
+
865
+ def validate_selected_options(browser, how, what, list, desc = '')
866
+ select_list = browser.select_list(how, what)
867
+ selected = select_list.selected_options.sort
868
+ if list.is_a?(Array)
869
+ if selected == list.sort
870
+ passed_to_log("Expected options [#{list.sort}] are selected [#{selected}]. #{desc}")
871
+ else
872
+ failed_to_log("Selected options [#{selected}] do not match expected [#{list.sort}]. #{desc}")
873
+ true
874
+ end
875
+ else
876
+ if selected.length == 1
877
+ if selected[0] =~ /#{list}/
878
+ passed_to_log("Expected option [#{list}] was selected. #{desc}")
879
+ true
880
+ else
881
+ failed_to_log("Expected option [#{list}] was not selected. Found [#{selected}]. #{desc}")
882
+ end
883
+ else
884
+ if selected.include?(list)
885
+ failed_to_log("Expected option [#{list}] was found among multiple selections [#{selected}]. #{desc}")
886
+ else
887
+ failed_to_log("Expected option [#{list}] was not found among multiple selections [#{selected}]. #{desc}")
888
+ end
889
+ end
890
+ end
891
+
892
+ rescue
893
+ failed_to_log("Unable to validate selected option(s): '#{$!}' #{desc}", __LINE__)
894
+ end
895
+
896
+ alias validate_selections validate_selected_options
897
+ alias validate_select_list_selections validate_selected_options
898
+
899
+ def string_contains?(strg, target, desc = '')
900
+ msg = "String '#{strg}' contains '#{target}'."
901
+ msg << " '#{desc}' " if desc.length > 0
902
+ if strg.match(target)
903
+ passed_to_log("#{msg} (#{__LINE__})")
904
+ true
905
+ else
906
+ failed_to_log("#{msg} (#{__LINE__})")
907
+ end
908
+ end
909
+
910
+ alias validate_string string_contains?
911
+ alias validate_string_contains string_contains?
912
+
913
+ def string_does_not_contain?(strg, target, desc = '')
914
+ msg = "String '#{strg}' does not contain '#{target}'."
915
+ msg << " '#{desc}' " if desc.length > 0
916
+ if strg.match(target)
917
+ failed_to_log("#{msg} (#{__LINE__})")
918
+ true
919
+ else
920
+ passed_to_log("#{msg} (#{__LINE__})")
921
+ end
922
+ end
923
+
924
+ alias validate_string_not_contains string_does_not_contain?
925
+ alias validate_string_not_contain string_does_not_contain?
926
+ alias validate_string_does_not_contain string_does_not_contain?
927
+
928
+ def validate_no_text(browser, ptrn, desc = '')
929
+ cls = browser.class.to_s
930
+ cls.gsub!('Watir::', '')
931
+ cls.gsub!('IE', 'Browser')
932
+ msg = "#{cls} does not contain text '#{ptrn}'."
933
+ msg << " #{desc}" if desc.length > 0
934
+ if ptrn.is_a?(Regexp)
935
+ target = ptrn
936
+ else
937
+ target = Regexp.new(Regexp.escape(ptrn))
938
+ end
939
+ browser_text = browser.text
940
+ if browser_text.match(target)
941
+ if validate(browser, @myName, __LINE__)
942
+ failed_to_log("#{msg} [#{browser_text.match(target)[0]}]")
943
+ end
944
+ else
945
+ passed_to_log(msg)
946
+ true
947
+ end
948
+ rescue
949
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
950
+ end
951
+
952
+ def textfield_does_not_equal?(browser, how, what, expected, desc = '')
953
+ msg = "Text field #{how}=>#{what} does not equal '#{expected}'"
954
+ msg << " #{desc}" if desc.length > 0
955
+ if not browser.text_field(how, what).value == expected
956
+ if validate(browser, @myName, __LINE__)
957
+ passed_to_log(msg)
958
+ true
959
+ end
960
+ else
961
+ failed_to_log(msg)
962
+ end
963
+ rescue
964
+ failed_to_log("Unable to validate that #{msg}: '#{$!}'")
965
+ end
966
+
967
+ alias validate_textfield_not_value textfield_does_not_equal?
968
+
969
+ ###################################
970
+ def validate_textfield_not_value_by_name(browser, name, value, desc = '')
971
+ textfield_does_not_equal?(browser, :name, name, value, desc)
972
+ end
973
+
974
+ alias validate_textfield_no_value_by_name validate_textfield_not_value_by_name
975
+
976
+ ###################################
977
+ def validate_textfield_not_value_by_id(browser, id, value, desc = '')
978
+ textfield_does_not_equal?(browser, :id, id, value, desc)
979
+ end
980
+
981
+ alias validate_textfield_no_value_by_id validate_textfield_not_value_by_id
982
+
983
+ def textfield_empty?(browser, how, what, desc = '')
984
+ msg = "Text field #{how}=>#{what} is empty."
985
+ msg << desc if desc.length > 0
986
+ value = browser.text_field(how, what).value
987
+ if value.to_s.length == 0
988
+ if validate(browser, @myName, __LINE__)
989
+ passed_to_log(msg)
990
+ true
991
+ end
992
+ else
993
+ failed_to_log("#{msg} Contains '#{value}'")
994
+ end
995
+ rescue
996
+ failed_to_log("Unable to validate #{msg} '#{$!}'")
997
+ end
998
+
999
+ alias validate_textfield_empty textfield_empty?
1000
+ alias text_field_empty? textfield_empty?
1001
+
1002
+ def validate_textfield_empty_by_name(browser, name, message = '')
1003
+ validate_textfield_empty(browser, :name, name, message)
1004
+ end
1005
+
1006
+ def validate_textfield_empty_by_id(browser, id, message = '')
1007
+ validate_textfield_empty(browser, :id, id, message)
1008
+ end
1009
+
1010
+ def validate_textfield_empty_by_title(browser, title, message = '')
1011
+ validate_textfield_empty(browser, :title, title, message)
1012
+ end
1013
+
1014
+ def textfield_equals?(browser, how, what, expected, desc = '')
1015
+ msg = "Expected '#{expected}' in textfield #{how}=>'#{what}'. #{desc}"
1016
+ actual = browser.text_field(how, what).value
1017
+ if actual.is_a?(Array)
1018
+ actual = actual[0].to_s
1019
+ end
1020
+ #debug_to_report("#{actual.inspect}")
1021
+ #debug_to_report("#{actual}")
1022
+ if actual == expected
1023
+ if validate(browser, @myName, __LINE__)
1024
+ passed_to_log("#{msg}")
1025
+ true
1026
+ end
1027
+ else
1028
+ act_s = actual.strip
1029
+ exp_s = expected.strip
1030
+ if act_s == exp_s
1031
+ if validate(browser, @myName, __LINE__)
1032
+ passed_to_log("#{msg} (stripped)")
1033
+ true
1034
+ end
1035
+ else
1036
+ debug_to_report(
1037
+ "#{__method__} (spaces underscored):\n "+
1038
+ "expected:[#{expected.gsub(' ', '_')}] (#{expected.length})\n "+
1039
+ "actual:[#{actual.gsub(' ', '_')}] (#{actual.length})"
1040
+ )
1041
+ failed_to_log("#{msg}. Found: '#{actual}'")
1042
+ end
1043
+ end
1044
+ rescue
1045
+ failed_to_log("Unable to validate #{msg}: '#{$!}")
1046
+ end
1047
+
1048
+ alias validate_textfield_value textfield_equals?
1049
+ alias text_field_equals? textfield_equals?
1050
+
1051
+ def validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '')
1052
+ desc << " Dollar formatting"
1053
+ if with_cents
1054
+ expected << '.00' if not expected =~ /\.00$/
1055
+ desc << ' without cents.'
1056
+ else
1057
+ expected.gsub!(/\.00$/, '')
1058
+ desc << ' with cents.'
1059
+ end
1060
+ textfield_equals?(browser, how, what, expected, desc)
1061
+ end
1062
+
1063
+ def validate_textfield_value_by_name(browser, name, expected, desc = '')
1064
+ textfield_equals?(browser, :name, name, expected, desc)
1065
+ end
1066
+
1067
+ def validate_textfield_value_by_id(browser, id, expected, desc = '')
1068
+ textfield_equals?(browser, :id, id, expected, desc)
1069
+ end
1070
+
1071
+ def validate_textfield_visible_by_name(browser, strg, desc = '')
1072
+ visible?(browser, :text_field, :name, strg, desc)
1073
+ end
1074
+
1075
+ alias visible_textfield_by_name validate_textfield_visible_by_name
1076
+
1077
+ def validate_textfield_disabled_by_name(browser, strg, desc = '')
1078
+ disabled?(browser, :text_field, :name, strg, desc)
1079
+ end
1080
+
1081
+ alias disabled_textfield_by_name validate_textfield_disabled_by_name
1082
+
1083
+ def validate_textfield_enabled_by_name(browser, strg, desc = '')
1084
+ enabled?(browser, :text_field, :name, strg, desc)
1085
+ end
1086
+
1087
+ alias enabled_textfield_by_name validate_textfield_enabled_by_name
1088
+
1089
+ def validate_textfield_not_visible_by_name(browser, strg, desc = '')
1090
+ not_visible?(browser, :text_field, :name, strg, desc)
1091
+ end
1092
+
1093
+ alias visible_no_textfield_by_name validate_textfield_not_visible_by_name
1094
+
1095
+ def validate_radio_not_set(browser, radio, message)
1096
+ if browser.radio(:id, radio).checked?
1097
+ if validate(browser, @myName, __LINE__)
1098
+ failed_to_log(message + " (#{__LINE__})")
1099
+ end
1100
+ else
1101
+ passed_to_log(message)
1102
+ true
1103
+ end
1104
+ rescue
1105
+ failed_to_log("Unable to validate that radio with id='#{radio} is clear': '#{$!}'. (#{__LINE__})")
1106
+ end
1107
+
1108
+ alias validate_not_radioset validate_radio_not_set
1109
+
1110
+ def radio_is_set?(browser, radio, message)
1111
+ if browser.radio(:id, radio).checked?
1112
+ if validate(browser, @myName, __LINE__)
1113
+ passed_to_log(message)
1114
+ true
1115
+ end
1116
+ else
1117
+ failed_to_log(message + " (#{__LINE__})")
1118
+ end
1119
+ rescue
1120
+ failed_to_log("Unable to validate that radio with id='#{radio} is clear': '#{$!}'. (#{__LINE__})")
1121
+ end
1122
+
1123
+ alias validate_radioset radio_is_set?
1124
+ alias validate_radio_set radio_is_set?
1125
+
1126
+ def validate_radioset_by_name(browser, radio, message)
1127
+ if browser.radio(:name, radio).checked?
1128
+ if validate(browser, @myName, __LINE__)
1129
+ passed_to_log(message)
1130
+ true
1131
+ end
1132
+ else
1133
+ failed_to_log(message + " (#{__LINE__})")
1134
+ end
1135
+ rescue
1136
+ failed_to_log("Unable to validate that radio with name='#{radio} is clear': '#{$!}'. (#{__LINE__})")
1137
+ end
1138
+
1139
+ def checked_by_id?(browser, strg, desc = '')
1140
+ checked?(browser, :id, strg, desc)
1141
+ end
1142
+
1143
+ alias validate_check checked_by_id?
1144
+ alias checkbox_is_checked? checked_by_id?
1145
+
1146
+ def checkbox_is_enabled?(browser, strg, desc = '')
1147
+ enabled?(browser, :checkbox, :id, strg, desc)
1148
+ end
1149
+
1150
+ alias validate_check_enabled checkbox_is_enabled?
1151
+
1152
+ def checkbox_is_disabled?(browser, strg, desc = '')
1153
+ disabled?(browser, :checkbox, :id, strg, desc)
1154
+ end
1155
+
1156
+ alias validate_check_disabled checkbox_is_disabled?
1157
+
1158
+ def validate_check_by_class(browser, strg, desc)
1159
+ checked?(browser, :class, strg, desc)
1160
+ end
1161
+
1162
+ def checkbox_not_checked?(browser, strg, desc)
1163
+ not_checked?(browser, :id, strg, desc)
1164
+ end
1165
+
1166
+ alias validate_not_check checkbox_not_checked?
1167
+
1168
+ def validate_image(browser, source, desc = '', nofail=false)
1169
+ if browser.image(:src, source).exists?
1170
+ if validate(browser, @myName, __LINE__)
1171
+ passed_to_log("Found '#{source}' image. #{desc}")
1172
+ true
1173
+ end
1174
+ else
1175
+ failed_to_log("Did not find '#{source}' image. #{desc} (#{__LINE__})") unless nofail
1176
+ end
1177
+ rescue
1178
+ failed_to_log("Unable to validate that '#{+source}' image appeared in page: '#{$!}'. (#{__LINE__})")
1179
+ end
1180
+
1181
+ end
1182
+ end
1183
+ end
1184
+