awetestlib 0.0.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1508 @@
1
+ module Validations
2
+
3
+ def self.included(mod)
4
+ # puts "RegressionSupport::Validations extended by #{mod}"
5
+ end
6
+
7
+ def modal_exists?(browser, button = nil)
8
+ rtrn = nil
9
+ if @browserAbbrev == 'IE'
10
+ Timeout::timeout(2) do
11
+ begin
12
+ if browser.enabled_popup
13
+ hwnd = browser.enabled_popup(5)
14
+ debug_to_log("Modal popup with handle #{hwnd} found. (#{__LINE__})")
15
+ wc = WinClicker.new
16
+ wc.makeWindowActive(hwnd)
17
+ rtrn = wc.getWindowTitle(hwnd)
18
+ if button
19
+ wc.clickWindowsButton_hWnd(hwnd, button)
20
+ end
21
+ wc = nil
22
+ end
23
+ rescue Timeout::Error
24
+ debug_to_log("No Modal popup found. (#{__LINE__})")
25
+ return rtrn
26
+ end
27
+ return rtrn
28
+ end
29
+ rtrn
30
+ else
31
+ rtrn
32
+ end
33
+ end
34
+
35
+ =begin rdoc
36
+ Verifies health of the browser. Looks for common http and system errors that are unrecoverable and
37
+ attempts to gracefully bail out of the script. Calls rescue_me() when trying to capture the text to filter out
38
+ known false errors and handle container elements that don't respond to the .text method.
39
+ category: bullet-proofing
40
+ tags: system, http, fatal, error
41
+ example: See click()
42
+ related methods: rescue_me()
43
+ =end
44
+ def validate(browser, fileName = '', lnbr = __LINE__, dbg = false)
45
+ debug_to_log("#{__method__} begin") if dbg
46
+ msg = ''
47
+ myOK = true
48
+ if not browser
49
+ msg = "#{fileName}----browser is nil object. (#{lnbr})"
50
+ myOK = false
51
+ elsif not is_browser?(browser)
52
+ msg = "#{fileName}----not a browser. (#{lnbr})"
53
+ debug_to_log(browser.inspect)
54
+ myOK = false
55
+
56
+ else
57
+ if browser.respond_to?(:url)
58
+ if not browser.url == @currentURL
59
+ @currentURL = browser.url
60
+ debug_to_log("Current URL: [#{@currentURL}]")
61
+ # mark_testlevel( "Current URL: [#{@currentURL}]", 1 )
62
+ end
63
+ end
64
+
65
+ if @capture_js_errors
66
+ if browser.respond_to?(:status)
67
+ if browser.status.downcase =~ /errors? on page/ and
68
+ not browser.status.downcase.include?('Waiting for')
69
+ capture_js_error(browser)
70
+ end
71
+ end
72
+ end
73
+
74
+ begin
75
+ browser_text = browser.text.downcase
76
+ rescue => e
77
+ if not rescue_me(e, __method__, "browser.text.downcase", "#{browser.class}", browser)
78
+ debug_to_log("browser.text.downcase in #{__method__} #{browser.class}")
79
+ debug_to_log("#{get_callers}")
80
+ raise e
81
+ else
82
+ return true
83
+ end
84
+ end
85
+
86
+ if browser_text
87
+ if browser_text.match(/unrecognized error condition has occurred/i)
88
+ msg = "#{fileName}----Unrecognized Exception occurred. (#{lnbr})"
89
+ myOK = false
90
+
91
+ elsif browser_text.match(/cannot find server or dns error/i)
92
+ msg = "#{fileName}----Cannot find server error or DNS error. (#{lnbr})"
93
+ myOK = false
94
+
95
+ elsif browser_text.match(/the rpc server is unavailable/i)
96
+ msg = "#{fileName}----RPC server unavailable. (#{lnbr})"
97
+ myOK = false
98
+
99
+ elsif browser_text.match(/404 not found/i) or
100
+ browser_text.match(/the page you were looking for does\s*n[o']t exist/i)
101
+ msg = "#{fileName}----RFC 2068 HTTP/1.1: 404 URI Not Found. (#{lnbr})"
102
+ myOK = false
103
+
104
+ elsif browser_text.match(/we're sorry, but something went wrong/i) or
105
+ browser_text.match(/http status 500/i)
106
+ msg = "#{fileName}----RFC 2068 HTTP/1.1: 500 Internal Server Error. (#{lnbr})"
107
+ myOK = false
108
+
109
+ elsif browser_text.match(/internet explorer cannot display the webpage/i)
110
+ msg = "#{fileName}----Probably RFC 2068 HTTP/1.1: 500 Internal Server Error. (#{lnbr})"
111
+ myOK = false
112
+
113
+ elsif browser_text.match(/503.*service unavailable/i)
114
+ msg = "#{fileName}----RFC 2068 HTTP/1.1: 503 Service Unavailable. (#{lnbr})"
115
+ myOK = false
116
+
117
+ elsif browser_text.match(/java.lang.NullPointerException/i)
118
+ msg = "#{fileName}----java.lang.NullPointerException. (#{lnbr})"
119
+ myOK = false
120
+
121
+ elsif browser_text.match(/due to unscheduled maintenance/i)
122
+ msg = "#{fileName}----Due to unscheduled maintenance. (#{lnbr})"
123
+ myOK = false
124
+
125
+ elsif browser_text.match(/network\s+error\s*(.+)$/i)
126
+ $1.chomp!
127
+ msg = "#{fileName}----Network Error #{$1}. (#{lnbr})"
128
+ myOK = false
129
+
130
+ elsif browser_text.match(/warning: page has expired/i)
131
+ msg = "#{fileName}----Page using information from form has expired. Not automatically resubmitted. (#{lnbr})"
132
+ myOK = false
133
+
134
+ elsif browser_text.match(/no backend server available/i)
135
+ msg = "#{fileName}----Cannot Reach Server (#{lnbr})"
136
+ myOK = false
137
+
138
+ elsif browser_text.match(/sign on\s+.+\s+unsuccessful/i)
139
+ msg = "#{fileName}----Invalid Id or Password (#{lnbr})"
140
+ myOK = false
141
+
142
+ elsif browser_text.match(/you are not authorized/i)
143
+ msg = "#{fileName}----Not authorized to view this page. (#{lnbr})"
144
+ myOK = false
145
+
146
+ elsif browser_text.match(/too many incorrect login attempts have been made/i)
147
+ msg = "#{fileName}----Invalid Id or Password. Too many tries. (#{lnbr})"
148
+ myOK = false
149
+
150
+ elsif browser_text.match(/system error\.\s+an error has occurred/i)
151
+ msg = "#{fileName}----System Error. An error has occurred. Please try again or call the Help Line for assistance. (#{lnbr})"
152
+ myOK = false
153
+
154
+ elsif browser_text.match(/Internal Server failure,\s+NSAPI plugin/i)
155
+ msg = "#{fileName}----Internal Server failure, NSAPI plugin. (#{lnbr})"
156
+ myOK = false
157
+
158
+ elsif browser_text.match(/Error Page/i)
159
+ msg = "#{fileName}----Error Page. (#{lnbr})"
160
+ myOK = false
161
+
162
+ elsif browser_text.match(/The website cannot display the page/i)
163
+ msg = "#{fileName}----HTTP 500. (#{lnbr})"
164
+ myOK = false
165
+
166
+ # elsif browser_text.match(/Insufficient Data/i)
167
+ # msg = "#{fileName}----Insufficient Data. (#{lnbr})"
168
+ # myOK = false
169
+
170
+ elsif browser_text.match(/The timeout period elapsed/i)
171
+ msg = "#{fileName}----Time out period elapsed or server not responding. (#{lnbr})"
172
+ myOK = false
173
+
174
+ elsif browser_text.match(/Unexpected\s+errors*\s+occur+ed\.\s+(?:-+)\s+(.+)/i)
175
+ msg = "#{fileName}----Unexpected errors occurred. #{$2.slice(0, 120)} (#{lnbr})"
176
+ if not browser_text.match(/close the window and try again/i)
177
+ myOK = false
178
+ else
179
+ debug_to_log("#{msg}")
180
+ end
181
+
182
+ elsif browser_text.match(/Server Error in (.+) Application\.\s+(?:-+)\s+(.+)/i)
183
+ msg = "#{fileName}----Server Error in #{1} Application. #{$2.slice(0, 100)} (#{lnbr})"
184
+ myOK = false
185
+
186
+ elsif browser_text.match(/Server Error in (.+) Application\./i)
187
+ msg = "#{fileName}----Server Error in #{1} Application. '#{browser_text.slice(0, 250)}...' (#{lnbr})"
188
+ myOK = false
189
+
190
+ elsif browser_text.match(/An error has occur+ed\. Please contact support/i)
191
+ msg = "#{fileName}----An error has occurred. Please contact support (#{lnbr})"
192
+ myOK = false
193
+
194
+ end
195
+ else
196
+ debug_to_log("browser.text returned nil")
197
+ end
198
+ end
199
+
200
+ if not myOK
201
+ msg << " (#{browser.url})"
202
+ puts msg
203
+ debug_to_log(browser.inspect)
204
+ debug_to_log(browser.text)
205
+ fatal_to_log(msg, lnbr)
206
+ raise(RuntimeError, msg, caller)
207
+ else
208
+ debug_to_log("#{__method__} returning OK") if dbg
209
+ return myOK
210
+ end
211
+
212
+ rescue
213
+ errmsg = $!
214
+ if errmsg.match(msg)
215
+ errmsg = ''
216
+ end
217
+ bail_out(browser, lnbr, "#{msg} #{errmsg}")
218
+ end
219
+
220
+ alias validate_browser validate
221
+
222
+ def validate_message(browser, message)
223
+ if validate(browser, @myName, __LINE__)
224
+ message_to_log(message)
225
+ end
226
+ end
227
+
228
+ ##### begin core validation methods #####
229
+
230
+ def arrays_match?(exp, act, dir, col, org = nil)
231
+ if exp == act
232
+ passed_to_log("Click on #{dir} column '#{col}' produces expected sorted list.")
233
+ true
234
+ else
235
+ failed_to_log("Click on #{dir} column '#{col}' fails to produce expected sorted list.")
236
+ debug_to_log("Original order ['#{org.join("', '")}']") if org
237
+ debug_to_log("Expected order ['#{exp.join("', '")}']")
238
+ debug_to_log(" Actual order ['#{act.join("', '")}']")
239
+ end
240
+ end
241
+
242
+ alias arrays_match arrays_match?
243
+
244
+ def enabled?(browser, element, how, what, desc = '')
245
+ msg = "#{element.to_s.titlecase} by #{how}=>'#{what}' is enabled. #{desc}"
246
+ case element
247
+ when :textfield, :textarea, :text_area, :text_field
248
+ rtrn = browser.text_field(how, what).enabled? and not browser.text_field(how, what).readonly?
249
+ when :select_list, :selectlist
250
+ rtrn = browser.select_list(how, what).enabled?
251
+ else
252
+ rtrn = browser.element(how, what).enabled?
253
+ end
254
+ if rtrn
255
+ passed_to_log("#{msg}")
256
+ true
257
+ else
258
+ failed_to_log("#{msg}")
259
+ end
260
+ rtrn
261
+ rescue
262
+ failed_to_log("#Unable to verify that #{msg}': '#{$!}")
263
+ end
264
+
265
+ alias validate_enabled enabled?
266
+
267
+ def date_string_equals?(actual, expected, desc = '', fail_on_format = true)
268
+ rtrn = false
269
+ msg = "Assert actual date '#{actual}' equals expected date '#{expected}'. #{desc} "
270
+ if actual == expected
271
+ rtrn = true
272
+ elsif DateTime.parse(actual).to_s == DateTime.parse(expected).to_s
273
+ msg << " with different formatting. "
274
+ if not fail_on_format
275
+ rtrn = true
276
+ end
277
+ end
278
+ msg << " #{desc}" if desc.length > 0
279
+ if rtrn
280
+ passed_to_log("#{msg}")
281
+ else
282
+ failed_to_log("#{msg}")
283
+ end
284
+ rtrn
285
+ rescue
286
+ failed_to_log("Unable to #{msg}. #{$!}")
287
+ end
288
+
289
+ def disabled?(browser, element, how, what, desc = '')
290
+ msg = "#{element.to_s.titlecase} by #{how}=>'#{what}' is disabled. #{desc}"
291
+ case element
292
+ when :textfield, :textarea, :text_area, :text_field
293
+ rtrn = browser.text_field(how, what).disabled? ||
294
+ browser.text_field(how, what).readonly?
295
+ when :select_list, :selectlist
296
+ rtrn = browser.select_list(how, what).disabled?
297
+ when :checkbox
298
+ rtrn = browser.checkbox(how, what).disabled?
299
+ when :radio
300
+ rtrn = browser.radio(how, what).disabled?
301
+ when :button
302
+ rtrn = browser.button(how, value).disabled?
303
+ else
304
+ msg = "#{__method__} does not yet support '#{element}'. #{desc}"
305
+ debug_to_log(msg)
306
+ raise msg
307
+ end
308
+ if rtrn
309
+ passed_to_log("#{msg}")
310
+ true
311
+ else
312
+ failed_to_log("#{msg}")
313
+ end
314
+ rtrn
315
+ rescue
316
+ failed_to_log("#Unable to verify that #{msg}: '#{$!}'")
317
+ end
318
+
319
+ alias validate_not_enabled disabled?
320
+ alias validate_disabled disabled?
321
+
322
+ def verify_text_in_table_with_text(table, text, value)
323
+ msg = "Table :id=>#{table.id} with text '#{text} contains '#{value}."
324
+ index = get_index_of_row_with_text(table, text)
325
+ if table[index].text =~ value
326
+ passed_to_log(msg)
327
+ true
328
+ else
329
+ failed_to_log(msg)
330
+ end
331
+ end
332
+
333
+ def visible?(browser, element, how, what, desc = '')
334
+ msg = "#{element.to_s.titlecase} #{how}=>'#{what}' is visible. #{desc}"
335
+ rtrn = false
336
+ case how
337
+ when :index
338
+ target = get_element(browser, element, how, what)
339
+ if target.visible?
340
+ rtrn = true
341
+ end
342
+ else
343
+ if browser.element(how, what).visible?
344
+ rtrn = true
345
+ end
346
+ end
347
+ if rtrn
348
+ passed_to_log("#{msg}")
349
+ else
350
+ failed_to_log("#{msg}")
351
+ end
352
+ rtrn
353
+ rescue
354
+ failed_to_log("Unable to verify that #{msg}': '#{$!}'")
355
+ end
356
+
357
+ alias validate_visible visible?
358
+
359
+ def not_visible?(browser, element, how, what, desc = '')
360
+ msg = "#{element.to_s.titlecase} #{how}=>'#{what}' is not visible. #{desc}"
361
+ rtrn = false
362
+ case how
363
+ when :index
364
+ target = get_element(browser, element, how, what)
365
+ if not target.visible?
366
+ rtrn = true
367
+ end
368
+ else
369
+ if not browser.element(how, what).visible?
370
+ rtrn = true
371
+ end
372
+ end
373
+ if rtrn
374
+ passed_to_log("#{msg}")
375
+ else
376
+ failed_to_log("#{msg}")
377
+ end
378
+ rtrn
379
+ rescue
380
+ failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}")
381
+ end
382
+
383
+ alias validate_not_visible not_visible?
384
+
385
+ def checked?(browser, how, what, desc = '')
386
+ msg = "Checkbox #{how}=>#{what} is checked."
387
+ msg << " #{desc}" if desc.length > 0
388
+ if browser.checkbox(how, what).checked?
389
+ if validate(browser, @myName, __LINE__)
390
+ passed_to_log(msg)
391
+ true
392
+ end
393
+ else
394
+ failed_to_log(msg)
395
+ end
396
+ rescue
397
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
398
+ end
399
+
400
+ alias checkbox_checked? checked?
401
+ alias checkbox_set? checked?
402
+
403
+ def exists?(browser, element, how, what, value = nil, desc = '')
404
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
405
+ msg << "and value=>'#{value}' " if value
406
+ msg << "exists"
407
+ e = get_element(browser, element, how, what, value)
408
+ if e
409
+ passed_to_log("#{msg}? #{desc}")
410
+ true
411
+ else
412
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
413
+ end
414
+ rescue
415
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
416
+ end
417
+
418
+ def does_not_exist?(browser, element, how, what, value = nil, desc = '')
419
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
420
+ msg << "and value=>'#{value}' " if value
421
+ msg << "does not exist."
422
+ msg << " #{desc}" if desc.length > 0
423
+ if browser.element(how, what).exists?
424
+ failed_to_log(msg)
425
+ else
426
+ passed_to_log(msg)
427
+ true
428
+ end
429
+ rescue
430
+ failed_to_log("Unable to verify that #{msg}': '#{$!}' #{desc}")
431
+ end
432
+
433
+ alias not_exist? does_not_exist?
434
+
435
+ def set?(browser, how, what, desc = '', no_fail = false)
436
+ msg = "Radio #{how}=>#{what} is selected."
437
+ msg << " #{desc}" if desc.length > 0
438
+ if browser.radio(how, what).set?
439
+ if validate(browser, @myName, __LINE__)
440
+ passed_to_log(msg)
441
+ true
442
+ end
443
+ else
444
+ if no_fail
445
+ passed_to_log("Radio #{how}=>#{what} is not selected.")
446
+ else
447
+ failed_to_log(msg)
448
+ end
449
+ end
450
+ rescue
451
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
452
+ end
453
+
454
+ alias radio_set? set?
455
+ alias radio_checked? set?
456
+ alias radio_selected? set?
457
+
458
+ def select_list_includes?(browser, how, what, option)
459
+ select_list = browser.select_list(how, what)
460
+ options = select_list.options
461
+ if option
462
+ if options.include?(option)
463
+ passed_to_log("Select list options contain option '#{option}'.")
464
+ true
465
+ else
466
+ failed_to_log("Select list options #{options} do not contain option '#{option}'.")
467
+ nil
468
+ end
469
+ end
470
+ rescue
471
+ failed_to_log("Unable to verify select_list contains option '#{option}': '#{$!}'", __LINE__)
472
+ end
473
+
474
+ alias validate_select_list_contains select_list_includes?
475
+ alias select_list_contains? select_list_includes?
476
+
477
+ def string_equals?(actual, target, desc = '')
478
+ msg = "Assert actual '#{actual}' equals expected '#{target}'. #{desc} "
479
+ if actual == target
480
+ passed_to_log("#{msg}")
481
+ true
482
+ else
483
+ failed_to_log("#{msg}")
484
+ end
485
+ rescue
486
+ failed_to_log("Unable to #{msg}. #{$!}")
487
+ end
488
+
489
+ alias validate_string_equal string_equals?
490
+ alias validate_string_equals string_equals?
491
+ alias text_equals string_equals?
492
+ alias text_equals? string_equals?
493
+
494
+ def read_only?(browser, element, how, what, value = nil, desc = '')
495
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
496
+ msg << "and value=>'#{value}' " if value
497
+ msg << "read only"
498
+ e = get_element(browser, element, how, what, value)
499
+ if e
500
+ if e.readonly?
501
+ passed_to_log("#{msg}? #{desc}")
502
+ true
503
+ else
504
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
505
+ end
506
+ end
507
+ rescue
508
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
509
+ end
510
+
511
+ def not_read_only?(browser, element, how, what, value = nil, desc = '')
512
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
513
+ msg << "and value=>'#{value}' " if value
514
+ msg << "is not read only"
515
+ e = get_element(browser, element, how, what, value)
516
+ if e
517
+ if e.readonly?
518
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
519
+ else
520
+ passed_to_log("#{msg}? #{desc}")
521
+ true
522
+ end
523
+ end
524
+ rescue
525
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
526
+ end
527
+
528
+ def ready?(browser, element, how, what, value = '', desc = '')
529
+ msg = "#{element.to_s.titlecase} with #{how}=>'#{what}' "
530
+ msg << "and value=>'#{value}' " if value
531
+ e = get_element(browser, element, how, what, value)
532
+ if e and e.enabled?
533
+ passed_to_log("#{msg}? #{desc}")
534
+ true
535
+ else
536
+ failed_to_log("#{msg}? #{desc} [#{get_callers(1)}]")
537
+ end
538
+ rescue
539
+ failed_to_log("Unable to determine if #{msg}. #{desc} '#{$!}' [#{get_callers(1)}]")
540
+ end
541
+
542
+ ##### end core validation methods #####
543
+
544
+ ##### begin methods using @ai #####
545
+
546
+ def window_exists?(title)
547
+ title = translate_popup_title(title)
548
+ if @ai.WinExists(title) == 1
549
+ passed_to_log("Window title:'#{title}' exists")
550
+ true
551
+ else
552
+ failed_to_log("Window title:'#{title}' does not exist")
553
+ end
554
+ end
555
+
556
+ alias window_exists window_exists?
557
+
558
+ def window_does_not_exist?(title)
559
+ title = translate_popup_title(title)
560
+ if @ai.WinExists(title) == 1
561
+ failed_to_log("Window title:'#{title}' exists")
562
+ else
563
+ passed_to_log("Window title:'#{title}' does not exist")
564
+ true
565
+ end
566
+ end
567
+
568
+ alias window_no_exists window_does_not_exist?
569
+
570
+ ##### end methods using @ai #####
571
+
572
+ ##### backward compatible methods #####
573
+
574
+ def validate_link_exist(browser, link, logit = true, desc = '')
575
+ exists?(browser, :link, :text, link, nil, desc)
576
+ end
577
+
578
+ def link_not_exist?(browser, link, desc = '')
579
+ does_not_exist?(browser, :link, :text, link, nil, desc)
580
+ end
581
+
582
+ alias validate_link_not_exist link_not_exist?
583
+
584
+ def validate_div_visible_by_id(browser, strg)
585
+ visible?(browser, :div, :id, strg)
586
+ end
587
+
588
+ def validate_div_not_visible_by_id(browser, strg, desc = '')
589
+ not_visible?(browser, :div, :id, strg, desc)
590
+ end
591
+
592
+ ##### end backward compatible methods #####
593
+
594
+
595
+ # TODO Deprecated: all util1 methods should be catching
596
+ # this issue
597
+ def link_enabled?(browser, strg)
598
+ count = string_count_in_string(browser.text, strg)
599
+ if count > 0
600
+ if browser.link(:text, strg).enabled?
601
+ if validate(browser, @myName, __LINE__)
602
+ passed_to_log(strg + " is enabled. (#{__LINE__})")
603
+ true
604
+ end
605
+ else
606
+ failed_to_log(strg + " is not enabled.")
607
+ end
608
+ else
609
+ failed_to_log("Link '#{strg.to_s}' (by :text) not found. Cannot validate if enabled. (#{__LINE__}) " + desc)
610
+ end
611
+ rescue
612
+ failed_to_log("Unable to validate that link with :text '#{text}' is enabled: '#{$!}'. (#{__LINE__})")
613
+ debug_to_log("#{strg} appears #{count} times in browser.text.")
614
+ end
615
+
616
+ alias validate_link_enabled link_enabled?
617
+
618
+ # TODO Deprecated: all util1 methods should be catching
619
+ # this issue
620
+ def link_disabled?(browser, strg)
621
+ count = string_count_in_string(browser.text, strg)
622
+ if count > 0
623
+ if browser.link(:text, strg).enabled?
624
+ if validate(browser, @myName, __LINE__)
625
+ failed_to_log(strg + " is enabled. (#{__LINE__})")
626
+ end
627
+ else
628
+ passed_to_log(strg + " is not enabled.")
629
+ true
630
+ end
631
+ else
632
+ failed_to_log("Link '#{strg.to_s}' (by :text) not found. Cannot validate if disabled. (#{__LINE__}) " + desc)
633
+ end
634
+ rescue
635
+ failed_to_log("Unable to validate that link with :text '#{text}' is enabled: '#{$!}'. (#{__LINE__})")
636
+ debug_to_log("#{strg} appears #{count} times in browser.text.")
637
+ end
638
+
639
+ alias validate_link_not_enabled link_disabled?
640
+
641
+ def popup_exists?(popup, message=nil)
642
+ if not message
643
+ message = "Popup: #{popup.title}"
644
+ end
645
+ if is_browser?(popup)
646
+ passed_to_log("#{message}: found.")
647
+ debug_to_log("\n"+popup.text+"\n")
648
+ true
649
+ else
650
+ failed_to_log("#{message}: not found." + " (#{__LINE__})")
651
+ end
652
+ rescue
653
+ failed_to_log("Unable to validate existence of popup: '#{$!}'. (#{__LINE__})")
654
+ end
655
+
656
+ alias popup_exist popup_exists?
657
+ alias popup_exists popup_exists?
658
+ alias popup_exist? popup_exists?
659
+ alias iepopup_exist popup_exists?
660
+ alias iepopup_exist? popup_exists?
661
+ alias iepopup_exists popup_exists?
662
+ alias iepopup_exists? popup_exists?
663
+
664
+ def validate_drag_drop(err, tol, exp, act)
665
+ ary = [false, "failed, expected: #{exp}, actual: #{act}, err: #{err}"]
666
+ if err == 0
667
+ ary = [true, 'succeeded ']
668
+ elsif err.abs <= tol
669
+ ary = [true, "within tolerance (+-#{tol}px) "]
670
+ end
671
+ ary
672
+ end
673
+
674
+ def validate_list(browser, listId, text, message)
675
+ message_to_log("Method validate_list() is deprecated: use validate_list_by_xxx instead")
676
+ validate_list_by_id(browser, listId, text, message)
677
+ end
678
+
679
+ #Validate select list contains text
680
+ def validate_list_by_id(browser, strg, text, message, select_if_present=true)
681
+ if browser.select_list(:id, strg).exists?
682
+ select_list = browser.select_list(:id, strg)
683
+ if select_list.include?(text)
684
+ if select_if_present
685
+ if select_option_by_id_and_option_text(browser, strg, text)
686
+ if validate(browser, @myName, __LINE__)
687
+ passed_to_log(message)
688
+ true
689
+ end
690
+ else
691
+ failed_to_log(message + " (#{__LINE__})")
692
+ end
693
+ else
694
+ if validate(browser, @myName, __LINE__)
695
+ passed_to_log(message)
696
+ true
697
+ end
698
+ end
699
+ else
700
+ failed_to_log(message + " Not found. (#{__LINE__})")
701
+ end
702
+ else
703
+ failed_to_log("Select list with id='#{strg} not found. (#{__LINE__})")
704
+ end
705
+ rescue
706
+ failed_to_log("Unable to validate selectlist with id='#{strg}: '#{$!}'. (#{__LINE__})")
707
+ end
708
+
709
+ #Validate select list contains text
710
+ def validate_list_by_name(browser, strg, text, message, select_if_present=true)
711
+ if browser.select_list(:name, strg).exists?
712
+ select_list = browser.select_list(:name, strg)
713
+ if select_list.include?(text)
714
+ if select_if_present
715
+ if select_option_by_name_and_option_text(browser, strg, text)
716
+ if validate(browser, @myName, __LINE__)
717
+ passed_to_log(message)
718
+ true
719
+ end
720
+ else
721
+ failed_to_log(message + " (#{__LINE__})")
722
+ end
723
+ else
724
+ if validate(browser, @myName, __LINE__)
725
+ passed_to_log(message)
726
+ true
727
+ end
728
+ end
729
+ else
730
+ failed_to_log(message + " Not found. (#{__LINE__})")
731
+ end
732
+ else
733
+ failed_to_log("Select list with name='#{strg} not found. (#{__LINE__})")
734
+ end
735
+ rescue
736
+ failed_to_log("Unable to validate that '#{text}' appeared in select list with name='#{strg}: '#{$!}'. (#{__LINE__})")
737
+ end
738
+
739
+ #Validate select list does not contain text
740
+ def validate_no_list(browser, id, text, message)
741
+ if browser.select_list(:id, id).includes?(text)
742
+ if validate(browser, @myName, __LINE__)
743
+ failed_to_log(message + " (#{__LINE__})")
744
+ end
745
+ else
746
+ passed_to_log(message + " (#{__LINE__})")
747
+ true
748
+ end
749
+ rescue
750
+ failed_to_log("Unable to validate that '#{text}' did not in select list with name='#{listName}: '#{$!}'. (#{__LINE__})")
751
+ end
752
+
753
+ def validate_resize(d, err, tol, min, act)
754
+ ary = [false, "failed, actual #{act} err #{err}"]
755
+ if err == 0
756
+ ary = [true, 'succeeded ']
757
+ #TODO need to find way to calculate this adjustment
758
+ elsif d <= min + 4
759
+ ary = [true, "reached minimum (#{min}) "]
760
+ elsif err.abs <= tol
761
+ ary = [true, "within tolerance (+-#{tol}px) "]
762
+ end
763
+ ary
764
+ end
765
+
766
+ alias validate_move validate_resize
767
+
768
+ def validate_text(browser, ptrn, desc = '', skip_fail = false, skip_sleep = false)
769
+ cls = browser.class.to_s
770
+ cls.gsub!('Watir::', '')
771
+ cls.gsub!('IE', 'Browser')
772
+ msg = "#{cls} text contains '#{ptrn}'."
773
+ msg << " #{desc}" if desc.length > 0
774
+ if ptrn.is_a?(Regexp)
775
+ target = ptrn
776
+ else
777
+ target = Regexp.new(Regexp.escape(ptrn))
778
+ end
779
+ sleep_for(2) unless skip_sleep
780
+ myText = browser.text
781
+ if not myText.match(target)
782
+ sleep_for(2) unless skip_sleep #TODO try a wait_until here
783
+ myText = browser.text
784
+ end
785
+ if myText.match(target)
786
+ #if myText.match(ptrn)
787
+ if validate(browser, @myName, __LINE__)
788
+ passed_to_log("#{msg}")
789
+ true
790
+ end
791
+ else
792
+ if skip_fail
793
+ debug_to_log("#{cls} text does not contain the text: '#{ptrn}'. #{desc}")
794
+ else
795
+ failed_to_log("#{msg}")
796
+ end
797
+ #debug_to_log("\n#{myText}")
798
+ end
799
+ rescue
800
+ failed_to_log("Unable to validate #{msg} '#{$!}'")
801
+ end
802
+
803
+ alias validate_link validate_text
804
+
805
+ def text_in_element_equals?(browser, element, how, what, expected, desc = '')
806
+ msg = "Expected exact text '#{expected}' in #{element} :#{how}=>#{what}."
807
+ msg << " #{desc}" if desc.length > 0
808
+ text = ''
809
+ who = browser.element(how, what)
810
+ if who
811
+ text = who.text
812
+ if text == expected
813
+ passed_to_log(msg)
814
+ true
815
+ else
816
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
817
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
818
+ failed_to_log("#{msg} Found '#{text}'.")
819
+ end
820
+ end
821
+ rescue
822
+ failed_to_log("Unable to verify #{msg} '#{$!}'")
823
+ end
824
+
825
+ def text_in_span_equals?(browser, how, what, expected, desc = '')
826
+ text_in_element_equals?(browser, :span, how, what, expected, desc)
827
+ end
828
+
829
+ def element_contains_text?(browser, element, how, what, expected, desc = '')
830
+ msg = "Expected #{element} :{how}=>#{what} to contain text '#{expected}'."
831
+ msg << " #{desc}" if desc.length > 0
832
+ who = browser.element(how, what)
833
+ if who
834
+ text = who.text
835
+ if expected and expected.length > 0
836
+ rgx = Regexp.new(Regexp.escape(expected))
837
+ if text =~ rgx
838
+ passed_to_log(msg)
839
+ true
840
+ else
841
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
842
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
843
+ failed_to_log("#{msg} Found '#{text}'. #{desc}")
844
+ end
845
+ else
846
+ if text.length > 0
847
+ debug_to_log("exp: [#{expected.gsub(' ', '^')}]")
848
+ debug_to_log("act: [#{text.gsub(' ', '^')}]")
849
+ failed_to_log("#{msg} Found '#{text}'. #{desc}")
850
+ else
851
+ passed_to_log(msg)
852
+ true
853
+ end
854
+ end
855
+ end
856
+ rescue
857
+ failed_to_log("Unable to verify #{msg} '#{$!}'")
858
+ end
859
+
860
+ def span_contains_text?(browser, how, what, expected, desc = '')
861
+ element_contains_text?(browser, :span, how, what, expected, desc)
862
+ end
863
+
864
+ alias valid_text_in_span span_contains_text?
865
+
866
+ def validate_text_in_span_by_id(browser, id, strg = '', desc = '')
867
+ element_contains_text?(browser, :span, :id, id, strg, desc)
868
+ end
869
+
870
+ def validate_url(browser, url, message = '')
871
+ if browser.url.to_s.match(url)
872
+ if validate(browser, @myName, __LINE__)
873
+ passed_to_log('Found "'+url.to_s+'" ' + message)
874
+ true
875
+ end
876
+ else
877
+ failed_to_log('Did not find "'+url.to_s+'" ' + message + " (#{__LINE__})")
878
+ end
879
+ rescue
880
+ failed_to_log("Unable to validate that current url is '#{url}': '#{$!}'. (#{__LINE__})")
881
+ end
882
+
883
+ def validate_select_list(browser, how, what, opt_type, list = nil, multiple = false, ignore = ['Select One'], limit = 5)
884
+ mark_testlevel("#{__method__.to_s.titleize} (#{how}=>#{what})", 2)
885
+ ok = true
886
+ select_list = browser.select_list(how, what)
887
+ options = select_list.options
888
+ if list
889
+ if options == list
890
+ passed_to_log("Select list options list equals expected list #{list}")
891
+ else
892
+ debug_to_report("actual:\n#{nice_array(options, true)}")
893
+ debug_to_report("expected:\n#{nice_array(list, true)}")
894
+ failed_to_log("Select list options list #{nice_array(options, true)} "+
895
+ "does not equal expected list #{nice_array(list, true)}")
896
+ end
897
+ end
898
+
899
+ #single selections
900
+ cnt = 0
901
+ options.each do |opt|
902
+ if not ignore.include?(opt)
903
+ cnt += 1
904
+ ok = select_option(select_list, opt_type, opt)
905
+ break if not ok
906
+ select_list.clear
907
+ break if limit > 0 and cnt >= limit
908
+ end
909
+ end
910
+
911
+ sleep_for(0.5)
912
+ select_list.clear
913
+ if ok and multiple
914
+ if options.length > 2
915
+ targets = list.slice(1, 2)
916
+ select_option(select_list, opt_type, options[1])
917
+ select_option(select_list, opt_type, options[2])
918
+ selected = select_list.selected_options
919
+ if selected == targets
920
+ passed_to_log("Select list selected options equals expected #{targets}")
921
+ else
922
+ failed_to_log("Select list selected options #{selected} does not equal expected list #{targets.to_a}")
923
+ end
924
+ else
925
+ debug_to_log("Too few options to test multiple selection (need 2 or more): '#{options}", __LINE__)
926
+ end
927
+ end
928
+ rescue
929
+ failed_to_log("Unable to validate select_list: '#{$!}'", __LINE__)
930
+ end
931
+
932
+
933
+ def validate_select_list_contents(browser, how, what, list)
934
+ mark_testlevel("#{__method__.to_s.titleize} (#{what})", 2)
935
+ select_list = browser.select_list(how, what)
936
+ options = select_list.options
937
+ if list
938
+ if options == list
939
+ passed_to_log("Select list options list equals expected list #{list}")
940
+ options
941
+ else
942
+ failed_to_log("Select list options list #{options} does not equal expected list #{list}")
943
+ nil
944
+ end
945
+ end
946
+ rescue
947
+ failed_to_log("Unable to validate select_list contents: '#{$!}'", __LINE__)
948
+ end
949
+
950
+ def validate_selected_options(browser, how, what, list, desc = '')
951
+ select_list = browser.select_list(how, what)
952
+ selected = select_list.selected_options.sort
953
+ if list.is_a?(Array)
954
+ if selected == list.sort
955
+ passed_to_log("Expected options [#{list.sort}] are selected [#{selected}]. #{desc}")
956
+ else
957
+ failed_to_log("Selected options [#{selected}] do not match expected [#{list.sort}]. #{desc}")
958
+ true
959
+ end
960
+ else
961
+ if selected.length == 1
962
+ if selected[0] =~ /#{list}/
963
+ passed_to_log("Expected option [#{list}] was selected. #{desc}")
964
+ true
965
+ else
966
+ failed_to_log("Expected option [#{list}] was not selected. Found [#{selected}]. #{desc}")
967
+ end
968
+ else
969
+ if selected.include?(list)
970
+ failed_to_log("Expected option [#{list}] was found among multiple selections [#{selected}]. #{desc}")
971
+ else
972
+ failed_to_log("Expected option [#{list}] was not found among multiple selections [#{selected}]. #{desc}")
973
+ end
974
+ end
975
+ end
976
+
977
+ rescue
978
+ failed_to_log("Unable to validate selected option(s): '#{$!}' #{desc}", __LINE__)
979
+ end
980
+
981
+ alias validate_selections validate_selected_options
982
+ alias validate_select_list_selections validate_selected_options
983
+
984
+ def validate_string_contains(strg, target, desc = '')
985
+ msg = "Assert '#{strg}' contains '#{target}'? #{desc} "
986
+ if strg.match(target)
987
+ passed_to_log("#{msg} (#{__LINE__})")
988
+ true
989
+ else
990
+ failed_to_log("#{msg} (#{__LINE__})")
991
+ end
992
+ end
993
+
994
+ alias validate_string validate_string_contains
995
+
996
+ def validate_string_does_not_contain(strg, target, message = '')
997
+ msg = "Assert '#{strg}' does not contain '#{target}'? #{message} "
998
+ if strg.match(target)
999
+ failed_to_log("#{msg} (#{__LINE__})")
1000
+ true
1001
+ else
1002
+ passed_to_log("#{msg} (#{__LINE__})")
1003
+ end
1004
+ end
1005
+
1006
+ alias validate_string_not_contains validate_string_does_not_contain
1007
+ alias validate_string_not_contain validate_string_does_not_contain
1008
+
1009
+ def validate_string_does_not_equal(strg, target, message = '')
1010
+ msg = "Assert '#{strg}' does not equal '#{target}'? #{message} "
1011
+ if strg == target
1012
+ failed_to_log("#{msg} (#{__LINE__})")
1013
+ true
1014
+ else
1015
+ passed_to_log("#{msg} (#{__LINE__})")
1016
+ end
1017
+ end
1018
+
1019
+ alias validate_string_not_equal validate_string_does_not_equal
1020
+
1021
+ def validate_no_text(browser, ptrn, desc = '')
1022
+ cls = browser.class.to_s
1023
+ cls.gsub!('Watir::', '')
1024
+ cls.gsub!('IE', 'Browser')
1025
+ msg = "#{cls} does not contain text '#{ptrn}'."
1026
+ msg << " #{desc}" if desc.length > 0
1027
+ if ptrn.is_a?(Regexp)
1028
+ target = ptrn
1029
+ else
1030
+ target = Regexp.new(Regexp.escape(ptrn))
1031
+ end
1032
+ browser_text = browser.text
1033
+ if browser_text.match(target)
1034
+ if validate(browser, @myName, __LINE__)
1035
+ failed_to_log("#{msg} [#{browser_text.match(target)[0]}]")
1036
+ end
1037
+ else
1038
+ passed_to_log(msg)
1039
+ true
1040
+ end
1041
+ rescue
1042
+ failed_to_log("Unable to validate #{msg}: '#{$!}'")
1043
+ end
1044
+
1045
+ def validate_textfield_not_value(browser, how, what, value, desc = '')
1046
+ msg = "Text field #{how}=>#{what} does not contain '#{value}'"
1047
+ msg << " #{desc}" if desc.length > 0
1048
+ if not browser.text_field(how, what).value == value
1049
+ if validate(browser, @myName, __LINE__)
1050
+ passed_to_log(msg)
1051
+ true
1052
+ end
1053
+ else
1054
+ failed_to_log(msg)
1055
+ end
1056
+ rescue
1057
+ failed_to_log("Unable to validate that #{msg}: '#{$!}'")
1058
+ end
1059
+
1060
+ ###################################
1061
+ def validate_textfield_not_value_by_name(browser, name, value, desc = '')
1062
+ validate_textfield_not_value(browser, :name, name, value, desc)
1063
+ end
1064
+
1065
+ alias validate_textfield_no_value_by_name validate_textfield_not_value_by_name
1066
+
1067
+ ###################################
1068
+ def validate_textfield_not_value_by_id(browser, id, value, desc = '')
1069
+ validate_textfield_not_value(browser, :id, id, value, desc)
1070
+ end
1071
+
1072
+ alias validate_textfield_no_value_by_id validate_textfield_not_value_by_id
1073
+
1074
+ def validate_textfield_empty(browser, how, what, desc = '')
1075
+ msg = "Text field #{how}=>#{what} is empty."
1076
+ msg << desc if desc.length > 0
1077
+ value = browser.text_field(how, what).value
1078
+ if value.to_s.length == 0
1079
+ if validate(browser, @myName, __LINE__)
1080
+ passed_to_log(msg)
1081
+ true
1082
+ end
1083
+ else
1084
+ failed_to_log("#{msg} Contains '#{value}'")
1085
+ end
1086
+ rescue
1087
+ failed_to_log("Unable to validate #{msg} '#{$!}'")
1088
+ end
1089
+
1090
+ def validate_textfield_empty_by_name(browser, name, message = '')
1091
+ validate_textfield_empty(browser, :name, name, message)
1092
+ end
1093
+
1094
+ def validate_textfield_empty_by_id(browser, id, message = '')
1095
+ validate_textfield_empty(browser, :id, id, message)
1096
+ end
1097
+
1098
+ def validate_textfield_empty_by_title(browser, title, message = '')
1099
+ validate_textfield_empty(browser, :title, title, message)
1100
+ end
1101
+
1102
+ def validate_textfield_value(browser, how, what, expected, desc = '')
1103
+ msg = "Expected '#{expected}' in textfield #{how}=>'#{what}'. #{desc}"
1104
+ actual = browser.text_field(how, what).value
1105
+ if actual.is_a?(Array)
1106
+ actual = actual[0].to_s
1107
+ end
1108
+ #debug_to_report("#{actual.inspect}")
1109
+ #debug_to_report("#{actual}")
1110
+ if actual == expected
1111
+ if validate(browser, @myName, __LINE__)
1112
+ passed_to_log("#{msg}")
1113
+ true
1114
+ end
1115
+ else
1116
+ act_s = actual.strip
1117
+ exp_s = expected.strip
1118
+ if act_s == exp_s
1119
+ if validate(browser, @myName, __LINE__)
1120
+ passed_to_log("#{msg} (stripped)")
1121
+ true
1122
+ end
1123
+ else
1124
+ debug_to_report(
1125
+ "#{__method__} (spaces underscored):\n "+
1126
+ "expected:[#{expected.gsub(' ', '_')}] (#{expected.length})\n "+
1127
+ "actual:[#{actual.gsub(' ', '_')}] (#{actual.length})"
1128
+ )
1129
+ failed_to_log("#{msg}. Found: '#{actual}'")
1130
+ end
1131
+ end
1132
+ rescue
1133
+ failed_to_log("Unable to validate #{msg}: '#{$!}")
1134
+ end
1135
+
1136
+ def validate_textfield_dollar_value(browser, how, what, expected, with_cents = true, desc = '')
1137
+ desc << " Dollar formatting"
1138
+ if with_cents
1139
+ expected << '.00' if not expected =~ /\.00$/
1140
+ desc << ' without cents.'
1141
+ else
1142
+ expected.gsub!(/\.00$/, '')
1143
+ desc << ' with cents.'
1144
+ end
1145
+ validate_textfield_value(browser, how, what, expected, desc)
1146
+ end
1147
+
1148
+ def validate_textfield_value_by_name(browser, name, expected, desc = '')
1149
+ validate_textfield_value(browser, :name, name, expected, desc)
1150
+ end
1151
+
1152
+ def validate_textfield_value_by_id(browser, id, expected, desc = '')
1153
+ validate_textfield_value(browser, :id, id, expected, desc)
1154
+ end
1155
+
1156
+ def validate_textfield_visible_by_name(browser, strg, desc = '')
1157
+ sleep_for(1)
1158
+ if browser.text_field(:name, strg).visible?
1159
+ passed_to_log("Textfield with :name='#{strg}' is visible as expected. #{desc}")
1160
+ true
1161
+ else
1162
+ failed_to_log("Textfield with :name='#{strg}' is not visible. #{desc}")
1163
+ end
1164
+ rescue
1165
+ failed_to_log("Unable to validate textfield with :name=>'#{strg}' is visible. #{desc}: '#{$!}'. (#{__LINE__})")
1166
+ end
1167
+
1168
+ alias visible_textfield_by_name validate_textfield_visible_by_name
1169
+
1170
+ def validate_textfield_disabled_by_name(browser, strg, desc = '')
1171
+ sleep_for(1)
1172
+ if browser.text_field(:name, strg).disabled?
1173
+ passed_to_log("Textfield with :name='#{strg}' is disabled as expected. #{desc}")
1174
+ true
1175
+ else
1176
+ failed_to_log("Textfield with :name='#{strg}' is not disabled. #{desc}")
1177
+ end
1178
+ rescue
1179
+ failed_to_log("Unable to validate textfield with :name=>'#{strg}' is disabled. #{desc}: '#{$!}'. (#{__LINE__})")
1180
+ end
1181
+
1182
+ alias disabled_textfield_by_name validate_textfield_disabled_by_name
1183
+
1184
+ def validate_textfield_enabled_by_name(browser, strg, desc = '')
1185
+ sleep_for(1)
1186
+ if browser.text_field(:name, strg).enabled?
1187
+ passed_to_log("Textfield with :name='#{strg}' is enabled as expected. #{desc}")
1188
+ true
1189
+ else
1190
+ failed_to_log("Textfield with :name='#{strg}' is not enabled. #{desc}")
1191
+ end
1192
+ rescue
1193
+ failed_to_log("Unable to validate textfield with :name=>'#{strg}' is enabled. #{desc}: '#{$!}'. (#{__LINE__})")
1194
+ end
1195
+
1196
+ alias enabled_textfield_by_name validate_textfield_enabled_by_name
1197
+
1198
+ def validate_textfield_not_visible_by_name(browser, strg, desc = '')
1199
+ sleep_for(1)
1200
+ if browser.text_field(:name, strg).visible?
1201
+ failed_to_log("Textfield with :name='#{strg}' is visible. #{desc}")
1202
+ true
1203
+ else
1204
+ passed_to_log("Textfield with :name='#{strg}' is not visible as expected. #{desc}")
1205
+ end
1206
+ rescue
1207
+ failed_to_log("Unable to validate textfield with :name=>'#{strg}' is not visible. #{desc}: '#{$!}'. (#{__LINE__})")
1208
+ end
1209
+
1210
+ alias visible_no_textfield_by_name validate_textfield_not_visible_by_name
1211
+
1212
+ def validate_radio_not_set(browser, radio, message)
1213
+ if browser.radio(:id, radio).checked?
1214
+ if validate(browser, @myName, __LINE__)
1215
+ failed_to_log(message + " (#{__LINE__})")
1216
+ end
1217
+ else
1218
+ passed_to_log(message)
1219
+ true
1220
+ end
1221
+ rescue
1222
+ failed_to_log("Unable to validate that radio with id='#{radio} is clear': '#{$!}'. (#{__LINE__})")
1223
+ end
1224
+
1225
+ alias validate_not_radioset validate_radio_not_set
1226
+
1227
+ def radio_is_set?(browser, radio, message)
1228
+ if browser.radio(:id, radio).checked?
1229
+ if validate(browser, @myName, __LINE__)
1230
+ passed_to_log(message)
1231
+ true
1232
+ end
1233
+ else
1234
+ failed_to_log(message + " (#{__LINE__})")
1235
+ end
1236
+ rescue
1237
+ failed_to_log("Unable to validate that radio with id='#{radio} is clear': '#{$!}'. (#{__LINE__})")
1238
+ end
1239
+
1240
+ alias validate_radioset radio_is_set?
1241
+ alias validate_radio_set radio_is_set?
1242
+
1243
+ def validate_radioset_by_name(browser, radio, message)
1244
+ if browser.radio(:name, radio).checked?
1245
+ if validate(browser, @myName, __LINE__)
1246
+ passed_to_log(message)
1247
+ true
1248
+ end
1249
+ else
1250
+ failed_to_log(message + " (#{__LINE__})")
1251
+ end
1252
+ rescue
1253
+ failed_to_log("Unable to validate that radio with name='#{radio} is clear': '#{$!}'. (#{__LINE__})")
1254
+ end
1255
+
1256
+ def checked_by_id?(browser, strg, desc = '')
1257
+ checked?(browser, :id, strg, desc)
1258
+ end
1259
+
1260
+ alias validate_check checked_by_id?
1261
+ alias checkbox_is_checked? checked_by_id?
1262
+
1263
+ def checkbox_is_enabled?(browser, strg, message)
1264
+ if browser.checkbox(:id, strg).enabled?
1265
+ passed_to_log(message, __LINE__)
1266
+ true
1267
+ else
1268
+ failed_to_log("Not Enabled. (#{__LINE__})")
1269
+ end
1270
+ rescue
1271
+ failed_to_log("Unable to validate check box with id=#{strg}: '#{$!}'. (#{__LINE__})")
1272
+ end
1273
+
1274
+ alias validate_check_enabled checkbox_is_enabled?
1275
+
1276
+ def checkbox_is_disabled?(browser, strg, message)
1277
+ if browser.checkbox(:id, strg).disabled?
1278
+ passed_to_log(message, __LINE__)
1279
+ true
1280
+ else
1281
+ failed_to_log("Not Disabled. (#{__LINE__})")
1282
+ end
1283
+ rescue
1284
+ failed_to_log("Unable to validate check box with id=#{strg}: '#{$!}'. (#{__LINE__})")
1285
+ end
1286
+
1287
+ alias validate_check_disabled checkbox_is_disabled?
1288
+
1289
+ def validate_check_by_class(browser, strg, message)
1290
+ if browser.radio(:class, strg).checked?
1291
+ if validate(browser, @myName, __LINE__)
1292
+ passed_to_log(message)
1293
+ true
1294
+ end
1295
+ else
1296
+ failed_to_log(message + " (#{__LINE__})")
1297
+ end
1298
+ rescue
1299
+ failed_to_log("Unable to validate check box with id=#{strg}: '#{$!}'. (#{__LINE__})")
1300
+ end
1301
+
1302
+ def checkbox_not_checked?(browser, strg, message)
1303
+ if browser.radio(:id, strg).checked?
1304
+ if validate(browser, @myName, __LINE__)
1305
+ failed_to_log(message + " (#{__LINE__})")
1306
+ end
1307
+ else
1308
+ passed_to_log(message)
1309
+ true
1310
+ end
1311
+ rescue
1312
+ failed_to_log("Unable to validate radio with id=#{strg}: '#{$!}'. (#{__LINE__})")
1313
+ end
1314
+
1315
+ alias validate_not_check checkbox_not_checked?
1316
+
1317
+ def validate_image(browser, source, desc = '', nofail=false)
1318
+ if browser.image(:src, source).exists?
1319
+ if validate(browser, @myName, __LINE__)
1320
+ passed_to_log("Found '#{source}' image. #{desc}")
1321
+ true
1322
+ end
1323
+ else
1324
+ failed_to_log("Did not find '#{source}' image. #{desc} (#{__LINE__})") unless nofail
1325
+ end
1326
+ rescue
1327
+ failed_to_log("Unable to validate that '#{+source}' image appeared in page: '#{$!}'. (#{__LINE__})")
1328
+ end
1329
+
1330
+ #TODO unstub
1331
+ def verify_column_hidden(browser, panel, table_index, column_name)
1332
+ passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.")
1333
+ return true
1334
+ # id = @column_data_display_ids[column_name]
1335
+ # ok = false
1336
+
1337
+ # row = panel.tables[2][3]
1338
+
1339
+ # row.each do |cell|
1340
+ ## strg = cell.to_s
1341
+ ## insp = cell.inspect
1342
+ ## ole = cell.ole_object
1343
+ ## anId = cell.attribute_value(:id)
1344
+ # text = cell.text
1345
+ # if text =~ /#{id}/
1346
+ # if cell.to_s =~ /hidden/
1347
+ # passed_to_log( "Column '#{column_name}' is hidden.")
1348
+ # else
1349
+ # failed_to_log( "Column '#{column_name}' is not hidden.")
1350
+ # end
1351
+ # ok = true
1352
+ # end
1353
+ # end
1354
+ # if not ok
1355
+ # failed_to_log( "Column '#{column_name}' not found.")
1356
+ # end
1357
+ # rescue
1358
+ # failed_to_log("Unable to verify column '#{column_name}' is hidden: '#{$!}' (#{__LINE__})")
1359
+ end
1360
+
1361
+ #TODO unstub
1362
+ def verify_column_hidden_temp_ff(browser, data_index, row_index, column_name)
1363
+ passed_to_log("TEST STUBBED: Column '#{column_name}' is hidden.")
1364
+ return true
1365
+
1366
+ row = browser.tables[data_index][row_index]
1367
+ # debug_to_log( "#{row.to_a}")
1368
+ #TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes
1369
+ act_ary = get_row_cells_text_as_array(row)
1370
+
1371
+ if not act_ary.include?(column_name)
1372
+ passed_to_log("Column '#{column_name}' is hidden.")
1373
+ else
1374
+ failed_to_log("Column '#{column_name}' is not hidden.")
1375
+ end
1376
+ end
1377
+
1378
+ #TODO unstub
1379
+ def verify_column_visible_temp_ff(browser, data_index, row_index, column_name)
1380
+ passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.")
1381
+ return true
1382
+
1383
+ row = browser.tables[data_index][row_index]
1384
+ #TODO cells are all still there in the row. Need to check for clue to hidden/visible in other tag attributes
1385
+ act_ary = get_row_cells_text_as_array(row)
1386
+
1387
+ if act_ary.include?(column_name)
1388
+ passed_to_log("Column '#{column_name}' is visible.")
1389
+ else
1390
+ failed_to_log("Column '#{column_name}' is not visible.")
1391
+ end
1392
+ end
1393
+
1394
+ #TODO unstub
1395
+ def verify_column_visible(browser, panel, table_index, column_name)
1396
+
1397
+ passed_to_log("TEST STUBBED: Column '#{column_name}' is visible.")
1398
+ return true
1399
+
1400
+ # id = @column_data_display_ids[column_name]
1401
+ # ok = false
1402
+ # row = panel.tables[table_index][1]
1403
+ # row.each do |cell|
1404
+ # if cell.id == id
1405
+ # if not cell.to_s =~ /hidden/
1406
+ # passed_to_log("Column '#{column_name}' is visible.")
1407
+ # else
1408
+ # failed_to_log("Column '#{column_name}' is not visible.")
1409
+ # end
1410
+ # ok = true
1411
+ # end
1412
+ # end
1413
+ # if not ok
1414
+ # failed_to_log("Column '#{column_name}' not found.")
1415
+ # end
1416
+ rescue
1417
+ failed_to_log("Unable to verify column '#{column_name} is visible': '#{$!}' (#{__LINE__})")
1418
+ end
1419
+
1420
+ def verify_column_order(browser, table_index, row_index, exp_ary)
1421
+ mark_testlevel("Verify Column Order", 2)
1422
+ row = browser.tables[table_index][row_index]
1423
+ act_ary = get_row_cells_text_as_array(row)
1424
+
1425
+ if exp_ary == act_ary
1426
+ passed_to_log("Column order [#{act_ary.join(', ')}] appeared as expected.")
1427
+ else
1428
+ failed_to_log("Column order [#{act_ary.join(', ')}] not as expected [#{exp_ary.join(', ')}].")
1429
+ end
1430
+ sleep_for(1)
1431
+ end
1432
+
1433
+ def verify_column_sort(browser, nc_element, strg, table_index, column_index=nil)
1434
+ mark_testlevel("Verify Column Sort '#{strg}'", 3)
1435
+ if not column_index
1436
+ column_index = get_index_for_column_head(nc_element, table_index, strg)
1437
+ end
1438
+
1439
+ if column_index
1440
+ bfr_ary = fetch_array_for_table_column(nc_element, table_index, column_index)
1441
+ if strg =~ /date/i
1442
+ exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) }
1443
+ else
1444
+ exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') }
1445
+ end
1446
+
1447
+ if click_text(browser, strg)
1448
+ if column_index
1449
+ sleep_for(2.5)
1450
+ else
1451
+ sleep_for(1)
1452
+ end
1453
+ act_ary = fetch_array_for_table_column(nc_element, table_index, column_index)
1454
+
1455
+ if exp_ary == act_ary
1456
+ passed_to_log("Click on column '#{strg}' produces expected sorted list.")
1457
+ true
1458
+ else
1459
+ failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.")
1460
+ debug_to_log("Original order ['#{bfr_ary.join("', '")}']")
1461
+ debug_to_log("Expected order ['#{exp_ary.join("', '")}']")
1462
+ debug_to_log(" Actual order ['#{act_ary.join("', '")}']")
1463
+ end
1464
+ end
1465
+ else
1466
+ failed_to_log("Unable to locate column index for '#{strg}' to verify sort.")
1467
+ end
1468
+ rescue
1469
+ failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}")
1470
+ end
1471
+
1472
+ def verify_column_sort_temp_ff(browser, strg, table_index, column_index=nil)
1473
+ mark_testlevel("Verify Column Sort '#{strg}'", 3)
1474
+
1475
+ if not column_index
1476
+ column_index = get_index_for_column_head(browser, table_index, strg)
1477
+ end
1478
+
1479
+ if column_index
1480
+ bfr_ary = fetch_array_for_table_column(browser, table_index, column_index)
1481
+ if strg =~ /date/i
1482
+ exp_ary = bfr_ary.sort { |x, y| Date.parse(x) <=> Date.parse(y) }
1483
+ else
1484
+ exp_ary = bfr_ary.sort { |x, y| x.gsub(',', '') <=> y.gsub(',', '') }
1485
+ end
1486
+
1487
+ if click_text(browser, strg)
1488
+ sleep_for(3)
1489
+ act_ary = fetch_array_for_table_column(browser, table_index, column_index)
1490
+
1491
+ if exp_ary == act_ary
1492
+ passed_to_log("Click on column '#{strg}' produces expected sorted list.")
1493
+ true
1494
+ else
1495
+ failed_to_log("Click on column '#{strg}' fails to produce expected sorted list.")
1496
+ debug_to_log("Original order ['#{bfr_ary.join("', '")}']")
1497
+ debug_to_log("Expected order ['#{exp_ary.join("', '")}']")
1498
+ debug_to_log(" Actual order ['#{act_ary.join("', '")}']")
1499
+ end
1500
+ end
1501
+ else
1502
+ failed_to_log("Unable to locate column index for '#{strg}' to verify sort.")
1503
+ end
1504
+ rescue
1505
+ failed_to_log("Unable to verify sort on column '#{strg}'. #{$!}")
1506
+ end
1507
+
1508
+ end