awetestlib 0.1.28 → 0.1.29pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitattributes +22 -22
- data/.gitignore +69 -69
- data/.yardopts +7 -7
- data/README.md +108 -108
- data/awetestlib.gemspec +57 -57
- data/awetestlib.windows.gemspec +41 -41
- data/awetestlib_notes.txt +4 -4
- data/awetestlib_osx.gemspec +47 -48
- data/bin/awetestlib +99 -99
- data/bin/awetestlib-android-setup.rb +26 -26
- data/bin/awetestlib-cucumber-setup.rb +28 -28
- data/bin/awetestlib-driver-setup.rb +21 -21
- data/bin/awetestlib-helpers.rb +41 -41
- data/bin/awetestlib-mobile-app-setup.rb +31 -31
- data/bin/awetestlib-netbeans-setup.rb +58 -58
- data/bin/awetestlib-regression-setup.rb +15 -15
- data/bin/awetestlib-rubymine-setup.rb +39 -39
- data/drivers/chromedriver.exe +0 -0
- data/ext/Rakefile +1 -1
- data/ext/mkrf_conf.rb +27 -27
- data/lib/awetestlib/html_report.rb +142 -142
- data/lib/awetestlib/logging.rb +366 -366
- data/lib/awetestlib/regression/browser.rb +1380 -1375
- data/lib/awetestlib/regression/drag_and_drop.rb +421 -420
- data/lib/awetestlib/regression/find.rb +345 -345
- data/lib/awetestlib/regression/legacy.rb +1187 -1187
- data/lib/awetestlib/regression/page_data.rb +191 -191
- data/lib/awetestlib/regression/runner.rb +307 -307
- data/lib/awetestlib/regression/tables.rb +627 -619
- data/lib/awetestlib/regression/user_input.rb +576 -576
- data/lib/awetestlib/regression/utilities.rb +1046 -988
- data/lib/awetestlib/regression/validations.rb +1093 -1074
- data/lib/awetestlib/regression/waits.rb +470 -470
- data/lib/awetestlib/runner.rb +18 -18
- data/lib/awetestlib.rb +41 -41
- data/lib/patches/README +2 -2
- data/lib/patches/firewatir.rb +106 -106
- data/lib/patches/watir.rb +175 -175
- data/lib/version.rb +2 -2
- data/license.txt +13 -13
- data/netbeans_setup.md +29 -29
- data/rdoc_test.bat +1 -1
- data/rubymine_setup.md +23 -23
- data/setup_samples/sample_android/features/dk.mejer.hansen.control.FlyingColorsPlayerAidActivity.apk +0 -0
- data/setup_samples/sample_android/features/sample_android.feature +5 -5
- data/setup_samples/sample_android/features/step_definitions/calabash_steps.rb +1 -1
- data/setup_samples/sample_android/features/support/app_installation_hooks.rb +36 -36
- data/setup_samples/sample_android/features/support/app_life_cycle_hooks.rb +14 -14
- data/setup_samples/sample_android/features/test_servers/8ba795a0288381ae346b67867b586881_0.3.2.apk +0 -0
- data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +76 -76
- data/setup_samples/sample_cucumber/features/yahoo_mail.feature +11 -11
- data/setup_samples/sample_mobile_app/features/my_first.feature +14 -14
- data/setup_samples/sample_mobile_app/features/step_definitions/predefined_webview_steps.rb +80 -80
- data/setup_samples/sample_mobile_app/features/support/env.rb +2 -2
- data/setup_samples/sample_netbeans/demo.rb +86 -86
- data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -2
- data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -1
- data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +2 -2
- data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -2
- data/setup_samples/sample_netbeans/nbproject/project.properties +5 -5
- data/setup_samples/sample_netbeans/nbproject/project.xml +13 -13
- data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -5
- data/setup_samples/sample_rubymine/.idea/misc.xml +5 -5
- data/setup_samples/sample_rubymine/.idea/modules.xml +9 -9
- data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -9
- data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +4 -4
- data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -7
- data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -213
- data/setup_samples/sample_rubymine/demo.rb +86 -86
- data/test/create_zoho.rb +66 -66
- data/test/create_zoho_account1.rb +68 -68
- data/test/create_zoho_account2.rb +72 -72
- data/test/demo.rb +87 -87
- data/test/google_search1.rb +16 -16
- data/test/google_search2.rb +19 -19
- data/test/login_1.rb +37 -37
- data/test/login_1a.rb +37 -37
- data/test/login_2.rb +32 -32
- data/test/zoho_exercise.rb +21 -21
- data/test/zoho_util.rb +487 -487
- data/tmp/placeholder.html +71 -71
- metadata +18 -49
@@ -1,345 +1,345 @@
|
|
1
|
-
module Awetestlib
|
2
|
-
module Regression
|
3
|
-
# Methods to fetch references to DOM elements for assigning to variables. Includes collections of elements.
|
4
|
-
# Primary use is to limit the scope of other commands to the element passed in their *browser* parameter.
|
5
|
-
# (example here)
|
6
|
-
module Find
|
7
|
-
|
8
|
-
# @!group Core
|
9
|
-
|
10
|
-
# Return a reference to a DOM element specified by its type *element*, attribute *how*, and the
|
11
|
-
# contents of that attribute *what*. Some elements may require use of the *:value* attribute in addition
|
12
|
-
# to the designated one. The target contents for *:value* are supplied in *value*.
|
13
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
14
|
-
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
15
|
-
# Some common values are :link, :button, :image, :div, :span.
|
16
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
17
|
-
# Valid values depend on the kind of element.
|
18
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
19
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
20
|
-
# @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute that uniquely identifies the element.
|
21
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
22
|
-
def get_element(browser, element, how, what, value = nil, desc = '')
|
23
|
-
msg = build_message("Return #{element} with :#{how}=#{what}", value, desc)
|
24
|
-
target = nil
|
25
|
-
what = Regexp.new(Regexp.escape(what)) unless how == :index or what.is_a?(Regexp)
|
26
|
-
case element
|
27
|
-
when :link
|
28
|
-
target = browser.link(how, what)
|
29
|
-
when :button
|
30
|
-
target = browser.button(how, what)
|
31
|
-
when :div
|
32
|
-
target = browser.div(how, what)
|
33
|
-
when :checkbox
|
34
|
-
target = browser.checkbox(how, what, value)
|
35
|
-
when :text_field, :textfield
|
36
|
-
target = browser.text_field(how, what)
|
37
|
-
when :image
|
38
|
-
target = browser.image(how, what)
|
39
|
-
when :file_field, :filefield
|
40
|
-
target = browser.file_field(how, what)
|
41
|
-
when :form
|
42
|
-
target = browser.form(how, what)
|
43
|
-
when :frame
|
44
|
-
target = browser.frame(how, what)
|
45
|
-
when :radio
|
46
|
-
target = browser.radio(how, what, value)
|
47
|
-
when :span
|
48
|
-
target = browser.span(how, what)
|
49
|
-
when :table
|
50
|
-
target = browser.table(how, what)
|
51
|
-
when :li
|
52
|
-
target = browser.li(how, what)
|
53
|
-
when :select_list, :selectlist
|
54
|
-
target = browser.select_list(how, what)
|
55
|
-
when :hidden
|
56
|
-
target = browser.hidden(how, what)
|
57
|
-
when :area
|
58
|
-
target = browser.area(how, what)
|
59
|
-
else
|
60
|
-
target = browser.element(how, what)
|
61
|
-
end
|
62
|
-
if target.exists?
|
63
|
-
passed_to_log(msg)
|
64
|
-
target
|
65
|
-
else
|
66
|
-
failed_to_log(msg)
|
67
|
-
nil
|
68
|
-
end
|
69
|
-
rescue => e
|
70
|
-
unless rescue_me(e, __method__, rescue_me_command(target, how, what), "#{browser.class}", target)
|
71
|
-
raise e
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def get_attribute_value(browser, element, how, what, attribute, desc = '')
|
76
|
-
msg = build_message("Value of #{attribute} in #{element} #{how}=>#{what}.", desc)
|
77
|
-
case element
|
78
|
-
when :link
|
79
|
-
value = browser.link(how => what).attribute_value attribute
|
80
|
-
when :button
|
81
|
-
value = browser.button(how => what).attribute_value attribute
|
82
|
-
else
|
83
|
-
if browser.element(how => what).responds_to('attribute_value')
|
84
|
-
value = browser.element(how => what).attribute_value attribute
|
85
|
-
end
|
86
|
-
end
|
87
|
-
value
|
88
|
-
rescue
|
89
|
-
failed_to_log(" Unable to #{msg}: '#{$!}'")
|
90
|
-
end
|
91
|
-
|
92
|
-
# Return an array containing the options available for selection in a select_list identifified by
|
93
|
-
# its attribute *how*, and the contents of that attribute *what*.
|
94
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
95
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
96
|
-
# Valid values depend on the kind of element.
|
97
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
98
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
99
|
-
# that uniquely identifies the element.
|
100
|
-
# @param [Boolean] dump If set to true, a dump of the contents of the options will go to the log.
|
101
|
-
# See Utilities#dump_select_list_options
|
102
|
-
# @return [Array]
|
103
|
-
def get_select_options(browser, how, what, dump = false)
|
104
|
-
list = browser.select_list(how, what)
|
105
|
-
dump_select_list_options(list) if dump
|
106
|
-
list.options
|
107
|
-
rescue
|
108
|
-
failed_to_log("Unable to get select options for #{how}=>#{what}. '#{$!}'")
|
109
|
-
end
|
110
|
-
|
111
|
-
# Return an array containing the _selected_ options in a select_list identified by
|
112
|
-
# its attribute *how*, and the contents of that attribute *what*.
|
113
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
114
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
115
|
-
# Valid values depend on the kind of element.
|
116
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
117
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
118
|
-
# that uniquely identifies the element.
|
119
|
-
# @return [Array]
|
120
|
-
def get_selected_options(browser, how, what)
|
121
|
-
begin
|
122
|
-
list = browser.select_list(how, what)
|
123
|
-
rescue => e
|
124
|
-
unless rescue_me(e, __method__, rescue_me_command(:select_list, how, what), "#{browser.class}")
|
125
|
-
raise e
|
126
|
-
end
|
127
|
-
end
|
128
|
-
list.selected_options if list
|
129
|
-
end
|
130
|
-
|
131
|
-
# Return a reference to a div element identified by the contents *what* of its attribute *how*.
|
132
|
-
# This differs from get_element in that it waits for the element to exist before trying to return it.
|
133
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
134
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
135
|
-
# Valid values depend on the kind of element.
|
136
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
137
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
138
|
-
# that uniquely identifies the element.
|
139
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
140
|
-
# @param [Boolean] dbg If set to true additional debug logging is performed.
|
141
|
-
# @return [Watir::Div]
|
142
|
-
def get_div(browser, how, what, desc = '', dbg = false)
|
143
|
-
msg = build_message("Get :div #{how}=>#{what}.", desc)
|
144
|
-
Watir::Wait.until { browser.div(how, what).exists? }
|
145
|
-
div = browser.div(how, what)
|
146
|
-
debug_to_log(div.inspect) if dbg
|
147
|
-
if div
|
148
|
-
passed_to_log(msg)
|
149
|
-
return div
|
150
|
-
else
|
151
|
-
failed_to_log(msg)
|
152
|
-
end
|
153
|
-
rescue
|
154
|
-
failed_to_log("Unable to '#{msg}' '#{$!}'")
|
155
|
-
end
|
156
|
-
|
157
|
-
# Return a reference to a _span_ element identified by the contents *what* of its attribute *how*.
|
158
|
-
# This differs from get_element in that it waits for the element to exist before trying to return it.
|
159
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
160
|
-
# @param [Symbol] how The element attribute used to identify the specific element.
|
161
|
-
# Valid values depend on the kind of element.
|
162
|
-
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
163
|
-
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
164
|
-
# that uniquely identifies the element.
|
165
|
-
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
166
|
-
# @return [Watir::Span]
|
167
|
-
def get_span(browser, how, what, desc = '')
|
168
|
-
begin
|
169
|
-
Watir::Wait.until { browser.span(how, what).exists? }
|
170
|
-
rescue => e
|
171
|
-
unless rescue_me(e, __method__, rescue_me_command(:span, how, what, :exists?), "#{browser.class}")
|
172
|
-
raise e
|
173
|
-
end
|
174
|
-
end
|
175
|
-
begin
|
176
|
-
span = browser.span(how, what)
|
177
|
-
rescue => e
|
178
|
-
unless rescue_me(e, __method__, rescue_me_command(:span, how, what, :exists?), "#{browser.class}")
|
179
|
-
raise e
|
180
|
-
end
|
181
|
-
end
|
182
|
-
passed_to_log("Span #{how}='#{what}' found and returned. #{desc}")
|
183
|
-
return span
|
184
|
-
rescue
|
185
|
-
failed_to_log("Unable to return span #{how}='#{what}'. #{desc}: '#{$!}' (#{__LINE__})")
|
186
|
-
end
|
187
|
-
|
188
|
-
# Return a reference to a _form_ element identified by the contents *what* of its attribute *how*.
|
189
|
-
# @param (see #get_span)
|
190
|
-
# @return [Watir::Form]
|
191
|
-
def get_form(browser, how, what, desc = '')
|
192
|
-
get_element(browser, :form, how, what, desc)
|
193
|
-
end
|
194
|
-
|
195
|
-
# Return a reference to a _frame_ element identified by the contents *what* of its attribute *how*.
|
196
|
-
# @param (see #get_span)
|
197
|
-
# @return [Watir::Frame]
|
198
|
-
def get_frame(browser, how, what, desc = '')
|
199
|
-
get_element(browser, :frame, how, what, desc)
|
200
|
-
end
|
201
|
-
|
202
|
-
# Return a reference to a _select_list_ element identified by the contents *what* of its attribute *how*.
|
203
|
-
# @param (see #get_span)
|
204
|
-
# @return [Watir::SelectList]
|
205
|
-
def get_select_list(browser, how, what, desc = '')
|
206
|
-
get_element(browser, :select_list, how, what, desc)
|
207
|
-
end
|
208
|
-
|
209
|
-
# Return an array (collection) of all the elements of the type *which* contained in the browser or container
|
210
|
-
# supplied in *browser*.
|
211
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
212
|
-
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
213
|
-
# Some common values are :link, :button, :image, :div, :span.
|
214
|
-
# @param [Boolean] dbg If set to true additional debug logging is performed.
|
215
|
-
# @return [Array]
|
216
|
-
def get_element_collection(browser, element, dbg = false)
|
217
|
-
cnt = 0
|
218
|
-
case element
|
219
|
-
when :links, :link
|
220
|
-
list = browser.links
|
221
|
-
sleep(1)
|
222
|
-
when :tables, :table
|
223
|
-
list = browser.tables
|
224
|
-
when :divs, :div
|
225
|
-
list = browser.divs
|
226
|
-
when :buttons, :button
|
227
|
-
list = browser.buttons
|
228
|
-
when :checkboxes, :checkbox
|
229
|
-
list = browser.checkboxes
|
230
|
-
when :radios, :radio
|
231
|
-
list = browser.radios
|
232
|
-
when :selectlists, :select_lists, :selectlist, :select_list
|
233
|
-
list = browser.selectlists
|
234
|
-
when :textfields, :text_fields, :textareas, :text_fields, :textfield, :text_field, :textarea, :text_area
|
235
|
-
list = browser.textfields
|
236
|
-
when :lis, :li
|
237
|
-
list = browser.lis
|
238
|
-
when :uls, :ul
|
239
|
-
list = browser.uls
|
240
|
-
else
|
241
|
-
debug_to_log("Unsupported DOM object '#{which}'")
|
242
|
-
end
|
243
|
-
if dbg
|
244
|
-
list.each do |obj|
|
245
|
-
cnt += 1
|
246
|
-
debug_to_log("\n==========#{which}:\nindex: #{cnt}\n#{obj}\n#{obj.to_yaml}")
|
247
|
-
end
|
248
|
-
end
|
249
|
-
list
|
250
|
-
end
|
251
|
-
|
252
|
-
alias get_objects get_element_collection
|
253
|
-
|
254
|
-
# Return the ole object for the specified element.
|
255
|
-
# @note Usable only with classic Watir.
|
256
|
-
# @todo Detect $watir_script variable and disable if not set to true
|
257
|
-
# @param [Symbol] element A reference to the already identified element.
|
258
|
-
def get_ole(element)
|
259
|
-
ole = element.ole_object
|
260
|
-
if ole
|
261
|
-
passed_to_log("Found ole_object for #{element}.")
|
262
|
-
ole
|
263
|
-
else
|
264
|
-
failed_to_log("Did not find ole_object for #{element}.")
|
265
|
-
end
|
266
|
-
rescue
|
267
|
-
failed_to_log("Unable to find ole_object for #{element}. #{$!}")
|
268
|
-
end
|
269
|
-
|
270
|
-
# Return a hash of all links in *browser* with *:href* attribute containing the exact url in *href*.
|
271
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
272
|
-
# @param [String] href The exact url to be located.
|
273
|
-
# @return [Hash] The hash is indexed by the order in which the links were located in *browser*.
|
274
|
-
def find_all_links_with_exact_href(browser, href)
|
275
|
-
links = browser.links
|
276
|
-
hash = Hash.new
|
277
|
-
idx = 0
|
278
|
-
links.each do |l|
|
279
|
-
idx += 1
|
280
|
-
an_href = href
|
281
|
-
my_href = l.href
|
282
|
-
if my_href == an_href
|
283
|
-
hash[idx] = l
|
284
|
-
debug_to_log("#{__method__}:#{idx}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
285
|
-
end
|
286
|
-
end
|
287
|
-
hash
|
288
|
-
end
|
289
|
-
|
290
|
-
# Return a reference to the first link in *browser* with *:href* attribute containing the exact url in *href*.
|
291
|
-
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
292
|
-
# @param [String] href The exact url to be located.
|
293
|
-
# @return [Watir::Link]
|
294
|
-
def find_link_with_exact_href(browser, href)
|
295
|
-
links = browser.links
|
296
|
-
link = nil
|
297
|
-
index = 0
|
298
|
-
links.each do |l|
|
299
|
-
index += 1
|
300
|
-
an_href = href
|
301
|
-
my_href = l.href
|
302
|
-
if my_href == an_href
|
303
|
-
link = l
|
304
|
-
# debug_to_log("#{__method__}:#{__LINE__}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
305
|
-
break
|
306
|
-
end
|
307
|
-
end
|
308
|
-
link
|
309
|
-
end
|
310
|
-
|
311
|
-
# @!endgroup Core
|
312
|
-
|
313
|
-
# @!group Deprecated
|
314
|
-
|
315
|
-
# Find the index of an element within *browser* which has attribute *how* containing *what*
|
316
|
-
# @deprecated
|
317
|
-
def find_index_for_element(browser, element, how, ord, what)
|
318
|
-
element_sym = (element.to_s.pluralize).to_sym
|
319
|
-
how_str = how.to_s
|
320
|
-
ptrn = /#{how}:\s+#{what}/i
|
321
|
-
list = get_element_collection(browser, element_sym, true)
|
322
|
-
cnt = 0
|
323
|
-
idx = 0
|
324
|
-
list.each do |nty|
|
325
|
-
s = nty.to_s
|
326
|
-
# a = nty.to_a
|
327
|
-
if s =~ ptrn
|
328
|
-
cnt += 1
|
329
|
-
if cnt == ord
|
330
|
-
break
|
331
|
-
end
|
332
|
-
end
|
333
|
-
idx += 1
|
334
|
-
end
|
335
|
-
idx
|
336
|
-
end
|
337
|
-
|
338
|
-
alias find_index_for_object find_index_for_element
|
339
|
-
|
340
|
-
# @!endgroup Deprecated
|
341
|
-
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
1
|
+
module Awetestlib
|
2
|
+
module Regression
|
3
|
+
# Methods to fetch references to DOM elements for assigning to variables. Includes collections of elements.
|
4
|
+
# Primary use is to limit the scope of other commands to the element passed in their *browser* parameter.
|
5
|
+
# (example here)
|
6
|
+
module Find
|
7
|
+
|
8
|
+
# @!group Core
|
9
|
+
|
10
|
+
# Return a reference to a DOM element specified by its type *element*, attribute *how*, and the
|
11
|
+
# contents of that attribute *what*. Some elements may require use of the *:value* attribute in addition
|
12
|
+
# to the designated one. The target contents for *:value* are supplied in *value*.
|
13
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
14
|
+
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
15
|
+
# Some common values are :link, :button, :image, :div, :span.
|
16
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
17
|
+
# Valid values depend on the kind of element.
|
18
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
19
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
20
|
+
# @param [String, Regexp] value A string or a regular expression to be found in the *:value* attribute that uniquely identifies the element.
|
21
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
22
|
+
def get_element(browser, element, how, what, value = nil, desc = '')
|
23
|
+
msg = build_message("Return #{element} with :#{how}=#{what}", value, desc)
|
24
|
+
target = nil
|
25
|
+
what = Regexp.new(Regexp.escape(what)) unless how == :index or what.is_a?(Regexp)
|
26
|
+
case element
|
27
|
+
when :link
|
28
|
+
target = browser.link(how, what)
|
29
|
+
when :button
|
30
|
+
target = browser.button(how, what)
|
31
|
+
when :div
|
32
|
+
target = browser.div(how, what)
|
33
|
+
when :checkbox
|
34
|
+
target = browser.checkbox(how, what, value)
|
35
|
+
when :text_field, :textfield
|
36
|
+
target = browser.text_field(how, what)
|
37
|
+
when :image
|
38
|
+
target = browser.image(how, what)
|
39
|
+
when :file_field, :filefield
|
40
|
+
target = browser.file_field(how, what)
|
41
|
+
when :form
|
42
|
+
target = browser.form(how, what)
|
43
|
+
when :frame
|
44
|
+
target = browser.frame(how, what)
|
45
|
+
when :radio
|
46
|
+
target = browser.radio(how, what, value)
|
47
|
+
when :span
|
48
|
+
target = browser.span(how, what)
|
49
|
+
when :table
|
50
|
+
target = browser.table(how, what)
|
51
|
+
when :li
|
52
|
+
target = browser.li(how, what)
|
53
|
+
when :select_list, :selectlist
|
54
|
+
target = browser.select_list(how, what)
|
55
|
+
when :hidden
|
56
|
+
target = browser.hidden(how, what)
|
57
|
+
when :area
|
58
|
+
target = browser.area(how, what)
|
59
|
+
else
|
60
|
+
target = browser.element(how, what)
|
61
|
+
end
|
62
|
+
if target.exists?
|
63
|
+
passed_to_log(msg)
|
64
|
+
target
|
65
|
+
else
|
66
|
+
failed_to_log(msg)
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
rescue => e
|
70
|
+
unless rescue_me(e, __method__, rescue_me_command(target, how, what), "#{browser.class}", target)
|
71
|
+
raise e
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_attribute_value(browser, element, how, what, attribute, desc = '')
|
76
|
+
msg = build_message("Value of #{attribute} in #{element} #{how}=>#{what}.", desc)
|
77
|
+
case element
|
78
|
+
when :link
|
79
|
+
value = browser.link(how => what).attribute_value attribute
|
80
|
+
when :button
|
81
|
+
value = browser.button(how => what).attribute_value attribute
|
82
|
+
else
|
83
|
+
if browser.element(how => what).responds_to('attribute_value')
|
84
|
+
value = browser.element(how => what).attribute_value attribute
|
85
|
+
end
|
86
|
+
end
|
87
|
+
value
|
88
|
+
rescue
|
89
|
+
failed_to_log(" Unable to #{msg}: '#{$!}'")
|
90
|
+
end
|
91
|
+
|
92
|
+
# Return an array containing the options available for selection in a select_list identifified by
|
93
|
+
# its attribute *how*, and the contents of that attribute *what*.
|
94
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
95
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
96
|
+
# Valid values depend on the kind of element.
|
97
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
98
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
99
|
+
# that uniquely identifies the element.
|
100
|
+
# @param [Boolean] dump If set to true, a dump of the contents of the options will go to the log.
|
101
|
+
# See Utilities#dump_select_list_options
|
102
|
+
# @return [Array]
|
103
|
+
def get_select_options(browser, how, what, dump = false)
|
104
|
+
list = browser.select_list(how, what)
|
105
|
+
dump_select_list_options(list) if dump
|
106
|
+
list.options
|
107
|
+
rescue
|
108
|
+
failed_to_log("Unable to get select options for #{how}=>#{what}. '#{$!}'")
|
109
|
+
end
|
110
|
+
|
111
|
+
# Return an array containing the _selected_ options in a select_list identified by
|
112
|
+
# its attribute *how*, and the contents of that attribute *what*.
|
113
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
114
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
115
|
+
# Valid values depend on the kind of element.
|
116
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
117
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
118
|
+
# that uniquely identifies the element.
|
119
|
+
# @return [Array]
|
120
|
+
def get_selected_options(browser, how, what)
|
121
|
+
begin
|
122
|
+
list = browser.select_list(how, what)
|
123
|
+
rescue => e
|
124
|
+
unless rescue_me(e, __method__, rescue_me_command(:select_list, how, what), "#{browser.class}")
|
125
|
+
raise e
|
126
|
+
end
|
127
|
+
end
|
128
|
+
list.selected_options if list
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return a reference to a div element identified by the contents *what* of its attribute *how*.
|
132
|
+
# This differs from get_element in that it waits for the element to exist before trying to return it.
|
133
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
134
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
135
|
+
# Valid values depend on the kind of element.
|
136
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
137
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
138
|
+
# that uniquely identifies the element.
|
139
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
140
|
+
# @param [Boolean] dbg If set to true additional debug logging is performed.
|
141
|
+
# @return [Watir::Div]
|
142
|
+
def get_div(browser, how, what, desc = '', dbg = false)
|
143
|
+
msg = build_message("Get :div #{how}=>#{what}.", desc)
|
144
|
+
Watir::Wait.until { browser.div(how, what).exists? }
|
145
|
+
div = browser.div(how, what)
|
146
|
+
debug_to_log(div.inspect) if dbg
|
147
|
+
if div
|
148
|
+
passed_to_log(msg)
|
149
|
+
return div
|
150
|
+
else
|
151
|
+
failed_to_log(msg)
|
152
|
+
end
|
153
|
+
rescue
|
154
|
+
failed_to_log("Unable to '#{msg}' '#{$!}'")
|
155
|
+
end
|
156
|
+
|
157
|
+
# Return a reference to a _span_ element identified by the contents *what* of its attribute *how*.
|
158
|
+
# This differs from get_element in that it waits for the element to exist before trying to return it.
|
159
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
160
|
+
# @param [Symbol] how The element attribute used to identify the specific element.
|
161
|
+
# Valid values depend on the kind of element.
|
162
|
+
# Common values: :text, :id, :title, :name, :class, :href (:link only)
|
163
|
+
# @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute
|
164
|
+
# that uniquely identifies the element.
|
165
|
+
# @param [String] desc Contains a message or description intended to appear in the log and/or report output
|
166
|
+
# @return [Watir::Span]
|
167
|
+
def get_span(browser, how, what, desc = '')
|
168
|
+
begin
|
169
|
+
Watir::Wait.until { browser.span(how, what).exists? }
|
170
|
+
rescue => e
|
171
|
+
unless rescue_me(e, __method__, rescue_me_command(:span, how, what, :exists?), "#{browser.class}")
|
172
|
+
raise e
|
173
|
+
end
|
174
|
+
end
|
175
|
+
begin
|
176
|
+
span = browser.span(how, what)
|
177
|
+
rescue => e
|
178
|
+
unless rescue_me(e, __method__, rescue_me_command(:span, how, what, :exists?), "#{browser.class}")
|
179
|
+
raise e
|
180
|
+
end
|
181
|
+
end
|
182
|
+
passed_to_log("Span #{how}='#{what}' found and returned. #{desc}")
|
183
|
+
return span
|
184
|
+
rescue
|
185
|
+
failed_to_log("Unable to return span #{how}='#{what}'. #{desc}: '#{$!}' (#{__LINE__})")
|
186
|
+
end
|
187
|
+
|
188
|
+
# Return a reference to a _form_ element identified by the contents *what* of its attribute *how*.
|
189
|
+
# @param (see #get_span)
|
190
|
+
# @return [Watir::Form]
|
191
|
+
def get_form(browser, how, what, desc = '')
|
192
|
+
get_element(browser, :form, how, what, desc)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Return a reference to a _frame_ element identified by the contents *what* of its attribute *how*.
|
196
|
+
# @param (see #get_span)
|
197
|
+
# @return [Watir::Frame]
|
198
|
+
def get_frame(browser, how, what, desc = '')
|
199
|
+
get_element(browser, :frame, how, what, desc)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Return a reference to a _select_list_ element identified by the contents *what* of its attribute *how*.
|
203
|
+
# @param (see #get_span)
|
204
|
+
# @return [Watir::SelectList]
|
205
|
+
def get_select_list(browser, how, what, desc = '')
|
206
|
+
get_element(browser, :select_list, how, what, desc)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Return an array (collection) of all the elements of the type *which* contained in the browser or container
|
210
|
+
# supplied in *browser*.
|
211
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
212
|
+
# @param [Symbol] element The kind of element to click. Must be one of the elements recognized by Watir.
|
213
|
+
# Some common values are :link, :button, :image, :div, :span.
|
214
|
+
# @param [Boolean] dbg If set to true additional debug logging is performed.
|
215
|
+
# @return [Array]
|
216
|
+
def get_element_collection(browser, element, dbg = false)
|
217
|
+
cnt = 0
|
218
|
+
case element
|
219
|
+
when :links, :link
|
220
|
+
list = browser.links
|
221
|
+
sleep(1)
|
222
|
+
when :tables, :table
|
223
|
+
list = browser.tables
|
224
|
+
when :divs, :div
|
225
|
+
list = browser.divs
|
226
|
+
when :buttons, :button
|
227
|
+
list = browser.buttons
|
228
|
+
when :checkboxes, :checkbox
|
229
|
+
list = browser.checkboxes
|
230
|
+
when :radios, :radio
|
231
|
+
list = browser.radios
|
232
|
+
when :selectlists, :select_lists, :selectlist, :select_list
|
233
|
+
list = browser.selectlists
|
234
|
+
when :textfields, :text_fields, :textareas, :text_fields, :textfield, :text_field, :textarea, :text_area
|
235
|
+
list = browser.textfields
|
236
|
+
when :lis, :li
|
237
|
+
list = browser.lis
|
238
|
+
when :uls, :ul
|
239
|
+
list = browser.uls
|
240
|
+
else
|
241
|
+
debug_to_log("Unsupported DOM object '#{which}'")
|
242
|
+
end
|
243
|
+
if dbg
|
244
|
+
list.each do |obj|
|
245
|
+
cnt += 1
|
246
|
+
debug_to_log("\n==========#{which}:\nindex: #{cnt}\n#{obj}\n#{obj.to_yaml}")
|
247
|
+
end
|
248
|
+
end
|
249
|
+
list
|
250
|
+
end
|
251
|
+
|
252
|
+
alias get_objects get_element_collection
|
253
|
+
|
254
|
+
# Return the ole object for the specified element.
|
255
|
+
# @note Usable only with classic Watir.
|
256
|
+
# @todo Detect $watir_script variable and disable if not set to true
|
257
|
+
# @param [Symbol] element A reference to the already identified element.
|
258
|
+
def get_ole(element)
|
259
|
+
ole = element.ole_object
|
260
|
+
if ole
|
261
|
+
passed_to_log("Found ole_object for #{element}.")
|
262
|
+
ole
|
263
|
+
else
|
264
|
+
failed_to_log("Did not find ole_object for #{element}.")
|
265
|
+
end
|
266
|
+
rescue
|
267
|
+
failed_to_log("Unable to find ole_object for #{element}. #{$!}")
|
268
|
+
end
|
269
|
+
|
270
|
+
# Return a hash of all links in *browser* with *:href* attribute containing the exact url in *href*.
|
271
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
272
|
+
# @param [String] href The exact url to be located.
|
273
|
+
# @return [Hash] The hash is indexed by the order in which the links were located in *browser*.
|
274
|
+
def find_all_links_with_exact_href(browser, href)
|
275
|
+
links = browser.links
|
276
|
+
hash = Hash.new
|
277
|
+
idx = 0
|
278
|
+
links.each do |l|
|
279
|
+
idx += 1
|
280
|
+
an_href = href
|
281
|
+
my_href = l.href
|
282
|
+
if my_href == an_href
|
283
|
+
hash[idx] = l
|
284
|
+
debug_to_log("#{__method__}:#{idx}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
285
|
+
end
|
286
|
+
end
|
287
|
+
hash
|
288
|
+
end
|
289
|
+
|
290
|
+
# Return a reference to the first link in *browser* with *:href* attribute containing the exact url in *href*.
|
291
|
+
# @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
|
292
|
+
# @param [String] href The exact url to be located.
|
293
|
+
# @return [Watir::Link]
|
294
|
+
def find_link_with_exact_href(browser, href)
|
295
|
+
links = browser.links
|
296
|
+
link = nil
|
297
|
+
index = 0
|
298
|
+
links.each do |l|
|
299
|
+
index += 1
|
300
|
+
an_href = href
|
301
|
+
my_href = l.href
|
302
|
+
if my_href == an_href
|
303
|
+
link = l
|
304
|
+
# debug_to_log("#{__method__}:#{__LINE__}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
305
|
+
break
|
306
|
+
end
|
307
|
+
end
|
308
|
+
link
|
309
|
+
end
|
310
|
+
|
311
|
+
# @!endgroup Core
|
312
|
+
|
313
|
+
# @!group Deprecated
|
314
|
+
|
315
|
+
# Find the index of an element within *browser* which has attribute *how* containing *what*
|
316
|
+
# @deprecated
|
317
|
+
def find_index_for_element(browser, element, how, ord, what)
|
318
|
+
element_sym = (element.to_s.pluralize).to_sym
|
319
|
+
how_str = how.to_s
|
320
|
+
ptrn = /#{how}:\s+#{what}/i
|
321
|
+
list = get_element_collection(browser, element_sym, true)
|
322
|
+
cnt = 0
|
323
|
+
idx = 0
|
324
|
+
list.each do |nty|
|
325
|
+
s = nty.to_s
|
326
|
+
# a = nty.to_a
|
327
|
+
if s =~ ptrn
|
328
|
+
cnt += 1
|
329
|
+
if cnt == ord
|
330
|
+
break
|
331
|
+
end
|
332
|
+
end
|
333
|
+
idx += 1
|
334
|
+
end
|
335
|
+
idx
|
336
|
+
end
|
337
|
+
|
338
|
+
alias find_index_for_object find_index_for_element
|
339
|
+
|
340
|
+
# @!endgroup Deprecated
|
341
|
+
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|