awetestlib 0.1.6-x86-mingw32 → 0.1.7-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,9 +31,8 @@ Gem::Specification.new do |s|
31
31
  s.add_dependency('selenium-webdriver')
32
32
  s.add_dependency('pry')
33
33
  s.add_dependency('rdoc', '~> 3.11')
34
- s.add_dependency('yard')
35
34
 
36
- s.has_rdoc = 'yard'
35
+
37
36
  s.require_paths = ["lib"]
38
37
  s.files = `git ls-files`.split("\n")
39
38
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -44,11 +44,7 @@ module Awetestlib
44
44
  ::PASS = '-PASS'
45
45
  ::FAIL = '-FAIL'
46
46
 
47
- # @return [Watir::Browser] the browser referenced by the attribute browser
48
- attr_accessor :browser
49
- # @return [String] abbreviation for the targeted browser (e.g., IE, FF, GC)
50
- attr_accessor :browser_abbrev
51
- attr_accessor :version, :env,
47
+ attr_accessor :browser, :browser_abbrev, :version, :env,
52
48
  :library, :script_type, :script_file,
53
49
  :log_properties, :log_queue, :log_class,
54
50
  :notify_queue, :notify_class, :notify_id,
@@ -249,7 +245,6 @@ module Awetestlib
249
245
  if USING_WINDOWS
250
246
  require 'watir/win32ole'
251
247
  @ai = ::WIN32OLE.new('AutoItX3.Control')
252
- require 'pry'
253
248
  else
254
249
  # TODO: Need alternative for Mac?
255
250
  @ai = ''
@@ -2,28 +2,36 @@ module Awetestlib
2
2
  module Regression
3
3
  module UserInput
4
4
 
5
- # @!group Core
6
-
7
- # Click a specific DOM element identified by one of its attributes and that attribute's value.
8
- #
9
- # @example
10
- # # html for a link element:
11
- # # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
12
- #
13
- # click(browser, :link, :text, 'Pickaxe')
14
- #
15
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
16
- # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
17
- # Some common values are :link, :button, :image, :div, :span.
18
- # @param [Symbol] how The element attribute used to identify the specific element.
19
- # Valid values depend on the kind of element.
20
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
21
- # @param [String|Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
22
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
23
- #
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
+
24
31
  def click(browser, element, how, what, desc = '')
25
32
  #debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
26
- msg = build_message("Click #{element} :#{how}=>'#{what}'", desc)
33
+ msg = "Click #{element} :#{how}=>'#{what}'"
34
+ msg << ", '#{desc}'" if desc.length > 0
27
35
  msg1 = "#{element}(#{how}, '#{what}')"
28
36
  begin
29
37
  case element
@@ -58,180 +66,38 @@ module Awetestlib
58
66
  failed_to_log("Unable to #{msg}. '#{$!}'")
59
67
  end
60
68
 
61
- # @!endgroup Core
62
-
63
- # @!group Click
64
-
65
- # Click a button element identified by the value of its _id_ attribute. A button is an HTML element with tag 'input' and type 'submit' or 'button'.
66
- # @param [Watir::Browser, Watir::Container] browser A reference to the browser window or container element to be tested.
67
- # @param [String|Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
68
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
69
- #
70
- def click_button_by_id(browser, what, desc = '')
71
- click(browser, :button, :id, what, desc)
72
- end
73
-
74
- # Click a button element identified by the value of its index within the container referred to by <b>+browser+</b>.
75
- # @param [Watir::Browser, Watir::Container] browser A reference to the browser window or container element to be tested.
76
- # @param [Fixnum] what An integer that indicates the index of the element within the container.
77
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
78
- def click_link_by_index(browser, what, desc = '')
79
- click(browser, :link, :index, what, desc)
80
- end
81
-
82
- # Click a link element identified by the value of its _href_ attribute. Take care to escape characters in the url that are reserved by Regexp.
83
- # @param (see #click_button_by_id)
84
- def click_link_by_href(browser, what, desc = '')
85
- click(browser, :link, :href, what, desc)
86
- end
87
-
88
- alias click_href click_link_by_href
89
-
90
- # Click a link element identified by the value of its _href_ attribute and do not wait for the browser to reach ready state.
91
- # Take care to escape characters in the url that are reserved by Regexp.
92
- # @param (see #click_button_by_id)
93
- def click_link_no_wait_by_href(browser, what, desc = '')
94
- click_no_wait(browser, :link, :href, what, desc)
95
- end
96
-
97
- # Click a button element identified by the value of its index within the container referred to by <b>+browser+</b>.
98
- # @param (see #click_link_by_index)
99
- def click_button_by_index(browser, what, desc = '')
100
- click(browser, :button, :index, what, desc)
101
- end
102
-
103
- # Click a button element identified by the value of its _name_ attribute. A button is an HTML element with tag 'input' and type 'submit' or 'button'.
104
- # @param (see #click_button_by_id)
105
- def click_button_by_name(browser, what, desc = '')
106
- click(browser, :button, :name, what, desc)
107
- end
108
-
109
- # Click a button element identified by the value of its _text_ attribute. A button is an HTML element with tag 'input' and type 'submit' or 'button'.
110
- # @param (see #click_button_by_id)
111
- def click_button_by_text(browser, what, desc = '')
112
- click(browser, :button, :text, what, desc)
113
- end
114
-
115
- # Click a button element identified by the value of its _class_ attribute. A button is an HTML element with tag 'input' and type 'submit' or 'button'.
116
- # @param (see #click_button_by_id)
117
- def click_button_by_class(browser, what, desc = '')
118
- click(browser, :button, :class, what, desc)
119
- end
120
-
121
- # Click a button element identified by the value of its _value_ attribute. A button is an HTML element with tag 'input' and type 'submit' or 'button'.
122
- # @param (see #click_button_by_id)
123
- def click_button_by_value(browser, what, desc = '')
124
- click(browser, :button, :value, what, desc)
125
- end
126
-
127
- # Click a button element identified by the value of its _title_ attribute. A button is an HTML element with tag 'input' and type 'submit' or 'button'.
128
- # @param (see #click_button_by_id)
129
- def click_button_by_title(browser, what, desc = '')
130
- click(browser, :button, :title, what, desc)
131
- end
132
-
133
- # Click a link element identified by the value of its _id_ attribute.
134
- # @param (see #click_button_by_id)
135
- def click_link_by_id(browser, what, desc = '')
136
- click(browser, :link, :id, what, desc)
137
- end
138
-
139
- alias click_id click_link_by_id
140
-
141
- # Click a link element identified by the value of its _name_ attribute.
142
- # @param (see #click_button_by_id)
143
- def click_link_by_name(browser, what, desc = '')
144
- click(browser, :link, :name, what, desc)
145
- end
146
-
147
- alias click_name click_link_by_name
148
-
149
- # Click a file_field element identified by the value of its _id_ attribute.
150
- # @param (see #click_button_by_id)
151
- def click_file_field_by_id(browser, what, desc = '')
152
- click(browser, :file_field, :id, what, desc)
153
- end
154
-
155
- # Click an image element identified by the value of its _id_ attribute.
156
- # @param (see #click_button_by_id)
157
- def click_img_by_alt(browser, what, desc = '')
158
- click(browser, :image, :alt, what, desc)
159
- end
160
-
161
- # Click an image element identified by the value of its _title_ attribute.
162
- # @param (see #click_button_by_id)
163
- def click_img_by_title(browser, what, desc = '')
164
- click(browser, :image, :title, what, desc)
165
- end
166
-
167
- # Click an image element identified by the value of its _src_ attribute.
168
- # Take care to escape characters in the source url that are reserved by Regexp.
169
- # @param (see #click_button_by_id)
170
- def click_img_by_src(browser, what, desc = '')
171
- click(browser, :image, :src, what, desc)
172
- end
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.
173
74
 
174
- # Click a link element identified by the value of its _value_ attribute.
175
- # @param (see #click_button_by_id)
176
- def click_link_by_value(browser, what, desc = '')
177
- click(browser, :link, :value, what, desc)
178
- end
75
+ _Parameters_::
179
76
 
180
- # Click a link element identified by the value in its text (innerHTML).
181
- # @param (see #click_button_by_id)
182
- def click_link_by_text(browser, what, desc = '')
183
- click(browser, :link, :text, what, desc)
184
- end
77
+ *browser* - a reference to the browser window to be tested
185
78
 
186
- alias click_link click_link_by_text
187
- alias click_text click_link_by_text
188
- alias click_js_button click_link_by_text
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.
189
81
 
190
- # Click a link element identified by the value of its _class_ attribute.
191
- # @param (see #click_button_by_id)
192
- def click_link_by_class(browser, what, desc = '')
193
- click(browser, :link, :class, what, desc)
194
- end
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)
195
84
 
196
- alias click_class click_link_by_class
85
+ *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
197
86
 
198
- # Click a span element identified by the value in its text (innerHTML).
199
- # @param (see #click_button_by_id)
200
- def click_span_by_text(browser, what, desc = '')
201
- click(browser, :span, :text, what)
202
- end
87
+ *desc* - a string containing a message or description intended to appear in the log and/or report output
203
88
 
204
- alias click_span_with_text click_span_by_text
89
+ _Example_
205
90
 
206
- # Click a link element identified by the value of its _title_ attribute.
207
- # @param (see #click_button_by_id)
208
- def click_link_by_title(browser, what, desc = '')
209
- click(browser, :link, :title, what, desc)
210
- end
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')
211
94
 
212
- alias click_title click_link_by_title
95
+ =end
213
96
 
214
- # @!endgroup Click
215
-
216
- # @!group Core
217
-
218
- # Click a specific DOM element by one of its attributes and that attribute's value and
219
- # do not wait for the browser to finish reloading. Used when a modal popup or alert is expected. Allows the script
220
- # to keep running so the popup can be handled.
221
- #
222
- # @example
223
- # # html for a link element:
224
- # # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
225
- #
226
- # click_no_wait(browser, :link, :text, 'Pickaxe')
227
- #
228
- # @see #click
229
- #
230
- # @param (see #click)
231
- #
232
97
  def click_no_wait(browser, element, how, what, desc = '')
233
98
  debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
234
- msg = build_message("Click no wait #{element} :#{how}=>'#{what}'", desc)
99
+ msg = "Click no wait #{element} :#{how}=>'#{what}'"
100
+ msg << ", '#{desc}'" if desc.length > 0
235
101
  msg1 = "#{element}(#{how}, '#{what}'"
236
102
  begin
237
103
  case element
@@ -273,172 +139,197 @@ module Awetestlib
273
139
  sleep_for(1)
274
140
  end
275
141
 
276
- # @!endgroup Core
277
-
278
- alias click_href_no_wait click_link_no_wait_by_href
279
-
280
- # @!group Click No Wait
281
-
282
- # Click a button element identified by the value of its _id_ attribute
283
- # and do not wait for the browser to reach ready state.
284
- # @param (see #click_button_by_id)
285
- def click_button_no_wait_by_id(browser, what, desc = '')
286
- click_no_wait(browser, :button, :id, what, desc)
142
+ # :category: User Input
143
+ def click_button_by_id(browser, strg, desc = '')
144
+ click(browser, :button, :id, strg, desc)
287
145
  end
288
146
 
289
- alias click_button_by_id_no_wait click_button_no_wait_by_id
290
-
291
- # Click a button element identified by the value of its _name_ attribute
292
- # and do not wait for the browser to reach ready state.
293
- # @param (see #click_button_by_id)
294
- def click_button_no_wait_by_name(browser, what, desc = '')
295
- click_no_wait(browser, :button, :name, what, desc)
147
+ # :category: User Input
148
+ def click_link_by_index(browser, strg, desc = '')
149
+ click(browser, :link, :index, strg, desc)
296
150
  end
297
151
 
298
- # Click a button element identified by the value of its _class_ attribute
299
- # and do not wait for the browser to reach ready state.
300
- # @param (see #click_button_by_id)
301
- def click_button_no_wait_by_class(browser, what, desc = '')
302
- click_no_wait(browser, :button, :class, what, desc)
152
+ # :category: User Input
153
+ def click_link_by_href(browser, strg, desc = '')
154
+ click(browser, :link, :href, strg, desc)
303
155
  end
304
156
 
305
- alias click_button_by_class_no_wait click_button_no_wait_by_class
306
-
307
- # Click a link element identified by the value of its _id_ attribute
308
- # and do not wait for the browser to reach ready state.
309
- # @param (see #click_button_by_id)
310
- def click_link_no_wait_by_id(browser, what, desc = '')
311
- click_no_wait(browser, :link, :id, what, desc)
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)
312
161
  end
313
162
 
314
- alias click_no_wait_id click_link_no_wait_by_id
315
- alias click_no_wait_by_id click_link_no_wait_by_id
316
- alias click_id_no_wait click_link_no_wait_by_id
317
- alias click_no_wait_link_by_id click_link_no_wait_by_id
318
-
319
- # Click an image element identified by the value of its _alt_ attribute
320
- # and do not wait for the browser to reach ready state.
321
- # @param (see #click_button_by_id)
322
- def click_img_no_wait_by_alt(browser, what, desc = '')
323
- click_no_wait(browser, :image, :alt, what, desc)
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)
324
167
  end
325
168
 
326
- alias click_img_by_alt_no_wait click_img_no_wait_by_alt
327
-
328
- # Click a button element identified by the value in its text (innerHTML)
329
- # and do not wait for the browser to reach ready state.
330
- # @param (see #click_button_by_id)
331
- def click_button_no_wait_by_text(browser, what, desc = '')
332
- click_no_wait(browser, :button, :text, what, desc)
169
+ # :category: User Input
170
+ def click_button_by_name(browser, strg, desc = '')
171
+ click(browser, :button, :name, strg, desc)
333
172
  end
334
173
 
335
- # Click a button element identified by the value of its _value_ attribute
336
- # and do not wait for the browser to reach ready state.
337
- # @param (see #click_button_by_id)
338
- def click_button_no_wait_by_value(browser, what, desc = '')
339
- click_no_wait(browser, :button, :value, what, desc)
174
+ # :category: User Input
175
+ def click_button_by_text(browser, strg, desc = '')
176
+ click(browser, :button, :text, strg, desc)
340
177
  end
341
178
 
342
- # Click a button element identified by the value of its _name_ attribute
343
- # and do not wait for the browser to reach ready state.
344
- # @param (see #click_button_by_id)
345
- def click_link_by_name_no_wait(browser, what, desc = '')
346
- click_no_wait(browser, :link, :name, what, desc)
179
+ # :category: User Input
180
+ def click_button_by_class(browser, strg, desc = '')
181
+ click(browser, :button, :class, strg, desc)
347
182
  end
348
183
 
349
- alias click_no_wait_name click_link_by_name_no_wait
350
- alias click_name_no_wait click_link_by_name_no_wait
351
-
352
- # Click a link element identified by the value in its text (innerHTML)
353
- # and do not wait for the browser to reach ready state.
354
- # @param (see #click_button_by_id)
355
- def click_link_by_text_no_wait(browser, what, desc = '')
356
- click_no_wait(browser, :link, :text, what, desc)
184
+ # :category: User Input
185
+ def click_button_no_wait_by_id(browser, strg, desc = '')
186
+ click_no_wait(browser, :button, :id, strg, desc)
357
187
  end
358
188
 
359
- alias click_no_wait_text click_link_by_text_no_wait
360
- alias click_text_no_wait click_link_by_text_no_wait
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
361
194
 
362
- # Click a link element identified by the value of its _title_ attribute
363
- # and do not wait for the browser to reach ready state.
364
- # @param (see #click_button_by_id)
365
- def click_title_no_wait(browser, what, desc = '')
366
- click_no_wait(browser, :link, :title, what, desc)
195
+ # :category: User Input
196
+ def click_button_no_wait_by_class(browser, strg, desc = '')
197
+ click_no_wait(browser, :button, :class, strg, desc)
367
198
  end
368
199
 
369
- # @!endgroup Click No Wait
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
370
205
 
371
- # @!group Xpath
206
+ # :category: User Input
207
+ def click_button_by_title(browser, strg, desc = '')
208
+ click(browser, :button, :title, strg, desc)
209
+ end
372
210
 
373
- # Click a button element identified by the value of its _id_ attribute using the xpath functionality in Watir.
374
- # A button is an HTML element with tag 'input' and type 'submit' or 'button'.
375
- # @note Normally used only when the element is not located by other methods.
376
- # @param (see #click_button_by_id)
377
- def click_button_by_xpath_and_id(browser, what, desc = '')
378
- msg = "Click button by xpath and id '#{what}' #{desc}"
379
- if browser.button(:xpath, "//a[@id = '#{what}']").click
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
380
215
  passed_to_log(msg)
381
216
  true
382
217
  else
383
218
  failed_to_log(msg)
384
219
  end
385
220
  rescue
386
- failed_to_log("Unable to click button by xpath and id '#{what}' #{desc} '#{$!}' (#{__LINE__})")
221
+ failed_to_log("Unable to click button by xpath and id '#{strg}' #{desc} '#{$!}' (#{__LINE__})")
387
222
  end
388
223
 
389
224
  alias click_button_by_xpath click_button_by_xpath_and_id
390
225
 
391
- # Click a link element identified by the value of its _id_ attribute using the xpath functionality in Watir.
392
- # @note Normally used only when the element is not located by other methods.
393
- # @param (see #click_button_by_id)
394
- def click_link_by_xpath_and_id(browser, what, desc = '')
395
- msg = "Click link by xpath and id '#{what}' #{desc}"
396
- if browser.link(:xpath, "//a[@id = '#{what}']").click
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
397
264
  passed_to_log(msg)
398
265
  true
399
266
  else
400
267
  failed_to_log(msg)
401
268
  end
402
269
  rescue
403
- failed_to_log("Unable to #{msg} '#{$!}' (#{__LINE__})")
270
+ failed_to_log("Unable click on link by xpath and id '#{strg}' #{desc} '#{$!}' (#{__LINE__})")
404
271
  end
405
272
 
406
273
  alias click_link_by_xpath click_link_by_xpath_and_id
407
274
 
408
- # Click a link element identified by the value of its _id_ attribute using the xpath functionality in Watir.
409
- # @note Normally used only when the element is not located by other methods.
410
- # @param (see #click_button_by_id)
411
- def click_img_by_xpath_and_name(browser, what, desc = '')
412
- msg = "Click image by xpath where name='#{what}' #{desc}"
413
- if browser.link(:xpath, "//input[@name = '#{what}']").click
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
414
304
  passed_to_log(msg)
415
305
  true
416
306
  else
417
307
  failed_to_log(msg)
418
308
  end
419
309
  rescue
420
- failed_to_log("Unable to click image by xpath where name='#{what}' #{desc} '#{$!}'")
310
+ failed_to_log("Unable to click image by xpath where name='#{strg}' #{desc} '#{$!}'")
421
311
  end
422
312
 
423
313
  alias click_img_by_xpath click_img_by_xpath_and_name
424
314
  alias click_image_by_xpath click_img_by_xpath_and_name
425
315
  alias click_image_by_xpath_and_name click_img_by_xpath_and_name
426
316
 
427
- # @!endgroup Xpath
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
428
321
 
429
- # @!group Core
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
430
327
 
431
- # Click an image element identified by the value of its _src_ attribute and its index
432
- # within the array of image elements with src containing <b>+what+</b> and
433
- # within the container referred to by <b>+browser+</b>.
434
- # @param [Watir::Browser, Watir::Container] browser A reference to the browser window or container element to be tested.
435
- # @param [String|Regexp] what A string or a regular expression to be found in the specified attribute that uniquely identifies the element.
436
- # @param [Fixnum] index An integer that indicates the index of the element within the array of image elements with src containing <b>+what+</b>.
437
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
438
- def click_img_by_src_and_index(browser, what, index, desc = '')
439
- msg = "Click image by src='#{what}' and index=#{index}"
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}"
440
331
  msg << " #{desc}" if desc.length > 0
441
- browser.image(:src => what, :index => index).click
332
+ browser.image(:src => strg, :index => index).click
442
333
  if validate(browser, @myName, __LINE__)
443
334
  passed_to_log(msg)
444
335
  true
@@ -447,122 +338,206 @@ module Awetestlib
447
338
  failed_to_log("Unable to #{msg} '#{$!}'")
448
339
  end
449
340
 
450
- # @!endgroup Core
451
-
452
- # @!group Core
453
-
454
- # Click the first row which contains a particular string in a table identified by attribute and value.
455
- # A specific column in the table can also be specified.
456
- #
457
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
458
- # @param [Symbol] how The element attribute used to identify the specific element.
459
- # Valid values depend on the kind of element.
460
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
461
- # @param [String|Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
462
- # @param [String] text Full text string to be found in the table row.
463
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
464
- # @param [Fixnum] column Integer indicating the column to search for the text string.
465
- # If not supplied all columns will be checked.
466
- #
467
- def click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
468
- msg = build_message("Click row with text #{text} in table :#{how}=>'#{what}.", desc)
469
- table = get_table(browser, how, what, desc)
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}/)
470
457
  if table
471
- index = get_index_of_row_with_text(table, text, column)
458
+ index = get_index_of_row_with_text(table, strg, column)
472
459
  if index
473
460
  table[index].click
474
461
  if validate(browser, @myName, __LINE__)
475
- passed_to_log(msg)
462
+ passed_to_log("Click #{msg} row index=#{index}.")
476
463
  index
477
464
  end
478
465
  else
479
- failed_to_log("#{msg} Row not found.")
466
+ failed_to_log("Table #{msg} not found to click.")
480
467
  end
481
468
  else
482
- failed_to_log("#{msg} Table not found.")
469
+ failed_to_log("Table id=#{ptrn} not found.")
483
470
  end
484
471
  rescue
485
- failed_to_log("Unable to #{msg}: '#{$!}'")
472
+ failed_to_log("Unable to click table #{msg}: '#{$!}' (#{__LINE__}) ")
486
473
  end
487
474
 
488
- # Double click the first row which contains a particular string in a table identified by attribute and value.
489
- # A specific column in the table can also be specified.
490
- # Uses fire_event method in Watir to send 'onDblClick' event.
491
- #
492
- # @param (see #click_table_row_with_text)
493
- #
494
- def double_click_table_row_with_text(browser, how, what, text, desc = '', column = nil)
495
- msg = build_message("Double click row with text #{text} in table :#{how}=>'#{what}.", desc)
496
- table = get_table(browser, how, what, desc)
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)
497
479
  if table
498
- index = get_index_of_row_with_text(table, text, column)
480
+ index = get_index_of_row_with_text(table, strg, column)
499
481
  if index
500
- table[index].fire_event('ondblclick')
482
+ table[index].click
501
483
  if validate(browser, @myName, __LINE__)
502
- passed_to_log(msg)
484
+ passed_to_log("Click #{msg} row index=#{index}.")
503
485
  index
504
486
  end
505
487
  else
506
- failed_to_log("#{msg} Row not found.")
488
+ failed_to_log("Table #{msg} not found to click.")
507
489
  end
508
490
  else
509
- failed_to_log("#{msg} Table not found.")
491
+ failed_to_log("Table id=#{ptrn} not found.")
510
492
  end
511
493
  rescue
512
- failed_to_log("Unable to #{msg}: '#{$!}'")
494
+ failed_to_log("Unable to click table #{msg}: '#{$!}' (#{__LINE__}) ")
513
495
  end
514
496
 
515
- # @!endgroup Core
516
-
517
- # @!group Tables
518
-
519
- # Click the first row which contains a particular string in a table identified by the value in its _id_ attribute.
520
- # A specific column in the table can also be specified.
521
- #
522
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
523
- # @param [String|Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
524
- # @param [String] text Full text string to be found in the table row.
525
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
526
- # @param [Fixnum] column Integer indicating the column to search for the text string.
527
- # If not supplied all columns will be checked.
528
- #
529
- def click_table_row_with_text_by_id(browser, what, text, desc = '', column = nil)
530
- click_table_row_with_text(browser, :id, what, text, desc, column)
531
- end
532
-
533
- # Click the first row which contains a particular string in a table identified by its index
534
- # in the array of tables contained in <b>+browser+</b>.
535
- # A specific column in the table can also be specified.
536
- #
537
- # @param (see #click_table_row_with_text_by_id)
538
- #
539
- def click_table_row_with_text_by_index(browser, what, text, desc = '', column = nil)
540
- click_table_row_with_text(browser, :id, what, text, desc, column)
541
- end
542
-
543
- # Double click the first row which contains a particular string in a table identified by the value in its _id_ attribute.
544
- # A specific column in the table can also be specified.
545
- #
546
- # @param (see #click_table_row_with_text_by_id)
547
- #
548
- def double_click_table_row_with_text_by_id(browser, what, text, desc = '', column = nil)
549
- double_click_table_row_with_text(browser, :id, what, text, desc, column)
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__}) ")
550
516
  end
551
517
 
552
- # Double click the first row which contains a particular string in a table identified by its index
553
- # in the array of tables contained in <b>+browser+</b>.
554
- # A specific column in the table can also be specified.
555
- #
556
- # @param (see #click_table_row_with_text_by_id)
557
- #
558
- def double_click_table_row_with_text_by_index(browser, idx, what, column = nil)
559
- double_click_table_row_with_text(browser, :index, what, text, desc, column)
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__}) ")
560
539
  end
561
540
 
562
- # @!endgroup Tables
563
-
564
- # @!group Core
565
-
566
541
  def click_popup_button(title, button, waitTime= 9, user_input=nil)
567
542
  #TODO: is winclicker still viable/available?
568
543
  wc = WinClicker.new
@@ -590,94 +565,240 @@ module Awetestlib
590
565
  # end
591
566
  end
592
567
 
593
- def select_option_from_list(list, which, value, desc = '', nofail = false)
594
- msg = build_message("Select :#{which}=>'#{value}", desc)
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 = '')
595
591
  ok = true
592
+ msg = "#{__method__.to_s.titleize} "
596
593
  if list
597
- case which
594
+ msg << "list id=#{list.id}: "
595
+ case what
598
596
  when :text
599
- list.select(value) #TODO: regex?
597
+ list.select(what_strg) #TODO: regex?
600
598
  when :value
601
- list.select_value(value) #TODO: regex?
599
+ list.select_value(what_strg) #TODO: regex?
602
600
  when :index
603
- list.select(list.getAllContents[value.to_i])
601
+ list.select(list.getAllContents[what_strg.to_i])
604
602
  else
605
- failed_to_log("#{msg} Select by #{which} not supported.")
603
+ msg << "select by #{what} not supported. #{desc} (#{__LINE__})"
604
+ failed_to_log(msg)
606
605
  ok = false
607
606
  end
608
607
  if ok
608
+ msg << "#{what}='#{what_strg}' selected. #{desc}"
609
609
  passed_to_log(msg)
610
610
  true
611
- else
612
- if nofail
613
- passed_to_log("#{msg} Option not found. No Fail specified.")
614
- true
615
- else
616
- failed_to_log("#{msg} Option not found.")
617
- end
618
611
  end
619
612
  else
620
- failed_to_log("#{msg} Select list not found.")
613
+ failed_to_log("#{__method__.to_s.titleize} list not found. #{desc} (#{__LINE__})")
621
614
  end
622
615
  rescue
623
- failed_to_log("Unable to #{msg} '#{$!}'")
616
+ failed_to_log("#{__method__.to_s.titleize}: #{what}='#{what_strg}' could not be selected: '#{$!}'. #{desc} (#{__LINE__})")
624
617
  end
625
618
 
626
- def select_option(browser, how, what, which, value, desc = '', nofail = false)
627
- list = browser.select_list(how, what)
628
- msg = build_message(" from list with :#{how}=>'#{what}", desc)
629
- select_option_from_list(list, which, value, msg, nofail)
630
- end
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
631
622
 
632
- # @!endgroup Core
623
+ _Parameters_::
633
624
 
634
- # @!group Select
625
+ *browser* - a reference to the browser window to be tested
635
626
 
636
- def select_option_by_id_and_option_text(browser, what, option, nofail = false, desc = '')
637
- select_option(browser, :id, what, :text, option, desc, nofail)
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
638
656
  end
639
657
 
640
658
  alias select_option_by_id select_option_by_id_and_option_text
641
659
  alias select_option_by_id_and_text select_option_by_id_and_option_text
642
660
 
643
- def select_option_by_name_and_option_text(browser, what, option, desc = '')
644
- select_option(browser, :name, what, :text, option, desc)
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} '#{$!}'")
645
684
  end
646
685
 
647
686
  alias select_option_by_name select_option_by_name_and_option_text
648
687
 
649
- def select_option_by_title_and_option_text(browser, what, option, desc = '')
650
- select_option(browser, :title, what, :text, option, desc)
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} '#{$!}'")
651
697
  end
652
698
 
653
- def select_option_by_class_and_option_text(browser, what, option, desc = '')
654
- select_option(browser, :class, what, :text, option, desc)
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} '#{$!}'")
655
709
  end
656
710
 
657
- def select_option_by_name_and_option_value(browser, what, option, desc = '')
658
- select_option(browser, :name, what, :value, option, desc)
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} '#{$!}'")
659
734
  end
660
735
 
661
- def select_option_by_id_and_option_value(browser, what, option, desc = '')
662
- select_option(browser, :id, what, :value, option, desc)
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} '#{$!}'")
663
760
  end
664
761
 
665
- def select_option_by_id_and_index(browser, what, option, desc = '')
666
- select_option(browser, :id, what, :index, option, desc)
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} '#{$!}'")
667
775
  end
668
776
 
669
- def select_option_by_name_and_index(browser, what, option, desc = '')
670
- select_option(browser, :name, what, :index, option, desc)
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} '#{$!}'")
671
788
  end
672
789
 
673
- def select_option_by_xpath_and_index(browser, what, option, desc = '')
674
- select_option(browser, :xpath, what, :index, option, desc)
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} '#{$!}'")
675
800
  end
676
801
 
677
- # @!endgroup Select
678
-
679
- # @!group Core
680
-
681
802
  def set(browser, element, how, what, value = nil, desc = '')
682
803
  msg = "Set #{element} #{how}=>'#{what}' "
683
804
  msg << ", :value=>#{value} " if value
@@ -698,50 +819,28 @@ module Awetestlib
698
819
  failed_to_log("#{msg} '#{$!}'")
699
820
  end
700
821
 
701
- def set_file_field(browser, how, what, filespec, desc = '')
702
- msg = "Set file field #{how}=>#{what} to '#{filespec}."
703
- msg << " #{desc}" if desc.length > 0
704
- ff = browser.file_field(how, what)
705
- if ff
706
- ff.set filespec
707
- sleep_for(8)
708
- if validate(browser, @myName, __LINE__)
709
- passed_to_log(msg)
710
- true
711
- end
712
- else
713
- failed_to_log("#{msg} File field not found.")
714
- end
715
- rescue
716
- failed_to_log("Unable to #{msg} '#{$!}'")
717
- end
718
-
719
- # @!endgroup Core
720
-
721
- # @!group Set
722
-
723
822
  def set_checkbox(browser, how, what, value, desc = '')
724
823
  set(browser, :checkbox, how, what, value, desc)
725
824
  end
726
825
 
727
- def set_checkbox_by_class(browser, what, value = nil, desc = '')
728
- set(browser, :checkbox, :class, what, value, desc)
826
+ def set_checkbox_by_class(browser, strg, value = nil, desc = '')
827
+ set(browser, :checkbox, :class, strg, value, desc)
729
828
  end
730
829
 
731
- def set_checkbox_by_id(browser, what, value = nil, desc = '')
732
- set(browser, :checkbox, :id, what, value, desc)
830
+ def set_checkbox_by_id(browser, strg, value = nil, desc = '')
831
+ set(browser, :checkbox, :id, strg, value, desc)
733
832
  end
734
833
 
735
- def set_checkbox_by_name(browser, what, value = nil, desc = '')
736
- set(browser, :checkbox, :name, what, value, desc)
834
+ def set_checkbox_by_name(browser, strg, value = nil, desc = '')
835
+ set(browser, :checkbox, :name, strg, value, desc)
737
836
  end
738
837
 
739
- def set_checkbox_by_title(browser, what, value = nil, desc = '')
740
- set(browser, :checkbox, :title, what, value, desc)
838
+ def set_checkbox_by_title(browser, strg, value = nil, desc = '')
839
+ set(browser, :checkbox, :title, strg, value, desc)
741
840
  end
742
841
 
743
- def set_checkbox_by_value(browser, what, desc = '')
744
- set(browser, :checkbox, :value, what, nil, desc)
842
+ def set_checkbox_by_value(browser, strg, desc = '')
843
+ set(browser, :checkbox, :value, strg, nil, desc)
745
844
  end
746
845
 
747
846
  def set_radio(browser, how, what, value = nil, desc = '')
@@ -760,28 +859,28 @@ module Awetestlib
760
859
  failed_to_log("#{msg} '#{$!}'")
761
860
  end
762
861
 
763
- def set_radio_by_class(browser, what, value = nil, desc = '')
764
- set(browser, :radio, :class, what, value, desc)
862
+ def set_radio_by_class(browser, strg, value = nil, desc = '')
863
+ set(browser, :radio, :class, strg, value, desc)
765
864
  end
766
865
 
767
- def set_radio_by_id(browser, what, value = nil, desc = '')
768
- set(browser, :radio, :id, what, value, desc)
866
+ def set_radio_by_id(browser, strg, value = nil, desc = '')
867
+ set(browser, :radio, :id, strg, value, desc)
769
868
  end
770
869
 
771
870
  def set_radio_by_index(browser, index, desc = '')
772
871
  set(browser, :radio, :index, index, value, desc)
773
872
  end
774
873
 
775
- def set_radio_by_name(browser, what, value = nil, desc = '')
776
- set(browser, :radio, :name, what, value, desc)
874
+ def set_radio_by_name(browser, strg, value = nil, desc = '')
875
+ set(browser, :radio, :name, strg, value, desc)
777
876
  end
778
877
 
779
- def set_radio_by_title(browser, what, value = nil, desc = '')
780
- set(browser, :radio, :title, what, value, desc)
878
+ def set_radio_by_title(browser, strg, value = nil, desc = '')
879
+ set(browser, :radio, :title, strg, value, desc)
781
880
  end
782
881
 
783
- def set_radio_by_value(browser, what, desc = '')
784
- set(browser, :radio, :value, what, nil, desc)
882
+ def set_radio_by_value(browser, strg, desc = '')
883
+ set(browser, :radio, :value, strg, nil, desc)
785
884
  end
786
885
 
787
886
  def set_radio_no_wait_by_index(browser, index, desc = '')
@@ -814,22 +913,10 @@ module Awetestlib
814
913
  set_radio_two_attributes(browser, :value, value, :index, index, desc)
815
914
  end
816
915
 
817
- def set_radio_by_name_and_value(browser, what, value, desc = '')
818
- set_radio(browser, :name, what, value, desc)
819
- end
820
-
821
- def set_file_field_by_name(browser, what, path, desc = '')
822
- set_file_field(browser, :name, what, path, desc)
916
+ def set_radio_by_name_and_value(browser, strg, value, desc = '')
917
+ set_radio(browser, :name, strg, value, desc)
823
918
  end
824
919
 
825
- def set_file_field_by_id(browser, what, path, desc = '')
826
- set_file_field(browser, :id, what, path, desc)
827
- end
828
-
829
- # @!endgroup Set
830
-
831
- # @!group Core
832
-
833
920
  def clear(browser, element, how, what, value = nil, desc = '')
834
921
  msg = "Clear #{element} #{how}=>'#{what}' "
835
922
  msg << ", value=>#{value} " if value
@@ -852,28 +939,22 @@ module Awetestlib
852
939
  failed_to_log("#{msg} '#{$!}'")
853
940
  end
854
941
 
855
- # @!endgroup Core
856
-
857
- # @!group Clear
858
-
859
942
  def clear_checkbox(browser, how, what, value = nil, desc = '')
860
943
  clear(browser, :checkbox, how, what, value, desc)
861
944
  end
862
945
 
863
- def clear_checkbox_by_name(browser, what, value = nil, desc = '')
864
- clear(browser, :checkbox, :name, what, value, desc)
946
+ def clear_checkbox_by_name(browser, strg, value = nil, desc = '')
947
+ clear(browser, :checkbox, :name, strg, value, desc)
865
948
  end
866
949
 
867
- def clear_checkbox_by_id(browser, what, value = nil, desc = '')
868
- clear(browser, :checkbox, :id, what, value, desc)
950
+ def clear_checkbox_by_id(browser, strg, value = nil, desc = '')
951
+ clear(browser, :checkbox, :id, strg, value, desc)
869
952
  end
870
953
 
871
954
  def clear_radio(browser, how, what, value = nil, desc = '')
872
955
  clear(browser, :radio, how, what, value, desc)
873
956
  end
874
957
 
875
- # @!endgroup Clear
876
-
877
958
  # Set skip_value_check = true when string is altered by application and/or
878
959
  # this method will be followed by validate_text
879
960
  def clear_textfield(browser, how, which, skip_value_check = false)
@@ -900,6 +981,32 @@ module Awetestlib
900
981
  failed_to_log("Textfield id='#{id}' could not be cleared: '#{$!}'. (#{__LINE__})")
901
982
  end
902
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
+
903
1010
  =begin rdoc
904
1011
  :category: A_rdoc_test
905
1012
  Enter a string into a text field element identified by an attribute type and a value.
@@ -991,7 +1098,7 @@ _Example_
991
1098
 
992
1099
  =begin rdoc
993
1100
  :category: A_rdoc_test
994
- Enter a string into a text field element identifiedelement identified by the value in its id attribute.
1101
+ Enter a string into a text field element identified by the value in its id attribute.
995
1102
 
996
1103
  _Parameters_::
997
1104
 
@@ -1021,8 +1128,8 @@ _Example_
1021
1128
  set_text_field(browser, :title, title, value, desc, skip_value_check)
1022
1129
  end
1023
1130
 
1024
- def set_textfield_by_class(browser, what, value, desc = '', skip_value_check = false)
1025
- set_text_field(browser, :class, what, value, desc, skip_value_check)
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)
1026
1133
  end
1027
1134
 
1028
1135
  =begin rdoc
@@ -1062,26 +1169,34 @@ _Example_
1062
1169
  failed_to_log("Unable to '#{msg}': '#{$!}'")
1063
1170
  end
1064
1171
 
1065
- # @!group Core
1066
-
1067
- # Fire an event on a specific DOM element identified by one of its attributes and that attribute's value.
1068
- #
1069
- # @example
1070
- # # html for a link element:
1071
- # # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
1072
- #
1073
- # fire_event(browser, :link, :text, 'Pickaxe', 'onMouseOver')
1074
- #
1075
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
1076
- # @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
1077
- # Some common values are :link, :button, :image, :div, :span.
1078
- # @param [Symbol] how The element attribute used to identify the specific element.
1079
- # Valid values depend on the kind of element.
1080
- # Common values: :text, :id, :title, :name, :class, :href (:link only)
1081
- # @param [String|Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
1082
- # @param [String] event A string identifying the event to be fired.
1083
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
1084
- #
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
+
1085
1200
  def fire_event(browser, element, how, what, event, desc = '')
1086
1201
  msg = "#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'"
1087
1202
  msg1 = "#{element.to_s.titlecase}(#{how}, '#{what}')"
@@ -1112,60 +1227,28 @@ _Example_
1112
1227
  rescue
1113
1228
  failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
1114
1229
  end
1115
-
1116
- # @!endgroup Core
1117
-
1118
- # @!group Fire Event
1119
-
1120
- # Fire an event on a link element identified by the value in its text (innerHTML)
1121
- #
1122
- # @example
1123
- # # html for a link element:
1124
- # # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
1125
- #
1126
- # fire_event_on_link_by_text(browser, 'Pickaxe', 'onMouseOver')
1127
- #
1128
- # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
1129
- # @param [String|Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
1130
- # @param [String] event A string identifying the event to be fired.
1131
- # @param [String] desc Contains a message or description intended to appear in the log and/or report output
1132
- #
1133
- def fire_event_on_link_by_text(browser, what, event, desc = '')
1134
- fire_event(browser, :link, :text, what, event, desc)
1230
+
1231
+ def fire_event_on_link_by_text(browser, strg, event = 'onclick', desc = '')
1232
+ fire_event(browser, :link, :text, strg, event, desc)
1135
1233
  end
1136
1234
 
1137
1235
  alias fire_event_text fire_event_on_link_by_text
1138
1236
  alias fire_event_by_text fire_event_on_link_by_text
1139
1237
 
1140
- # Fire an event on a link element identified by the value in its _id_ attribute.
1141
- #
1142
- # @example
1143
- # # html for a link element:
1144
- # # <a href="http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe</a>
1145
- #
1146
- # fire_event_on_link_by_id(browser, 'one', 'onMouseOver')
1147
- #
1148
- # @param (see #fire_event_on_link_by_text)
1149
- #
1150
- def fire_event_on_link_by_id(browser, what, event, desc = '')
1151
- fire_event(browser, :link, :id, what, event, desc)
1238
+ def fire_event_on_link_by_id(browser, strg, event = 'onclick', desc = '')
1239
+ fire_event(browser, :link, :id, strg, event, desc)
1152
1240
  end
1153
1241
 
1154
1242
  alias fire_event_id fire_event_on_link_by_id
1155
1243
  alias fire_event_by_id fire_event_on_link_by_id
1156
1244
 
1157
- # Fire an event on a image element identified by the value in its _src_ attribute.
1158
- # Take care to escape characters in the source url that are reserved by Regexp.
1159
- # @param (see #fire_event_on_link_by_text)
1160
- #
1161
- def fire_event_on_image_by_src(browser, what, event, desc = '')
1162
- fire_event(browser, :img, :src, what, event, desc)
1245
+ def fire_event_on_image_by_src(browser, strg, event = 'onclick', desc = '')
1246
+ fire_event(browser, :img, :src, strg, event, desc)
1163
1247
  end
1164
1248
 
1165
1249
  alias fire_event_src fire_event_on_image_by_src
1166
1250
  alias fire_event_image_by_src fire_event_on_image_by_src
1167
1251
 
1168
- # @!endgroup Fire Event
1169
1252
 
1170
1253
  end
1171
1254
  end