awetestlib 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/README.md +55 -0
  2. data/awetestlib.windows.gemspec +1 -1
  3. data/awetestlib_osx.gemspec +1 -0
  4. data/bin/AutoItX3.dll +0 -0
  5. data/bin/awetestlib +23 -3
  6. data/bin/awetestlib-helpers.rb +39 -0
  7. data/bin/awetestlib-netbeans-setup.rb +39 -0
  8. data/bin/awetestlib-regression-setup.rb +16 -0
  9. data/bin/awetestlib-rubymine-setup.rb +33 -0
  10. data/images/logo.png +0 -0
  11. data/lib/awetestlib.rb +4 -4
  12. data/lib/awetestlib/html_report.rb +171 -0
  13. data/lib/{regression → awetestlib}/logging.rb +13 -46
  14. data/lib/awetestlib/regression/browser.rb +1233 -0
  15. data/lib/awetestlib/regression/drag_and_drop.rb +379 -0
  16. data/lib/awetestlib/regression/find.rb +431 -0
  17. data/lib/awetestlib/regression/legacy.rb +45 -0
  18. data/lib/awetestlib/regression/page_data.rb +190 -0
  19. data/lib/awetestlib/regression/runner.rb +307 -0
  20. data/lib/awetestlib/regression/tables.rb +491 -0
  21. data/lib/awetestlib/regression/user_input.rb +1256 -0
  22. data/lib/awetestlib/regression/utilities.rb +895 -0
  23. data/lib/awetestlib/regression/validations.rb +1184 -0
  24. data/lib/awetestlib/regression/waits.rb +391 -0
  25. data/lib/awetestlib/runner.rb +16 -0
  26. data/lib/version.rb +2 -2
  27. data/setup_samples/sample_netbeans/demo.rb +86 -0
  28. data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -0
  29. data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -0
  30. data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +1 -0
  31. data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -0
  32. data/setup_samples/sample_netbeans/nbproject/project.properties +5 -0
  33. data/setup_samples/sample_netbeans/nbproject/project.xml +13 -0
  34. data/setup_samples/sample_rubymine/.idea/.name +1 -0
  35. data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -0
  36. data/setup_samples/sample_rubymine/.idea/misc.xml +5 -0
  37. data/setup_samples/sample_rubymine/.idea/modules.xml +9 -0
  38. data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -0
  39. data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +5 -0
  40. data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -0
  41. data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -0
  42. data/setup_samples/sample_rubymine/demo.rb +86 -0
  43. metadata +64 -17
  44. data/lib/regression/browser.rb +0 -1259
  45. data/lib/regression/drag_and_drop.rb +0 -374
  46. data/lib/regression/find.rb +0 -426
  47. data/lib/regression/legacy.rb +0 -40
  48. data/lib/regression/page_data.rb +0 -185
  49. data/lib/regression/runner.rb +0 -278
  50. data/lib/regression/tables.rb +0 -486
  51. data/lib/regression/user_input.rb +0 -1255
  52. data/lib/regression/utilities.rb +0 -891
  53. data/lib/regression/validations.rb +0 -1179
  54. data/lib/regression/waits.rb +0 -387
@@ -0,0 +1,1256 @@
1
+ module Awetestlib
2
+ module Regression
3
+ module UserInput
4
+
5
+ =begin rdoc
6
+ :category: A_rdoc_test
7
+ Click a specific DOM element by one of its attributes and that attribute's value.
8
+
9
+ _Parameters_::
10
+
11
+ *browser* - a reference to the browser window or container element to be tested
12
+
13
+ *element* - the kind of element to click. Must be one of the elements recognized by Watir.
14
+ Some common values are :link, :button, :image, :div, :span.
15
+
16
+ *how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
17
+ Common values: :text, :id, :title, :name, :class, :href (:link only)
18
+
19
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
20
+
21
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
22
+
23
+ _Example_
24
+
25
+ # html for a link element:
26
+ # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
27
+ click(browser, :link, :text, 'Pickaxe')
28
+
29
+ =end
30
+
31
+ def click(browser, element, how, what, desc = '')
32
+ #debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
33
+ msg = "Click #{element} :#{how}=>'#{what}'"
34
+ msg << ", '#{desc}'" if desc.length > 0
35
+ msg1 = "#{element}(#{how}, '#{what}')"
36
+ begin
37
+ case element
38
+ when :link
39
+ browser.link(how, what).click
40
+ when :button
41
+ browser.button(how, what).click
42
+ when :image
43
+ browser.image(how, what).click
44
+ when :radio
45
+ case how
46
+ when :index
47
+ set_radio_by_index(browser, what, desc)
48
+ else
49
+ browser.radio(how, what).set
50
+ end
51
+ when :span
52
+ browser.span(how, what).click
53
+ when :div
54
+ browser.div(how, what).click
55
+ when :cell
56
+ browser.cell(how, what).click
57
+ else
58
+ browser.element(how, what).click
59
+ end
60
+ end
61
+ if validate(browser, @myName, __LINE__)
62
+ passed_to_log(msg)
63
+ true
64
+ end
65
+ rescue
66
+ failed_to_log("Unable to #{msg}. '#{$!}'")
67
+ end
68
+
69
+ =begin rdoc
70
+ :category: A_rdoc_test
71
+ Click a specific DOM element by one of its attributes and that attribute's value and
72
+ do not wait for the browser to finish reloading. Used when a modal popup or alert is expected. Allows the script
73
+ to keep running so the popup can be handled.
74
+
75
+ _Parameters_::
76
+
77
+ *browser* - a reference to the browser window to be tested
78
+
79
+ *element* - the kind of element to click. Must be one of the elements recognized by Watir.
80
+ Some common values are :link, :button, :image, :div, :span.
81
+
82
+ *how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
83
+ Common values: :text, :id, :title, :name, :class, :href (:link only)
84
+
85
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
86
+
87
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
88
+
89
+ _Example_
90
+
91
+ # html for a link element:
92
+ # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
93
+ click_no_wait(browser, :link, :text, 'Pickaxe')
94
+
95
+ =end
96
+
97
+ def click_no_wait(browser, element, how, what, desc = '')
98
+ debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
99
+ msg = "Click no wait #{element} :#{how}=>'#{what}'"
100
+ msg << ", '#{desc}'" if desc.length > 0
101
+ msg1 = "#{element}(#{how}, '#{what}'"
102
+ begin
103
+ case element
104
+ when :link
105
+ browser.link(how, what).click_no_wait
106
+ when :button
107
+ browser.button(how, what).click_no_wait
108
+ when :image
109
+ browser.image(how, what).click_no_wait
110
+ when :radio
111
+ case how
112
+ when :index
113
+ set_radio_no_wait_by_index(browser, what, desc)
114
+ else
115
+ browser.radio(how, what).click_no_wait
116
+ end
117
+ when :span
118
+ browser.span(how, what).click_no_wait
119
+ when :div
120
+ browser.div(how, what).click_no_wait
121
+ when :checkbox
122
+ browser.checkbox(how, what).click_no_wait
123
+ when :cell
124
+ browser.cell(how, what).click_no_wait
125
+ else
126
+ browser.element(how, what).click_no_wait
127
+ end
128
+ rescue => e
129
+ if not rescue_me(e, __method__, "browser(#{msg1}').click_no_wait", "#{browser.class}")
130
+ raise e
131
+ end
132
+ end
133
+ if validate(browser, @myName, __LINE__)
134
+ passed_to_log(msg)
135
+ true
136
+ end
137
+ rescue
138
+ failed_to_log("Unable to #{msg} '#{$!}'")
139
+ sleep_for(1)
140
+ end
141
+
142
+ # :category: User Input
143
+ def click_button_by_id(browser, strg, desc = '')
144
+ click(browser, :button, :id, strg, desc)
145
+ end
146
+
147
+ # :category: User Input
148
+ def click_link_by_index(browser, strg, desc = '')
149
+ click(browser, :link, :index, strg, desc)
150
+ end
151
+
152
+ # :category: User Input
153
+ def click_link_by_href(browser, strg, desc = '')
154
+ click(browser, :link, :href, strg, desc)
155
+ end
156
+
157
+ alias click_href click_link_by_href
158
+ # :category: User Input
159
+ def click_link_no_wait_by_href(browser, strg, desc = '')
160
+ click_no_wait(browser, :link, :href, strg, desc)
161
+ end
162
+
163
+ alias click_href_no_wait click_link_no_wait_by_href
164
+ # :category: User Input
165
+ def click_button_by_index(browser, index, desc = '')
166
+ click(browser, :button, :index, index, desc)
167
+ end
168
+
169
+ # :category: User Input
170
+ def click_button_by_name(browser, strg, desc = '')
171
+ click(browser, :button, :name, strg, desc)
172
+ end
173
+
174
+ # :category: User Input
175
+ def click_button_by_text(browser, strg, desc = '')
176
+ click(browser, :button, :text, strg, desc)
177
+ end
178
+
179
+ # :category: User Input
180
+ def click_button_by_class(browser, strg, desc = '')
181
+ click(browser, :button, :class, strg, desc)
182
+ end
183
+
184
+ # :category: User Input
185
+ def click_button_no_wait_by_id(browser, strg, desc = '')
186
+ click_no_wait(browser, :button, :id, strg, desc)
187
+ end
188
+
189
+ alias click_button_by_id_no_wait click_button_no_wait_by_id
190
+ # :category: User Input
191
+ def click_button_no_wait_by_name(browser, strg, desc = '')
192
+ click_no_wait(browser, :button, :name, strg, desc)
193
+ end
194
+
195
+ # :category: User Input
196
+ def click_button_no_wait_by_class(browser, strg, desc = '')
197
+ click_no_wait(browser, :button, :class, strg, desc)
198
+ end
199
+
200
+ alias click_button_by_class_no_wait click_button_no_wait_by_class
201
+ # :category: User Input
202
+ def click_button_by_value(browser, strg, desc = '')
203
+ click(browser, :button, :value, strg, desc)
204
+ end
205
+
206
+ # :category: User Input
207
+ def click_button_by_title(browser, strg, desc = '')
208
+ click(browser, :button, :title, strg, desc)
209
+ end
210
+
211
+ # :category: User Input
212
+ def click_button_by_xpath_and_id(browser, strg, desc = '')
213
+ msg = "Click button by xpath and id '#{strg}' #{desc}"
214
+ if browser.button(:xpath, "//a[@id = '#{strg}']").click
215
+ passed_to_log(msg)
216
+ true
217
+ else
218
+ failed_to_log(msg)
219
+ end
220
+ rescue
221
+ failed_to_log("Unable to click button by xpath and id '#{strg}' #{desc} '#{$!}' (#{__LINE__})")
222
+ end
223
+
224
+ alias click_button_by_xpath click_button_by_xpath_and_id
225
+
226
+ =begin rdoc
227
+ :category: A_rdoc_test
228
+ Click a link identified by the value in its id attribute. Calls click()
229
+
230
+ _Parameters_::
231
+
232
+ *browser* - a reference to the browser window to be tested
233
+
234
+ *strg* - a string or a regular expression to be found in the id attribute that uniquely identifies the element.
235
+
236
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
237
+
238
+
239
+ _Example_
240
+
241
+ # html for a link element:
242
+ # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
243
+ click_link_by_text(browser, 'Pickaxe', 'Open the page for the Pickaxe book')
244
+
245
+ =end
246
+
247
+ def click_link_by_id(browser, strg, desc = '')
248
+ click(browser, :link, :id, strg, desc)
249
+ end
250
+
251
+ # :category: A_rdoc_test
252
+ alias click_id click_link_by_id
253
+
254
+ # :category: User Input
255
+ def click_link_by_name(browser, strg, desc = '')
256
+ click(browser, :link, :name, strg, desc)
257
+ end
258
+
259
+ alias click_name click_link_by_name
260
+ # :category: User Input
261
+ def click_link_by_xpath_and_id(browser, strg, desc = '')
262
+ msg = "Click link by xpath and id '#{strg}' #{desc}"
263
+ if browser.link(:xpath, "//a[@id = '#{strg}']").click
264
+ passed_to_log(msg)
265
+ true
266
+ else
267
+ failed_to_log(msg)
268
+ end
269
+ rescue
270
+ failed_to_log("Unable click on link by xpath and id '#{strg}' #{desc} '#{$!}' (#{__LINE__})")
271
+ end
272
+
273
+ alias click_link_by_xpath click_link_by_xpath_and_id
274
+
275
+ # :category: User Input
276
+ def click_link_no_wait_by_id(browser, strg, desc = '')
277
+ click_no_wait(browser, :link, :id, strg, desc)
278
+ end
279
+
280
+ alias click_no_wait_id click_link_no_wait_by_id
281
+ alias click_no_wait_by_id click_link_no_wait_by_id
282
+ alias click_id_no_wait click_link_no_wait_by_id
283
+ alias click_no_wait_link_by_id click_link_no_wait_by_id
284
+
285
+ # :category: User Input
286
+ def click_file_field_by_id(browser, strg, desc = '')
287
+ click(browser, :file_field, :id, strg, desc)
288
+ end
289
+
290
+ # :category: User Input
291
+ def click_img_by_alt(browser, strg, desc = '')
292
+ click(browser, :image, :alt, strg, desc)
293
+ end
294
+
295
+ # :category: User Input
296
+ def click_img_by_title(browser, strg, desc = '')
297
+ click(browser, :image, :title, strg, desc)
298
+ end
299
+
300
+ # :category: User Input
301
+ def click_img_by_xpath_and_name(browser, strg, desc = '')
302
+ msg = "Click image by xpath where name='#{strg}' #{desc}"
303
+ if browser.link(:xpath, "//input[@name = '#{strg}']").click
304
+ passed_to_log(msg)
305
+ true
306
+ else
307
+ failed_to_log(msg)
308
+ end
309
+ rescue
310
+ failed_to_log("Unable to click image by xpath where name='#{strg}' #{desc} '#{$!}'")
311
+ end
312
+
313
+ alias click_img_by_xpath click_img_by_xpath_and_name
314
+ alias click_image_by_xpath click_img_by_xpath_and_name
315
+ alias click_image_by_xpath_and_name click_img_by_xpath_and_name
316
+
317
+ # :category: User Input
318
+ def click_img_no_wait_by_alt(browser, strg, desc = '')
319
+ click_no_wait(browser, :image, :alt, strg, desc)
320
+ end
321
+
322
+ alias click_img_by_alt_no_wait click_img_no_wait_by_alt
323
+ # :category: User Input
324
+ def click_img_by_src(browser, strg, desc = '')
325
+ click(browser, :image, :src, strg, desc)
326
+ end
327
+
328
+ # :category: User Input
329
+ def click_img_by_src_and_index(browser, strg, index, desc = '')
330
+ msg = "Click image by src='#{strg}' and index=#{index}"
331
+ msg << " #{desc}" if desc.length > 0
332
+ browser.image(:src => strg, :index => index).click
333
+ if validate(browser, @myName, __LINE__)
334
+ passed_to_log(msg)
335
+ true
336
+ end
337
+ rescue
338
+ failed_to_log("Unable to #{msg} '#{$!}'")
339
+ end
340
+
341
+ # :category: User Input
342
+ def click_link_by_value(browser, strg, desc = '')
343
+ click(browser, :link, :value, strg, desc)
344
+ end
345
+
346
+ =begin rdoc
347
+ :category: A_rdoc_test
348
+ Click a link identified by the value in its text attribute. Calls click()
349
+
350
+ _Parameters_::
351
+
352
+ *browser* - a reference to the browser window to be tested
353
+
354
+ *strg* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
355
+
356
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
357
+
358
+
359
+ _Example_
360
+
361
+ # html for a link element:
362
+ # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
363
+ click_link_by_text(browser, 'Pickaxe', 'Open the page for the Pickaxe book')
364
+
365
+ =end
366
+
367
+ def click_link_by_text(browser, strg, desc = '')
368
+ click(browser, :link, :text, strg, desc)
369
+ end
370
+
371
+ alias click_link click_link_by_text
372
+ # :category: A_rdoc_test
373
+ alias click_text click_link_by_text
374
+ alias click_js_button click_link_by_text
375
+
376
+ # :category: User Input
377
+ def click_link_by_class(browser, strg, desc = '')
378
+ click(browser, :link, :class, strg, desc)
379
+ end
380
+
381
+ alias click_class click_link_by_class
382
+
383
+ # :category: User Input
384
+ def click_button_no_wait_by_text(browser, strg, desc = '')
385
+ click_no_wait(browser, :button, :text, strg, desc)
386
+ end
387
+
388
+ # :category: User Input
389
+ def click_button_no_wait_by_value(browser, strg, desc = '')
390
+ click_no_wait(browser, :button, :value, strg, desc)
391
+ end
392
+
393
+ # :category: User Input
394
+ def click_link_by_name_no_wait(browser, strg, desc = '')
395
+ click_no_wait(browser, :link, :name, strg, desc)
396
+ end
397
+
398
+ alias click_no_wait_name click_link_by_name_no_wait
399
+ alias click_name_no_wait click_link_by_name_no_wait
400
+
401
+ # :category: User Input
402
+ def click_link_by_text_no_wait(browser, strg, desc = '')
403
+ click_no_wait(browser, :link, :text, strg, desc)
404
+ end
405
+
406
+ alias click_no_wait_text click_link_by_text_no_wait
407
+ alias click_text_no_wait click_link_by_text_no_wait
408
+
409
+ # :category: User Input
410
+ def click_span_by_text(browser, strg, desc = '')
411
+ if not desc and not strg.match(/Save|Open|Close|Submit|Cancel/)
412
+ desc = 'to navigate to selection'
413
+ end
414
+ msg = "Click span containing text '#{strg}'."
415
+ msg << " #{desc}" if desc.length > 0
416
+ if validate(browser, @myName, __LINE__)
417
+ passed_to_log("#{msg}")
418
+ end
419
+ rescue
420
+ failed_to_log("Unable to #{msg}: '#{$!}'")
421
+ end
422
+
423
+ # TODO no logging yet. slow.# :category: User Input
424
+ def click_span_with_text(browser, trgt, desc = '')
425
+ msg = "Find and click span containing text '#{trgt}'."
426
+ msg << " #{desc}" if desc.length > 0
427
+ spans = browser.spans
428
+ x = 0
429
+ spans.each do |span|
430
+ x += 1
431
+ debug_to_log("Span #{x}: #{span.text}")
432
+ aText = span.text
433
+ if aText and aText.size > 0
434
+ if aText =~ /#{trgt}/
435
+ break
436
+ end
437
+ end
438
+ end
439
+ spans[x].click
440
+ end
441
+
442
+ # :category: User Input
443
+ def click_link_by_title(browser, strg, desc = '')
444
+ click(browser, :link, :title, strg, desc)
445
+ end
446
+
447
+ alias click_title click_link_by_title
448
+ # :category: User Input
449
+ def click_title_no_wait(browser, strg, desc = '')
450
+ click_no_wait(browser, :link, :title, strg, desc)
451
+ end
452
+
453
+ # :category: User Input
454
+ def click_table_row_with_text_by_id(browser, ptrn, strg, column = nil)
455
+ msg = "id=#{ptrn} row with text='#{strg}"
456
+ table = get_table_by_id(browser, /#{ptrn}/)
457
+ if table
458
+ index = get_index_of_row_with_text(table, strg, column)
459
+ if index
460
+ table[index].click
461
+ if validate(browser, @myName, __LINE__)
462
+ passed_to_log("Click #{msg} row index=#{index}.")
463
+ index
464
+ end
465
+ else
466
+ failed_to_log("Table #{msg} not found to click.")
467
+ end
468
+ else
469
+ failed_to_log("Table id=#{ptrn} not found.")
470
+ end
471
+ rescue
472
+ failed_to_log("Unable to click table #{msg}: '#{$!}' (#{__LINE__}) ")
473
+ end
474
+
475
+ # :category: User Input
476
+ def click_table_row_with_text_by_index(browser, idx, strg, column = nil)
477
+ msg = "index=#{idx} row with text='#{strg}"
478
+ table = get_table_by_index(browser, idx)
479
+ if table
480
+ index = get_index_of_row_with_text(table, strg, column)
481
+ if index
482
+ table[index].click
483
+ if validate(browser, @myName, __LINE__)
484
+ passed_to_log("Click #{msg} row index=#{index}.")
485
+ index
486
+ end
487
+ else
488
+ failed_to_log("Table #{msg} not found to click.")
489
+ end
490
+ else
491
+ failed_to_log("Table id=#{ptrn} not found.")
492
+ end
493
+ rescue
494
+ failed_to_log("Unable to click table #{msg}: '#{$!}' (#{__LINE__}) ")
495
+ end
496
+
497
+ def double_click_table_row_with_text_by_id(browser, ptrn, strg, column = nil)
498
+ msg = "id=#{ptrn} row with text='#{strg}"
499
+ table = get_table_by_id(browser, /#{ptrn}/)
500
+ if table
501
+ index = get_index_of_row_with_text(table, strg, column)
502
+ if index
503
+ table[index].fire_event('ondblclick')
504
+ if validate(browser, @myName, __LINE__)
505
+ passed_to_log("Double click #{msg} row index=#{index}.")
506
+ index
507
+ end
508
+ else
509
+ failed_to_log("Table #{msg} not found to double click.")
510
+ end
511
+ else
512
+ failed_to_log("Table id=#{ptrn} not found.")
513
+ end
514
+ rescue
515
+ failed_to_log("Unable to double click table #{msg}: '#{$!}' (#{__LINE__}) ")
516
+ end
517
+
518
+ def double_click_table_row_with_text_by_index(browser, idx, strg, column = nil)
519
+ msg = "index=#{idx} row with text='#{strg}"
520
+ table = get_table_by_index(browser, idx)
521
+ if table
522
+ index = get_index_of_row_with_text(table, strg, column)
523
+ if index
524
+ row = table[index]
525
+ table[index].fire_event('ondblclick')
526
+ row.fire_event('ondblclick')
527
+ if validate(browser, @myName, __LINE__)
528
+ passed_to_log("Double click #{msg} row index=#{index}.")
529
+ index
530
+ end
531
+ else
532
+ failed_to_log("Table #{msg} not found to double click.")
533
+ end
534
+ else
535
+ failed_to_log("Table id=#{ptrn} not found.")
536
+ end
537
+ rescue
538
+ failed_to_log("Unable to double click table #{msg}: '#{$!}' (#{__LINE__}) ")
539
+ end
540
+
541
+ def click_popup_button(title, button, waitTime= 9, user_input=nil)
542
+ #TODO: is winclicker still viable/available?
543
+ wc = WinClicker.new
544
+ if wc.clickWindowsButton(title, button, waitTime)
545
+ passed_to_log("Window '#{title}' button '#{button}' found and clicked.")
546
+ true
547
+ else
548
+ failed_to_log("Window '#{title}' button '#{button}' not found. (#{__LINE__})")
549
+ end
550
+ wc = nil
551
+ # get a handle if one exists
552
+ # hwnd = $ie.enabled_popup(waitTime)
553
+ # if (hwnd) # yes there is a popup
554
+ # w = WinClicker.new
555
+ # if ( user_input )
556
+ # w.setTextValueForFileNameField( hwnd, "#{user_input}" )
557
+ # end
558
+ # # I put this in to see the text being input it is not necessary to work
559
+ # sleep 3
560
+ # # "OK" or whatever the name on the button is
561
+ # w.clickWindowsButton_hwnd( hwnd, "#{button}" )
562
+ # #
563
+ # # this is just cleanup
564
+ # w=nil
565
+ # end
566
+ end
567
+
568
+ def select_option(browser, how, what, which, value, desc = '')
569
+ msg = "Select option #{which}='#{value}' from list #{how}=#{what}. #{desc}"
570
+ list = browser.select_list(how, what)
571
+ case which
572
+ when :text
573
+ list.select(value)
574
+ when :value
575
+ list.select_value(value)
576
+ when :index
577
+ all = list.getAllContents
578
+ txt = all[value]
579
+ list.select(txt)
580
+ else
581
+ na = "#{__method__} cannot support select by '#{which}'. (#{msg})"
582
+ debug_to_log(na, __LINE__, true)
583
+ raise na
584
+ end
585
+ passed_to_log(msg)
586
+ rescue
587
+ failed_to_log("#Unable to #{msg}': '#{$!}'")
588
+ end
589
+
590
+ def select_option_from_list(list, what, what_strg, desc = '')
591
+ ok = true
592
+ msg = "#{__method__.to_s.titleize} "
593
+ if list
594
+ msg << "list id=#{list.id}: "
595
+ case what
596
+ when :text
597
+ list.select(what_strg) #TODO: regex?
598
+ when :value
599
+ list.select_value(what_strg) #TODO: regex?
600
+ when :index
601
+ list.select(list.getAllContents[what_strg.to_i])
602
+ else
603
+ msg << "select by #{what} not supported. #{desc} (#{__LINE__})"
604
+ failed_to_log(msg)
605
+ ok = false
606
+ end
607
+ if ok
608
+ msg << "#{what}='#{what_strg}' selected. #{desc}"
609
+ passed_to_log(msg)
610
+ true
611
+ end
612
+ else
613
+ failed_to_log("#{__method__.to_s.titleize} list not found. #{desc} (#{__LINE__})")
614
+ end
615
+ rescue
616
+ failed_to_log("#{__method__.to_s.titleize}: #{what}='#{what_strg}' could not be selected: '#{$!}'. #{desc} (#{__LINE__})")
617
+ end
618
+
619
+ =begin rdoc
620
+ :category: A_rdoc_test
621
+ Select an option from a specific drop down list. The drop down (select list) is id
622
+
623
+ _Parameters_::
624
+
625
+ *browser* - a reference to the browser window to be tested
626
+
627
+ *how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
628
+ Common values: :text, :id, :title, :name, :class, :href (:link only)
629
+
630
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
631
+
632
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
633
+
634
+ _Example_
635
+
636
+ # html for a link element:
637
+ # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
638
+ click_no_wait(browser, :link, :text, 'Pickaxe')
639
+
640
+ =end
641
+
642
+ def select_option_by_id_and_option_text(browser, strg, option, nofail=false, desc = '')
643
+ msg = "Select list id=#{strg} option text='#{option}' selected."
644
+ msg << " #{desc}" if desc.length > 0
645
+ list = browser.select_list(:id, strg)
646
+ list.select(option)
647
+ # browser.select_list(:id, strg).select(option) #(browser.select_list(:id, strg).getAllContents[option])
648
+ if validate(browser, @myName, __LINE__)
649
+ passed_to_log(msg)
650
+ true
651
+ end
652
+ rescue
653
+ if !nofail
654
+ failed_to_log("#{msg} '#{$!}'")
655
+ end
656
+ end
657
+
658
+ alias select_option_by_id select_option_by_id_and_option_text
659
+ alias select_option_by_id_and_text select_option_by_id_and_option_text
660
+
661
+ def select_option_by_name_and_option_text(browser, strg, option, desc = '')
662
+ msg = "Select list name=#{strg} option text='#{option}' selected."
663
+ msg << " #{desc}" if desc.length > 0
664
+ begin
665
+ list = browser.select_list(:name, strg)
666
+ rescue => e
667
+ if not rescue_me(e, __method__, "#{__LINE__}: select_list(:name,'#{strg}')", "#{browser.class}")
668
+ raise e
669
+ end
670
+ end
671
+ begin
672
+ list.select(option)
673
+ rescue => e
674
+ if not rescue_me(e, __method__, "#{__LINE__}: select_list#select('#{option}')", "#{browser.class}")
675
+ raise e
676
+ end
677
+ end
678
+ if validate(browser, @myName, __LINE__)
679
+ passed_to_log(msg)
680
+ true
681
+ end
682
+ rescue
683
+ failed_to_log("#{msg} '#{$!}'")
684
+ end
685
+
686
+ alias select_option_by_name select_option_by_name_and_option_text
687
+
688
+ def select_option_by_title_and_option_text(browser, strg, option, desc = '')
689
+ msg = "Select list name=#{strg} option text='#{option}' selected."
690
+ msg << " #{desc}" if desc.length > 0
691
+ browser.select_list(:title, strg).select(option)
692
+ if validate(browser, @myName, __LINE__)
693
+ passed_to_log(msg)
694
+ end
695
+ rescue
696
+ failed_to_log("#{msg} '#{$!}'")
697
+ end
698
+
699
+ def select_option_by_class_and_option_text(browser, strg, option, desc = '')
700
+ msg = "Select list class=#{strg} option text='#{option}' selected."
701
+ msg << " #{desc}" if desc.length > 0
702
+ browser.select_list(:class, strg).select(option)
703
+ if validate(browser, @myName, __LINE__)
704
+ passed_to_log(msg)
705
+ true
706
+ end
707
+ rescue
708
+ failed_to_log("#{msg} '#{$!}'")
709
+ end
710
+
711
+ def select_option_by_name_and_option_value(browser, strg, option, desc = '')
712
+ msg = "Select list name=#{strg} option value='#{option}' selected."
713
+ msg << " #{desc}" if desc.length > 0
714
+ begin
715
+ list = browser.select_list(:name, strg)
716
+ rescue => e
717
+ if not rescue_me(e, __method__, "#{__LINE__}: select_list(:name,'#{strg}')", "#{browser.class}")
718
+ raise e
719
+ end
720
+ end
721
+ begin
722
+ list.select_value(option)
723
+ rescue => e
724
+ if not rescue_me(e, __method__, "#{__LINE__}: select_list#select_value('#{option}')", "#{browser.class}")
725
+ raise e
726
+ end
727
+ end
728
+ if validate(browser, @myName, __LINE__)
729
+ passed_to_log(msg)
730
+ true
731
+ end
732
+ rescue
733
+ failed_to_log("#{msg} '#{$!}'")
734
+ end
735
+
736
+ def select_option_by_id_and_option_value(browser, strg, option, desc = '')
737
+ msg = "Select list name=#{strg} option value='#{option}' selected."
738
+ msg << " #{desc}" if desc.length > 0
739
+ begin
740
+ list = browser.select_list(:id, strg)
741
+ rescue => e
742
+ if not rescue_me(e, __method__, "#{__LINE__}: select_list(:text,'#{strg}')", "#{browser.class}")
743
+ raise e
744
+ end
745
+ end
746
+ sleep(0.5) unless @targetBrowser.abbrev == 'IE'
747
+ begin
748
+ list.select_value(option)
749
+ rescue => e
750
+ if not rescue_me(e, __method__, "#{__LINE__}: select_list#select_value('#{option}')", "#{browser.class}")
751
+ raise e
752
+ end
753
+ end
754
+ if validate(browser, @myName, __LINE__)
755
+ passed_to_log(msg)
756
+ true
757
+ end
758
+ rescue
759
+ failed_to_log("#{msg} '#{$!}'")
760
+ end
761
+
762
+ def select_option_by_id_and_index(browser, strg, idx, desc = '')
763
+ msg = "Select list id=#{strg} index='#{idx}' selected."
764
+ msg << " #{desc}" if desc.length > 0
765
+ list = browser.select_list(:id, strg)
766
+ all = list.getAllContents
767
+ txt = all[idx]
768
+ browser.select_list(:id, strg).set(browser.select_list(:id, strg).getAllContents[idx])
769
+ if validate(browser, @myName, __LINE__)
770
+ passed_to_log(msg)
771
+ true
772
+ end
773
+ rescue
774
+ failed_to_log("#{msg} '#{$!}'")
775
+ end
776
+
777
+ def select_option_by_name_and_index(browser, strg, idx)
778
+ # TODO add check that both list and option exist
779
+ msg = "Select list name=#{strg} index='#{idx}' selected."
780
+ msg << " #{desc}" if desc.length > 0
781
+ browser.select_list(:name, strg).set(browser.select_list(:name, strg).getAllContents[idx])
782
+ if validate(browser, @myName, __LINE__)
783
+ passed_to_log(msg)
784
+ true
785
+ end
786
+ rescue
787
+ failed_to_log("#{msg} '#{$!}'")
788
+ end
789
+
790
+ def select_option_by_xpath_and_index(browser, strg, idx)
791
+ msg = "Select list xpath=#{strg} index='#{idx}' selected."
792
+ msg << " #{desc}" if desc.length > 0
793
+ browser.select_list(:xpath, strg).set(browser.select_list(:xpath, strg).getAllContents[idx])
794
+ if validate(browser, nil, __LINE__)
795
+ passed_to_log(msg)
796
+ true
797
+ end
798
+ rescue
799
+ failed_to_log("#{msg} '#{$!}'")
800
+ end
801
+
802
+ def set(browser, element, how, what, value = nil, desc = '')
803
+ msg = "Set #{element} #{how}=>'#{what}' "
804
+ msg << ", :value=>#{value} " if value
805
+ msg << " '#{desc}' " if desc.length > 0
806
+ case element
807
+ when :radio
808
+ browser.radio(how, what, value).set
809
+ when :checkbox
810
+ browser.checkbox(how, what, value).set
811
+ else
812
+ failed_to_log("#{__method__}: #{element} not supported")
813
+ end
814
+ if validate(browser, @myName, __LINE__)
815
+ passed_to_log(msg)
816
+ true
817
+ end
818
+ rescue
819
+ failed_to_log("#{msg} '#{$!}'")
820
+ end
821
+
822
+ def set_checkbox(browser, how, what, value, desc = '')
823
+ set(browser, :checkbox, how, what, value, desc)
824
+ end
825
+
826
+ def set_checkbox_by_class(browser, strg, value = nil, desc = '')
827
+ set(browser, :checkbox, :class, strg, value, desc)
828
+ end
829
+
830
+ def set_checkbox_by_id(browser, strg, value = nil, desc = '')
831
+ set(browser, :checkbox, :id, strg, value, desc)
832
+ end
833
+
834
+ def set_checkbox_by_name(browser, strg, value = nil, desc = '')
835
+ set(browser, :checkbox, :name, strg, value, desc)
836
+ end
837
+
838
+ def set_checkbox_by_title(browser, strg, value = nil, desc = '')
839
+ set(browser, :checkbox, :title, strg, value, desc)
840
+ end
841
+
842
+ def set_checkbox_by_value(browser, strg, desc = '')
843
+ set(browser, :checkbox, :value, strg, nil, desc)
844
+ end
845
+
846
+ def set_radio(browser, how, what, value = nil, desc = '')
847
+ set(browser, :radio, how, what, value, desc)
848
+ end
849
+
850
+ def set_radio_two_attributes(browser, how1, what1, how2, what2, desc = '')
851
+ msg = "Set radio #{how1}='#{what1}', #{how2}= #{what2}"
852
+ msg << " '#{desc}' " if desc.length > 0
853
+ browser.radio(how1 => what1, how2 => what2).set
854
+ if validate(browser, @myName, __LINE__)
855
+ passed_to_log(msg)
856
+ true
857
+ end
858
+ rescue
859
+ failed_to_log("#{msg} '#{$!}'")
860
+ end
861
+
862
+ def set_radio_by_class(browser, strg, value = nil, desc = '')
863
+ set(browser, :radio, :class, strg, value, desc)
864
+ end
865
+
866
+ def set_radio_by_id(browser, strg, value = nil, desc = '')
867
+ set(browser, :radio, :id, strg, value, desc)
868
+ end
869
+
870
+ def set_radio_by_index(browser, index, desc = '')
871
+ set(browser, :radio, :index, index, value, desc)
872
+ end
873
+
874
+ def set_radio_by_name(browser, strg, value = nil, desc = '')
875
+ set(browser, :radio, :name, strg, value, desc)
876
+ end
877
+
878
+ def set_radio_by_title(browser, strg, value = nil, desc = '')
879
+ set(browser, :radio, :title, strg, value, desc)
880
+ end
881
+
882
+ def set_radio_by_value(browser, strg, desc = '')
883
+ set(browser, :radio, :value, strg, nil, desc)
884
+ end
885
+
886
+ def set_radio_no_wait_by_index(browser, index, desc = '')
887
+ #TODO: Not supported by Watir 1.8.x
888
+ msg = "Radio :index=#{index} "
889
+ radios = browser.radios
890
+ debug_to_log("\n#{radios}")
891
+ radio = radios[index]
892
+ debug_to_log("\n#{radio}")
893
+ radio.click_no_wait
894
+ if validate(browser)
895
+ msg << 'set ' + desc
896
+ passed_to_log(msg)
897
+ true
898
+ end
899
+ rescue
900
+ msg << 'not found ' + desc
901
+ failed_to_log("#{msg} (#{__LINE__})")
902
+ end
903
+
904
+ def set_radio_by_name_and_index(browser, name, index, desc = '')
905
+ set_radio_two_attributes(browser, :name, name, :index, index, desc)
906
+ end
907
+
908
+ def set_radio_by_name_and_text(browser, name, text, desc = '')
909
+ set_radio_two_attributes(browser, :name, name, :text, text, desc)
910
+ end
911
+
912
+ def set_radio_by_value_and_index(browser, value, index, desc = '')
913
+ set_radio_two_attributes(browser, :value, value, :index, index, desc)
914
+ end
915
+
916
+ def set_radio_by_name_and_value(browser, strg, value, desc = '')
917
+ set_radio(browser, :name, strg, value, desc)
918
+ end
919
+
920
+ def clear(browser, element, how, what, value = nil, desc = '')
921
+ msg = "Clear #{element} #{how}=>'#{what}' "
922
+ msg << ", value=>#{value} " if value
923
+ msg << " '#{desc}' " if desc.length > 0
924
+ case element
925
+ when :radio
926
+ browser.radio(how, what, value).clear
927
+ when :checkbox
928
+ browser.checkbox(how, what, value).clear
929
+ when :text_field
930
+ browser.text_field(how, what).set('')
931
+ else
932
+ failed_to_log("#{__method__}: #{element} not supported")
933
+ end
934
+ if validate(browser, @myName, __LINE__)
935
+ passed_to_log(msg)
936
+ true
937
+ end
938
+ rescue
939
+ failed_to_log("#{msg} '#{$!}'")
940
+ end
941
+
942
+ def clear_checkbox(browser, how, what, value = nil, desc = '')
943
+ clear(browser, :checkbox, how, what, value, desc)
944
+ end
945
+
946
+ def clear_checkbox_by_name(browser, strg, value = nil, desc = '')
947
+ clear(browser, :checkbox, :name, strg, value, desc)
948
+ end
949
+
950
+ def clear_checkbox_by_id(browser, strg, value = nil, desc = '')
951
+ clear(browser, :checkbox, :id, strg, value, desc)
952
+ end
953
+
954
+ def clear_radio(browser, how, what, value = nil, desc = '')
955
+ clear(browser, :radio, how, what, value, desc)
956
+ end
957
+
958
+ # Set skip_value_check = true when string is altered by application and/or
959
+ # this method will be followed by validate_text
960
+ def clear_textfield(browser, how, which, skip_value_check = false)
961
+ if browser.text_field(how, which).exists?
962
+ tf = browser.text_field(how, which)
963
+ if validate(browser, @myName, __LINE__)
964
+ tf.clear
965
+ if validate(browser, @myName, __LINE__)
966
+ if tf.value == ''
967
+ passed_to_log("Textfield #{how}='#{which}' cleared.")
968
+ true
969
+ elsif skip_value_check
970
+ passed_to_log("Textfield #{how}='#{which}' cleared. (skip value check)")
971
+ true
972
+ else
973
+ failed_to_log("Textfield #{how}='#{which}' not cleared: Found:'#{tf.value}'. (#{__LINE__})")
974
+ end
975
+ end
976
+ end
977
+ else
978
+ failed_to_log("Textfield id='#{id}' to clear. (#{__LINE__})")
979
+ end
980
+ rescue
981
+ failed_to_log("Textfield id='#{id}' could not be cleared: '#{$!}'. (#{__LINE__})")
982
+ end
983
+
984
+ def set_file_field(browser, how, what, filespec, desc = '')
985
+ msg = "Set file field #{how}=>#{what} to '#{filespec}."
986
+ msg << " #{desc}" if desc.length > 0
987
+ ff = browser.file_field(how, what)
988
+ if ff
989
+ ff.set filespec
990
+ sleep_for(8)
991
+ if validate(browser, @myName, __LINE__)
992
+ passed_to_log(msg)
993
+ true
994
+ end
995
+ else
996
+ failed_to_log("#{msg} File field not found.")
997
+ end
998
+ rescue
999
+ failed_to_log("Unable to #{msg} '#{$!}'")
1000
+ end
1001
+
1002
+ def set_file_field_by_name(browser, strg, path, desc = '')
1003
+ set_file_field(browser, :name, strg, path, desc)
1004
+ end
1005
+
1006
+ def set_file_field_by_id(browser, strg, path, desc = '')
1007
+ set_file_field(browser, :id, strg, path, desc)
1008
+ end
1009
+
1010
+ =begin rdoc
1011
+ :category: A_rdoc_test
1012
+ Enter a string into a text field element identified by an attribute type and a value.
1013
+ After the entry the value in the text field is validated against the input value unless the *skip_value_check*
1014
+ parameter is set to true
1015
+
1016
+ _Parameters_::
1017
+
1018
+ *browser* - a reference to the browser window to be tested
1019
+
1020
+ *how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
1021
+ Common values: :text, :id, :title, :name, :class, :href (:link only)
1022
+
1023
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
1024
+
1025
+ *value* - a string to be entered in the text field
1026
+
1027
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
1028
+
1029
+ *skip_value_check* (Optional, default is false). Set to true to prevent the built-in verification
1030
+ that the text field actually contains the value entered. Useful when application reformats
1031
+ or otherwise edits the input string.
1032
+
1033
+ _Example_
1034
+
1035
+ set_text_field(browser, :name, /thisTextfield/, 'The text to enter')
1036
+
1037
+ =end
1038
+
1039
+ def set_text_field(browser, how, what, value, desc = '', skip_value_check = false)
1040
+ #TODO: fix this to handle Safari password field
1041
+ msg = "Set textfield #{how}='#{what}' to '#{value}'"
1042
+ msg << " #{desc}" if desc.length > 0
1043
+ msg << " (Skip value check)" if skip_value_check
1044
+ if browser.text_field(how, what).exists?
1045
+ tf = browser.text_field(how, what)
1046
+ debug_to_log("#{tf.inspect}")
1047
+ if validate(browser, @myName, __LINE__)
1048
+ tf.set(value)
1049
+ if validate(browser, @myName, __LINE__)
1050
+ if tf.value == value
1051
+ passed_to_log(msg)
1052
+ true
1053
+ elsif skip_value_check
1054
+ passed_to_log(msg)
1055
+ true
1056
+ else
1057
+ failed_to_log("#{msg}: Found:'#{tf.value}'.")
1058
+ end
1059
+ end
1060
+ end
1061
+ else
1062
+ failed_to_log("Textfield #{how}='#{what}' not found to set to '#{value}''")
1063
+ end
1064
+ rescue
1065
+ failed_to_log("Unable to '#{msg}': '#{$!}'")
1066
+ end
1067
+
1068
+ alias set_textfield set_text_field
1069
+
1070
+ def set_textfield_by_name(browser, name, value, desc = '', skip_value_check = false)
1071
+ if browser.text_field(:name, name).exists?
1072
+ tf = browser.text_field(:name, name)
1073
+ # Workaround because browser.text_field doesn't work for password fields in Safari
1074
+ elsif @browserAbbrev.eql?("S")
1075
+ tf = browser.password(:name, name)
1076
+ end
1077
+ if tf.exists?
1078
+ if validate(browser, @myName, __LINE__)
1079
+ tf.set(value)
1080
+ if validate(browser, @myName, __LINE__)
1081
+ if tf.value == value
1082
+ passed_to_log("Set textfield name='#{name}' to '#{value}' #{desc}")
1083
+ true
1084
+ elsif skip_value_check
1085
+ passed_to_log("Set textfield name='#{name}' to '#{value}' #{desc} (skip value check)")
1086
+ true
1087
+ else
1088
+ failed_to_log("Set textfield name='#{name}' to '#{value}': Found:'#{tf.value}'. #{desc} (#{__LINE__})")
1089
+ end
1090
+ end
1091
+ end
1092
+ else
1093
+ failed_to_log("Textfield name='#{name}' not found to set to '#{value}'. #{desc} (#{__LINE__})")
1094
+ end
1095
+ rescue
1096
+ failed_to_log("Textfield name='#{name}' could not be set to '#{value}': '#{$!}'. #{desc} (#{__LINE__})")
1097
+ end
1098
+
1099
+ =begin rdoc
1100
+ :category: A_rdoc_test
1101
+ Enter a string into a text field element identified by the value in its id attribute.
1102
+
1103
+ _Parameters_::
1104
+
1105
+ *browser* - a reference to the browser window to be tested
1106
+
1107
+ *id* - a string or a regular expression to be found in the id attribute that uniquely identifies the element.
1108
+
1109
+ *value* - a string to be entered in the text field
1110
+
1111
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
1112
+
1113
+ *skip_value_check* (Optional, default is false). Set to true to prevent the built-in verification
1114
+ that the text field actually contains the value entered. Useful when application reformats
1115
+ or otherwise edits the input string.
1116
+
1117
+ _Example_
1118
+
1119
+ set_text_field_by_id(browser, /thisTextfield/, 'The text to enter')
1120
+
1121
+ =end
1122
+
1123
+ def set_textfield_by_id(browser, id, value, desc = '', skip_value_check = false)
1124
+ set_text_field(browser, :id, id, value, desc, skip_value_check)
1125
+ end
1126
+
1127
+ def set_textfield_by_title(browser, title, value, desc = '', skip_value_check = false)
1128
+ set_text_field(browser, :title, title, value, desc, skip_value_check)
1129
+ end
1130
+
1131
+ def set_textfield_by_class(browser, strg, value, desc = '', skip_value_check = false)
1132
+ set_text_field(browser, :class, strg, value, desc, skip_value_check)
1133
+ end
1134
+
1135
+ =begin rdoc
1136
+ :category: A_rdoc_test
1137
+ Enter a string into a text field element identified by an attribute type and a value.
1138
+ After the entry the value in the text field is validated against the *valid_value*. Use when the application reformats
1139
+ or performs edits on the input value.
1140
+
1141
+ _Parameters_::
1142
+
1143
+ *browser* - a reference to the browser window to be tested
1144
+
1145
+ *how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
1146
+ Common values: :text, :id, :title, :name, :class, :href (:link only)
1147
+
1148
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
1149
+
1150
+ *value* - a string to be entered in the text field
1151
+
1152
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
1153
+
1154
+ *valid_value* (Optional, default is nil). Set to the expected value
1155
+
1156
+ _Example_
1157
+
1158
+ set_text_field_and_validate(browser, :id, /AmountTendered/, '7500', 'Dollar formatting', '$7,500.00')
1159
+
1160
+ =end
1161
+
1162
+ def set_text_field_and_validate(browser, how, what, value, desc = '', valid_value = nil)
1163
+ #NOTE: use when value and valid_value differ as with dollar reformatting
1164
+ if set_text_field(browser, how, what, value, desc, true)
1165
+ expected = valid_value ? valid_value : value
1166
+ validate_textfield_value(browser, how, what, expected)
1167
+ end
1168
+ rescue
1169
+ failed_to_log("Unable to '#{msg}': '#{$!}'")
1170
+ end
1171
+
1172
+ =begin rdoc
1173
+ :category: A_rdoc_test
1174
+ Allows a generic way to fire browser or javascript events on page elements.
1175
+ Raises UnknownObjectException if the object is not found or ObjectDisabledException if the object is currently disabled.
1176
+ _Parameters_::
1177
+
1178
+ *browser* - a reference to the browser window to be tested
1179
+
1180
+ *element* - the kind of element to click. Must be one of the elements recognized by Watir.
1181
+ Some common values are :link, :button, :image, :div, :span.
1182
+
1183
+ *how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
1184
+ Common values: :text, :id, :title, :name, :class, :href (:link only)
1185
+
1186
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
1187
+
1188
+ *event* - a string indicating the event to be triggered, e.g., 'onMouseOver', 'onClick', and etc.
1189
+
1190
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
1191
+
1192
+ _Example_
1193
+
1194
+ # html for a link element:
1195
+ # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
1196
+ fire_event(browser, :link, :text, 'Pickaxe', 'onMouseOver')
1197
+
1198
+ =end
1199
+
1200
+ def fire_event(browser, element, how, what, event, desc = '')
1201
+ msg = "#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'"
1202
+ msg1 = "#{element.to_s.titlecase}(#{how}, '#{what}')"
1203
+ begin
1204
+ case element
1205
+ when :link
1206
+ browser.link(how, what).fire_event(event)
1207
+ when :button
1208
+ browser.button(how, what).fire_event(event)
1209
+ when :image
1210
+ browser.image(how, what).fire_event(event)
1211
+ when :span
1212
+ browser.span(how, what).fire_event(event)
1213
+ when :div
1214
+ browser.div(how, what).fire_event(event)
1215
+ else
1216
+ browser.element(how, what).fire_event(event)
1217
+ end
1218
+ rescue => e
1219
+ if not rescue_me(e, __method__, "browser(#{msg1}).fire_event('#{event}')", "#{browser.class}")
1220
+ raise e
1221
+ end
1222
+ end
1223
+ if validate(browser, @myName, __LINE__)
1224
+ passed_to_log("Fire event: #{msg}. #{desc}")
1225
+ true
1226
+ end
1227
+ rescue
1228
+ failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
1229
+ end
1230
+
1231
+ def fire_event_on_link_by_text(browser, strg, event = 'onclick', desc = '')
1232
+ fire_event(browser, :link, :text, strg, event, desc)
1233
+ end
1234
+
1235
+ alias fire_event_text fire_event_on_link_by_text
1236
+ alias fire_event_by_text fire_event_on_link_by_text
1237
+
1238
+ def fire_event_on_link_by_id(browser, strg, event = 'onclick', desc = '')
1239
+ fire_event(browser, :link, :id, strg, event, desc)
1240
+ end
1241
+
1242
+ alias fire_event_id fire_event_on_link_by_id
1243
+ alias fire_event_by_id fire_event_on_link_by_id
1244
+
1245
+ def fire_event_on_image_by_src(browser, strg, event = 'onclick', desc = '')
1246
+ fire_event(browser, :img, :src, strg, event, desc)
1247
+ end
1248
+
1249
+ alias fire_event_src fire_event_on_image_by_src
1250
+ alias fire_event_image_by_src fire_event_on_image_by_src
1251
+
1252
+
1253
+ end
1254
+ end
1255
+ end
1256
+