awetestlib 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,8 +31,9 @@ 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')
34
35
 
35
-
36
+ s.has_rdoc = 'yard'
36
37
  s.require_paths = ["lib"]
37
38
  s.files = `git ls-files`.split("\n")
38
39
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -44,7 +44,11 @@ module Awetestlib
44
44
  ::PASS = '-PASS'
45
45
  ::FAIL = '-FAIL'
46
46
 
47
- attr_accessor :browser, :browser_abbrev, :version, :env,
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,
48
52
  :library, :script_type, :script_file,
49
53
  :log_properties, :log_queue, :log_class,
50
54
  :notify_queue, :notify_class, :notify_id,
@@ -160,6 +164,7 @@ module Awetestlib
160
164
  options.each_pair do |k, v|
161
165
  self.send("#{k}=", v)
162
166
  end
167
+ script_file = options[:script_file]
163
168
  load script_file
164
169
  setup_global_test_vars(options)
165
170
 
@@ -2,19 +2,44 @@ module Awetestlib
2
2
  module Regression
3
3
  module Tables
4
4
 
5
- def get_index_for_column_head(panel, table_index, strg)
5
+ def get_index_for_column_head(panel, table_index, strg, desc = '')
6
+ table = panel.tables[table_index]
7
+ get_column_index(table, strg, desc, true)
8
+ end
9
+
10
+ def get_column_index(table, strg, desc = '', header = false)
11
+ msg = "Get index of "
12
+ msg << " header" if header
13
+ msg << " column containing #{strg}. "
14
+ msg << " #{desc}" if desc.length > 0
6
15
  rgx = Regexp.new(strg)
7
- panel.tables[table_index].each do |row|
16
+ row_idx = 0
17
+ index = -1
18
+ found = false
19
+ table.each do |row|
20
+ row_idx += 1
8
21
  if row.text =~ rgx
9
- index = 1
22
+ col_idx = 1
10
23
  row.each do |cell|
11
24
  if cell.text =~ rgx
12
- return index
25
+ index = col_idx
26
+ found = true
27
+ break
13
28
  end
14
- index += 1
29
+ col_idx += 1
15
30
  end
16
31
  end
32
+ break if found or header
33
+ end
34
+ if found
35
+ passed_to_log("#{msg} at index #{index}.")
36
+ index
37
+ else
38
+ failed_to_log("#{msg}")
39
+ nil
17
40
  end
41
+ rescue
42
+ failed_to_log("Unable to #{msg} '#{$!}'")
18
43
  end
19
44
 
20
45
  def get_index_of_last_row(table, pad = 2, every = 1)
@@ -2,36 +2,28 @@ module Awetestlib
2
2
  module Regression
3
3
  module UserInput
4
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
-
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
+ #
31
24
  def click(browser, element, how, what, desc = '')
32
25
  #debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
33
- msg = "Click #{element} :#{how}=>'#{what}'"
34
- msg << ", '#{desc}'" if desc.length > 0
26
+ msg = build_message("Click #{element} :#{how}=>'#{what}'", desc)
35
27
  msg1 = "#{element}(#{how}, '#{what}')"
36
28
  begin
37
29
  case element
@@ -66,38 +58,180 @@ _Example_
66
58
  failed_to_log("Unable to #{msg}. '#{$!}'")
67
59
  end
68
60
 
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.
61
+ # @!endgroup Core
74
62
 
75
- _Parameters_::
63
+ # @!group Click
76
64
 
77
- *browser* - a reference to the browser window to be tested
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
78
73
 
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.
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
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)
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
84
87
 
85
- *what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
88
+ alias click_href click_link_by_href
86
89
 
87
- *desc* - a string containing a message or description intended to appear in the log and/or report output
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
88
96
 
89
- _Example_
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
90
102
 
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')
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
94
108
 
95
- =end
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
173
+
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
96
179
 
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
185
+
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
189
+
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
195
+
196
+ alias click_class click_link_by_class
197
+
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
203
+
204
+ alias click_span_with_text click_span_by_text
205
+
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
211
+
212
+ alias click_title click_link_by_title
213
+
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
+ #
97
232
  def click_no_wait(browser, element, how, what, desc = '')
98
233
  debug_to_log("#{__method__}: #{element}, #{how}, #{what}")
99
- msg = "Click no wait #{element} :#{how}=>'#{what}'"
100
- msg << ", '#{desc}'" if desc.length > 0
234
+ msg = build_message("Click no wait #{element} :#{how}=>'#{what}'", desc)
101
235
  msg1 = "#{element}(#{how}, '#{what}'"
102
236
  begin
103
237
  case element
@@ -139,197 +273,172 @@ _Example_
139
273
  sleep_for(1)
140
274
  end
141
275
 
142
- # :category: User Input
143
- def click_button_by_id(browser, strg, desc = '')
144
- click(browser, :button, :id, strg, desc)
145
- end
276
+ # @!endgroup Core
146
277
 
147
- # :category: User Input
148
- def click_link_by_index(browser, strg, desc = '')
149
- click(browser, :link, :index, strg, desc)
150
- end
278
+ alias click_href_no_wait click_link_no_wait_by_href
151
279
 
152
- # :category: User Input
153
- def click_link_by_href(browser, strg, desc = '')
154
- click(browser, :link, :href, strg, desc)
155
- end
280
+ # @!group Click No Wait
156
281
 
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)
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)
161
287
  end
162
288
 
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)
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)
167
296
  end
168
297
 
169
- # :category: User Input
170
- def click_button_by_name(browser, strg, desc = '')
171
- click(browser, :button, :name, strg, desc)
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)
172
303
  end
173
304
 
174
- # :category: User Input
175
- def click_button_by_text(browser, strg, desc = '')
176
- click(browser, :button, :text, strg, desc)
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)
177
312
  end
178
313
 
179
- # :category: User Input
180
- def click_button_by_class(browser, strg, desc = '')
181
- click(browser, :button, :class, strg, desc)
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)
182
324
  end
183
325
 
184
- # :category: User Input
185
- def click_button_no_wait_by_id(browser, strg, desc = '')
186
- click_no_wait(browser, :button, :id, strg, desc)
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)
187
333
  end
188
334
 
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)
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)
193
340
  end
194
341
 
195
- # :category: User Input
196
- def click_button_no_wait_by_class(browser, strg, desc = '')
197
- click_no_wait(browser, :button, :class, strg, desc)
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)
198
347
  end
199
348
 
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)
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)
204
357
  end
205
358
 
206
- # :category: User Input
207
- def click_button_by_title(browser, strg, desc = '')
208
- click(browser, :button, :title, strg, desc)
359
+ alias click_no_wait_text click_link_by_text_no_wait
360
+ alias click_text_no_wait click_link_by_text_no_wait
361
+
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)
209
367
  end
210
368
 
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
369
+ # @!endgroup Click No Wait
370
+
371
+ # @!group Xpath
372
+
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
215
380
  passed_to_log(msg)
216
381
  true
217
382
  else
218
383
  failed_to_log(msg)
219
384
  end
220
385
  rescue
221
- failed_to_log("Unable to click button by xpath and id '#{strg}' #{desc} '#{$!}' (#{__LINE__})")
386
+ failed_to_log("Unable to click button by xpath and id '#{what}' #{desc} '#{$!}' (#{__LINE__})")
222
387
  end
223
388
 
224
389
  alias click_button_by_xpath click_button_by_xpath_and_id
225
390
 
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
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
264
397
  passed_to_log(msg)
265
398
  true
266
399
  else
267
400
  failed_to_log(msg)
268
401
  end
269
402
  rescue
270
- failed_to_log("Unable click on link by xpath and id '#{strg}' #{desc} '#{$!}' (#{__LINE__})")
403
+ failed_to_log("Unable to #{msg} '#{$!}' (#{__LINE__})")
271
404
  end
272
405
 
273
406
  alias click_link_by_xpath click_link_by_xpath_and_id
274
407
 
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
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
304
414
  passed_to_log(msg)
305
415
  true
306
416
  else
307
417
  failed_to_log(msg)
308
418
  end
309
419
  rescue
310
- failed_to_log("Unable to click image by xpath where name='#{strg}' #{desc} '#{$!}'")
420
+ failed_to_log("Unable to click image by xpath where name='#{what}' #{desc} '#{$!}'")
311
421
  end
312
422
 
313
423
  alias click_img_by_xpath click_img_by_xpath_and_name
314
424
  alias click_image_by_xpath click_img_by_xpath_and_name
315
425
  alias click_image_by_xpath_and_name click_img_by_xpath_and_name
316
426
 
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
427
+ # @!endgroup Xpath
321
428
 
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
429
+ # @!group Core
327
430
 
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}"
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}"
331
440
  msg << " #{desc}" if desc.length > 0
332
- browser.image(:src => strg, :index => index).click
441
+ browser.image(:src => what, :index => index).click
333
442
  if validate(browser, @myName, __LINE__)
334
443
  passed_to_log(msg)
335
444
  true
@@ -338,206 +447,122 @@ _Example_
338
447
  failed_to_log("Unable to #{msg} '#{$!}'")
339
448
  end
340
449
 
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}/)
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)
457
470
  if table
458
- index = get_index_of_row_with_text(table, strg, column)
471
+ index = get_index_of_row_with_text(table, text, column)
459
472
  if index
460
473
  table[index].click
461
474
  if validate(browser, @myName, __LINE__)
462
- passed_to_log("Click #{msg} row index=#{index}.")
475
+ passed_to_log(msg)
463
476
  index
464
477
  end
465
478
  else
466
- failed_to_log("Table #{msg} not found to click.")
479
+ failed_to_log("#{msg} Row not found.")
467
480
  end
468
481
  else
469
- failed_to_log("Table id=#{ptrn} not found.")
482
+ failed_to_log("#{msg} Table not found.")
470
483
  end
471
484
  rescue
472
- failed_to_log("Unable to click table #{msg}: '#{$!}' (#{__LINE__}) ")
485
+ failed_to_log("Unable to #{msg}: '#{$!}'")
473
486
  end
474
487
 
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)
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)
479
497
  if table
480
- index = get_index_of_row_with_text(table, strg, column)
498
+ index = get_index_of_row_with_text(table, text, column)
481
499
  if index
482
- table[index].click
500
+ table[index].fire_event('ondblclick')
483
501
  if validate(browser, @myName, __LINE__)
484
- passed_to_log("Click #{msg} row index=#{index}.")
502
+ passed_to_log(msg)
485
503
  index
486
504
  end
487
505
  else
488
- failed_to_log("Table #{msg} not found to click.")
506
+ failed_to_log("#{msg} Row not found.")
489
507
  end
490
508
  else
491
- failed_to_log("Table id=#{ptrn} not found.")
509
+ failed_to_log("#{msg} Table not found.")
492
510
  end
493
511
  rescue
494
- failed_to_log("Unable to click table #{msg}: '#{$!}' (#{__LINE__}) ")
512
+ failed_to_log("Unable to #{msg}: '#{$!}'")
495
513
  end
496
514
 
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__}) ")
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)
516
531
  end
517
532
 
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__}) ")
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)
550
+ end
551
+
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)
539
560
  end
540
561
 
562
+ # @!endgroup Tables
563
+
564
+ # @!group Core
565
+
541
566
  def click_popup_button(title, button, waitTime= 9, user_input=nil)
542
567
  #TODO: is winclicker still viable/available?
543
568
  wc = WinClicker.new
@@ -565,240 +590,94 @@ _Example_
565
590
  # end
566
591
  end
567
592
 
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 = '')
593
+ def select_option_from_list(list, which, value, desc = '', nofail = false)
594
+ msg = build_message("Select :#{which}=>'#{value}", desc)
591
595
  ok = true
592
- msg = "#{__method__.to_s.titleize} "
593
596
  if list
594
- msg << "list id=#{list.id}: "
595
- case what
597
+ case which
596
598
  when :text
597
- list.select(what_strg) #TODO: regex?
599
+ list.select(value) #TODO: regex?
598
600
  when :value
599
- list.select_value(what_strg) #TODO: regex?
601
+ list.select_value(value) #TODO: regex?
600
602
  when :index
601
- list.select(list.getAllContents[what_strg.to_i])
603
+ list.select(list.getAllContents[value.to_i])
602
604
  else
603
- msg << "select by #{what} not supported. #{desc} (#{__LINE__})"
604
- failed_to_log(msg)
605
+ failed_to_log("#{msg} Select by #{which} not supported.")
605
606
  ok = false
606
607
  end
607
608
  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
611
618
  end
612
619
  else
613
- failed_to_log("#{__method__.to_s.titleize} list not found. #{desc} (#{__LINE__})")
620
+ failed_to_log("#{msg} Select list not found.")
614
621
  end
615
622
  rescue
616
- failed_to_log("#{__method__.to_s.titleize}: #{what}='#{what_strg}' could not be selected: '#{$!}'. #{desc} (#{__LINE__})")
623
+ failed_to_log("Unable to #{msg} '#{$!}'")
617
624
  end
618
625
 
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_
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
635
631
 
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')
632
+ # @!endgroup Core
639
633
 
640
- =end
634
+ # @!group Select
641
635
 
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
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)
656
638
  end
657
639
 
658
640
  alias select_option_by_id select_option_by_id_and_option_text
659
641
  alias select_option_by_id_and_text select_option_by_id_and_option_text
660
642
 
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} '#{$!}'")
643
+ def select_option_by_name_and_option_text(browser, what, option, desc = '')
644
+ select_option(browser, :name, what, :text, option, desc)
684
645
  end
685
646
 
686
647
  alias select_option_by_name select_option_by_name_and_option_text
687
648
 
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} '#{$!}'")
649
+ def select_option_by_title_and_option_text(browser, what, option, desc = '')
650
+ select_option(browser, :title, what, :text, option, desc)
697
651
  end
698
652
 
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} '#{$!}'")
653
+ def select_option_by_class_and_option_text(browser, what, option, desc = '')
654
+ select_option(browser, :class, what, :text, option, desc)
709
655
  end
710
656
 
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} '#{$!}'")
657
+ def select_option_by_name_and_option_value(browser, what, option, desc = '')
658
+ select_option(browser, :name, what, :value, option, desc)
734
659
  end
735
660
 
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} '#{$!}'")
661
+ def select_option_by_id_and_option_value(browser, what, option, desc = '')
662
+ select_option(browser, :id, what, :value, option, desc)
760
663
  end
761
664
 
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} '#{$!}'")
665
+ def select_option_by_id_and_index(browser, what, option, desc = '')
666
+ select_option(browser, :id, what, :index, option, desc)
775
667
  end
776
668
 
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} '#{$!}'")
669
+ def select_option_by_name_and_index(browser, what, option, desc = '')
670
+ select_option(browser, :name, what, :index, option, desc)
788
671
  end
789
672
 
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} '#{$!}'")
673
+ def select_option_by_xpath_and_index(browser, what, option, desc = '')
674
+ select_option(browser, :xpath, what, :index, option, desc)
800
675
  end
801
676
 
677
+ # @!endgroup Select
678
+
679
+ # @!group Core
680
+
802
681
  def set(browser, element, how, what, value = nil, desc = '')
803
682
  msg = "Set #{element} #{how}=>'#{what}' "
804
683
  msg << ", :value=>#{value} " if value
@@ -819,28 +698,50 @@ _Example_
819
698
  failed_to_log("#{msg} '#{$!}'")
820
699
  end
821
700
 
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
+
822
723
  def set_checkbox(browser, how, what, value, desc = '')
823
724
  set(browser, :checkbox, how, what, value, desc)
824
725
  end
825
726
 
826
- def set_checkbox_by_class(browser, strg, value = nil, desc = '')
827
- set(browser, :checkbox, :class, strg, value, desc)
727
+ def set_checkbox_by_class(browser, what, value = nil, desc = '')
728
+ set(browser, :checkbox, :class, what, value, desc)
828
729
  end
829
730
 
830
- def set_checkbox_by_id(browser, strg, value = nil, desc = '')
831
- set(browser, :checkbox, :id, strg, value, desc)
731
+ def set_checkbox_by_id(browser, what, value = nil, desc = '')
732
+ set(browser, :checkbox, :id, what, value, desc)
832
733
  end
833
734
 
834
- def set_checkbox_by_name(browser, strg, value = nil, desc = '')
835
- set(browser, :checkbox, :name, strg, value, desc)
735
+ def set_checkbox_by_name(browser, what, value = nil, desc = '')
736
+ set(browser, :checkbox, :name, what, value, desc)
836
737
  end
837
738
 
838
- def set_checkbox_by_title(browser, strg, value = nil, desc = '')
839
- set(browser, :checkbox, :title, strg, value, desc)
739
+ def set_checkbox_by_title(browser, what, value = nil, desc = '')
740
+ set(browser, :checkbox, :title, what, value, desc)
840
741
  end
841
742
 
842
- def set_checkbox_by_value(browser, strg, desc = '')
843
- set(browser, :checkbox, :value, strg, nil, desc)
743
+ def set_checkbox_by_value(browser, what, desc = '')
744
+ set(browser, :checkbox, :value, what, nil, desc)
844
745
  end
845
746
 
846
747
  def set_radio(browser, how, what, value = nil, desc = '')
@@ -859,28 +760,28 @@ _Example_
859
760
  failed_to_log("#{msg} '#{$!}'")
860
761
  end
861
762
 
862
- def set_radio_by_class(browser, strg, value = nil, desc = '')
863
- set(browser, :radio, :class, strg, value, desc)
763
+ def set_radio_by_class(browser, what, value = nil, desc = '')
764
+ set(browser, :radio, :class, what, value, desc)
864
765
  end
865
766
 
866
- def set_radio_by_id(browser, strg, value = nil, desc = '')
867
- set(browser, :radio, :id, strg, value, desc)
767
+ def set_radio_by_id(browser, what, value = nil, desc = '')
768
+ set(browser, :radio, :id, what, value, desc)
868
769
  end
869
770
 
870
771
  def set_radio_by_index(browser, index, desc = '')
871
772
  set(browser, :radio, :index, index, value, desc)
872
773
  end
873
774
 
874
- def set_radio_by_name(browser, strg, value = nil, desc = '')
875
- set(browser, :radio, :name, strg, value, desc)
775
+ def set_radio_by_name(browser, what, value = nil, desc = '')
776
+ set(browser, :radio, :name, what, value, desc)
876
777
  end
877
778
 
878
- def set_radio_by_title(browser, strg, value = nil, desc = '')
879
- set(browser, :radio, :title, strg, value, desc)
779
+ def set_radio_by_title(browser, what, value = nil, desc = '')
780
+ set(browser, :radio, :title, what, value, desc)
880
781
  end
881
782
 
882
- def set_radio_by_value(browser, strg, desc = '')
883
- set(browser, :radio, :value, strg, nil, desc)
783
+ def set_radio_by_value(browser, what, desc = '')
784
+ set(browser, :radio, :value, what, nil, desc)
884
785
  end
885
786
 
886
787
  def set_radio_no_wait_by_index(browser, index, desc = '')
@@ -913,10 +814,22 @@ _Example_
913
814
  set_radio_two_attributes(browser, :value, value, :index, index, desc)
914
815
  end
915
816
 
916
- def set_radio_by_name_and_value(browser, strg, value, desc = '')
917
- set_radio(browser, :name, strg, value, desc)
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)
918
823
  end
919
824
 
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
+
920
833
  def clear(browser, element, how, what, value = nil, desc = '')
921
834
  msg = "Clear #{element} #{how}=>'#{what}' "
922
835
  msg << ", value=>#{value} " if value
@@ -939,22 +852,28 @@ _Example_
939
852
  failed_to_log("#{msg} '#{$!}'")
940
853
  end
941
854
 
855
+ # @!endgroup Core
856
+
857
+ # @!group Clear
858
+
942
859
  def clear_checkbox(browser, how, what, value = nil, desc = '')
943
860
  clear(browser, :checkbox, how, what, value, desc)
944
861
  end
945
862
 
946
- def clear_checkbox_by_name(browser, strg, value = nil, desc = '')
947
- clear(browser, :checkbox, :name, strg, value, desc)
863
+ def clear_checkbox_by_name(browser, what, value = nil, desc = '')
864
+ clear(browser, :checkbox, :name, what, value, desc)
948
865
  end
949
866
 
950
- def clear_checkbox_by_id(browser, strg, value = nil, desc = '')
951
- clear(browser, :checkbox, :id, strg, value, desc)
867
+ def clear_checkbox_by_id(browser, what, value = nil, desc = '')
868
+ clear(browser, :checkbox, :id, what, value, desc)
952
869
  end
953
870
 
954
871
  def clear_radio(browser, how, what, value = nil, desc = '')
955
872
  clear(browser, :radio, how, what, value, desc)
956
873
  end
957
874
 
875
+ # @!endgroup Clear
876
+
958
877
  # Set skip_value_check = true when string is altered by application and/or
959
878
  # this method will be followed by validate_text
960
879
  def clear_textfield(browser, how, which, skip_value_check = false)
@@ -981,32 +900,6 @@ _Example_
981
900
  failed_to_log("Textfield id='#{id}' could not be cleared: '#{$!}'. (#{__LINE__})")
982
901
  end
983
902
 
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
903
  =begin rdoc
1011
904
  :category: A_rdoc_test
1012
905
  Enter a string into a text field element identified by an attribute type and a value.
@@ -1098,7 +991,7 @@ _Example_
1098
991
 
1099
992
  =begin rdoc
1100
993
  :category: A_rdoc_test
1101
- Enter a string into a text field element identified by the value in its id attribute.
994
+ Enter a string into a text field element identifiedelement identified by the value in its id attribute.
1102
995
 
1103
996
  _Parameters_::
1104
997
 
@@ -1128,8 +1021,8 @@ _Example_
1128
1021
  set_text_field(browser, :title, title, value, desc, skip_value_check)
1129
1022
  end
1130
1023
 
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)
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)
1133
1026
  end
1134
1027
 
1135
1028
  =begin rdoc
@@ -1169,34 +1062,26 @@ _Example_
1169
1062
  failed_to_log("Unable to '#{msg}': '#{$!}'")
1170
1063
  end
1171
1064
 
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
-
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
+ #
1200
1085
  def fire_event(browser, element, how, what, event, desc = '')
1201
1086
  msg = "#{element.to_s.titlecase}: #{how}=>'#{what}' event:'#{event}'"
1202
1087
  msg1 = "#{element.to_s.titlecase}(#{how}, '#{what}')"
@@ -1227,28 +1112,60 @@ _Example_
1227
1112
  rescue
1228
1113
  failed_to_log("Unable to fire event: #{msg}. '#{$!}' #{desc}")
1229
1114
  end
1230
-
1231
- def fire_event_on_link_by_text(browser, strg, event = 'onclick', desc = '')
1232
- fire_event(browser, :link, :text, strg, event, desc)
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)
1233
1135
  end
1234
1136
 
1235
1137
  alias fire_event_text fire_event_on_link_by_text
1236
1138
  alias fire_event_by_text fire_event_on_link_by_text
1237
1139
 
1238
- def fire_event_on_link_by_id(browser, strg, event = 'onclick', desc = '')
1239
- fire_event(browser, :link, :id, strg, event, desc)
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)
1240
1152
  end
1241
1153
 
1242
1154
  alias fire_event_id fire_event_on_link_by_id
1243
1155
  alias fire_event_by_id fire_event_on_link_by_id
1244
1156
 
1245
- def fire_event_on_image_by_src(browser, strg, event = 'onclick', desc = '')
1246
- fire_event(browser, :img, :src, strg, event, desc)
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)
1247
1163
  end
1248
1164
 
1249
1165
  alias fire_event_src fire_event_on_image_by_src
1250
1166
  alias fire_event_image_by_src fire_event_on_image_by_src
1251
1167
 
1168
+ # @!endgroup Fire Event
1252
1169
 
1253
1170
  end
1254
1171
  end