awetestlib 0.1.3-x86-mingw32 → 0.1.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/awetestlib.windows.gemspec +1 -1
- data/bin/awetestlib +11 -4
- data/bin/awetestlib-helpers.rb +28 -1
- data/bin/awetestlib-netbeans-setup.rb +39 -0
- data/bin/awetestlib-rubymine-setup.rb +33 -0
- data/images/logo.png +0 -0
- data/lib/awetestlib/html_report.rb +171 -0
- data/lib/{regression → awetestlib}/logging.rb +10 -43
- data/lib/awetestlib/regression/browser.rb +1233 -0
- data/lib/awetestlib/regression/drag_and_drop.rb +379 -0
- data/lib/awetestlib/regression/find.rb +431 -0
- data/lib/awetestlib/regression/legacy.rb +45 -0
- data/lib/awetestlib/regression/page_data.rb +190 -0
- data/lib/awetestlib/regression/runner.rb +306 -0
- data/lib/awetestlib/regression/tables.rb +491 -0
- data/lib/awetestlib/regression/user_input.rb +1256 -0
- data/lib/awetestlib/regression/utilities.rb +895 -0
- data/lib/awetestlib/regression/validations.rb +1184 -0
- data/lib/awetestlib/regression/waits.rb +391 -0
- data/lib/awetestlib/runner.rb +16 -0
- data/lib/awetestlib.rb +4 -4
- data/lib/version.rb +2 -2
- data/setup_samples/sample_netbeans/demo.rb +86 -0
- data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -0
- data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -0
- data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +1 -0
- data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -0
- data/setup_samples/sample_netbeans/nbproject/project.properties +5 -0
- data/setup_samples/sample_netbeans/nbproject/project.xml +13 -0
- data/setup_samples/sample_rubymine/.idea/.name +1 -0
- data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -0
- data/setup_samples/sample_rubymine/.idea/misc.xml +5 -0
- data/setup_samples/sample_rubymine/.idea/modules.xml +9 -0
- data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -0
- data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +5 -0
- data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -0
- data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -0
- data/setup_samples/sample_rubymine/demo.rb +86 -0
- metadata +44 -19
- data/lib/regression/browser.rb +0 -1259
- data/lib/regression/drag_and_drop.rb +0 -374
- data/lib/regression/find.rb +0 -426
- data/lib/regression/legacy.rb +0 -40
- data/lib/regression/page_data.rb +0 -185
- data/lib/regression/runner.rb +0 -278
- data/lib/regression/tables.rb +0 -486
- data/lib/regression/user_input.rb +0 -1255
- data/lib/regression/utilities.rb +0 -891
- data/lib/regression/validations.rb +0 -1179
- data/lib/regression/waits.rb +0 -387
@@ -0,0 +1,431 @@
|
|
1
|
+
module Awetestlib
|
2
|
+
module Regression
|
3
|
+
module Find
|
4
|
+
|
5
|
+
def get_select_list(browser, how, what, desc = '')
|
6
|
+
list = browser.select_list(how, what)
|
7
|
+
if validate(browser, @myName, __LINE__)
|
8
|
+
passed_to_log("Select list #{how}='#{what}' found and returned.")
|
9
|
+
return list
|
10
|
+
end
|
11
|
+
rescue
|
12
|
+
failed_to_log("Unable to return select list #{how}='#{what}': '#{$!}' (#{__LINE__})")
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_select_options(browser, how, what, dump = false)
|
16
|
+
list = browser.select_list(how, what)
|
17
|
+
dump_select_list_options(list) if dump
|
18
|
+
list.options
|
19
|
+
rescue
|
20
|
+
failed_to_log("Unable to get select options for #{how}=>#{what}. '#{$!}'")
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_select_options_by_id(browser, strg, dump = false)
|
24
|
+
get_select_options(browser, :id, strg, dump)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_select_options_by_name(browser, strg, dump = false)
|
28
|
+
get_select_options(browser, :name, strg, dump)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_selected_options(browser, how, what)
|
32
|
+
begin
|
33
|
+
list = browser.select_list(how, what)
|
34
|
+
rescue => e
|
35
|
+
if not rescue_me(e, __method__, "browser.select_list(#{how}, '#{what}')", "#{browser.class}")
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
list.selected_options
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_selected_options_by_id(browser, strg)
|
43
|
+
get_selected_options(browser, :id, strg)
|
44
|
+
end
|
45
|
+
|
46
|
+
alias get_selected_option_by_id get_selected_options_by_id
|
47
|
+
|
48
|
+
def get_selected_options_by_name(browser, strg)
|
49
|
+
get_selected_options(browser, :name, strg)
|
50
|
+
end
|
51
|
+
|
52
|
+
alias get_selected_option_by_name get_selected_options_by_name
|
53
|
+
|
54
|
+
=begin rdoc
|
55
|
+
:category: A_rdoc_test
|
56
|
+
Returns a reference to a division element. Used to assign a div element to a variable
|
57
|
+
which can then be passed to methods that require a *browser* parameter.
|
58
|
+
|
59
|
+
_Parameters_::
|
60
|
+
|
61
|
+
*browser* - a reference to the browser window or container element to be tested
|
62
|
+
|
63
|
+
*how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
|
64
|
+
Common values: :text, :id, :title, :name, :class, :href (:link only)
|
65
|
+
|
66
|
+
*what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
67
|
+
|
68
|
+
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
69
|
+
|
70
|
+
_Example_
|
71
|
+
|
72
|
+
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
73
|
+
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
74
|
+
popup = attach_browser(mainwindow, :url, '[url of new window]') *or*
|
75
|
+
popup = attach_browser(mainwindow, :title, '[title of new window]')
|
76
|
+
|
77
|
+
=end
|
78
|
+
|
79
|
+
def get_div(browser, how, what, desc = '', dbg = false)
|
80
|
+
msg = "Get division #{how}=>#{what}."
|
81
|
+
msg << " #{desc}" if desc.length > 0
|
82
|
+
Watir::Wait.until { browser.div(how, what).exists? }
|
83
|
+
div = browser.div(how, what)
|
84
|
+
debug_to_log(div.inspect) if dbg
|
85
|
+
if validate(browser, @myName, __LINE__)
|
86
|
+
if div
|
87
|
+
passed_to_log(msg)
|
88
|
+
return div
|
89
|
+
else
|
90
|
+
failed_to_log(msg)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
rescue
|
94
|
+
failed_to_log("Unable to '#{msg}' '#{$!}'")
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_div_by_id(browser, strg, desc = '', dbg = false)
|
98
|
+
get_div(browser, :id, strg, desc, dbg)
|
99
|
+
end
|
100
|
+
|
101
|
+
=begin rdoc
|
102
|
+
:category: A_rdoc_test
|
103
|
+
Returns a reference to a division element identified by the value in its class attribute. Calls get_div()
|
104
|
+
|
105
|
+
_Parameters_::
|
106
|
+
|
107
|
+
*browser* - a reference to the browser window or container element to be tested
|
108
|
+
|
109
|
+
*strg* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
110
|
+
|
111
|
+
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
112
|
+
|
113
|
+
_Example_
|
114
|
+
|
115
|
+
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
116
|
+
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
117
|
+
popup = attach_browser(mainwindow, :url, '[url of new window]') *or*
|
118
|
+
popup = attach_browser(mainwindow, :title, '[title of new window]')
|
119
|
+
|
120
|
+
=end
|
121
|
+
|
122
|
+
def get_div_by_class(browser, strg, desc = '', dbg = false)
|
123
|
+
get_div(browser, :class, strg, desc, dbg)
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_div_by_text(browser, strg, desc = '', dbg = false)
|
127
|
+
get_div(browser, :text, strg, desc, dbg)
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_form(browser, how, strg)
|
131
|
+
begin
|
132
|
+
# Watir::Wait.until( browser.form(how, strg).exists? ) # fails in wait_until
|
133
|
+
rescue => e
|
134
|
+
if not rescue_me(e, __method__, "browser.form(#{how}, '#{strg}').exists?", "#{browser.class}")
|
135
|
+
raise e
|
136
|
+
end
|
137
|
+
end
|
138
|
+
myForm = browser.form(how, strg)
|
139
|
+
if validate(browser, @myName, __LINE__)
|
140
|
+
passed_to_log("Form #{how}='#{strg}' found and returned.")
|
141
|
+
return myForm
|
142
|
+
end
|
143
|
+
rescue
|
144
|
+
failed_to_log("Unable to return form #{how}='#{strg}': '#{$!}' (#{__LINE__})")
|
145
|
+
end
|
146
|
+
|
147
|
+
def get_form_by_id(browser, strg)
|
148
|
+
get_form(browser, :id, strg)
|
149
|
+
end
|
150
|
+
|
151
|
+
def get_frame(browser, how, strg, desc = '')
|
152
|
+
# begin
|
153
|
+
# Watir::Wait.until(browser.frame(how, strg).exists?) # fails in wait_until
|
154
|
+
# rescue => e
|
155
|
+
# if not rescue_me(e, __method__, "browser.frame(#{how}, '#{strg}').exists?", "#{browser.class}")
|
156
|
+
# raise e
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
begin
|
160
|
+
frame = browser.frame(how, strg)
|
161
|
+
rescue => e
|
162
|
+
if not rescue_me(e, __method__, "browser.frame(#{how}, '#{strg}').exists?", "#{browser.class}")
|
163
|
+
raise e
|
164
|
+
end
|
165
|
+
end
|
166
|
+
if validate(browser, @myName, __LINE__)
|
167
|
+
passed_to_log("Frame #{how}='#{strg}' found and returned. #{desc}")
|
168
|
+
return frame
|
169
|
+
end
|
170
|
+
rescue
|
171
|
+
failed_to_log("Unable to return frame #{how}='#{strg}'. #{desc}: '#{$!}' (#{__LINE__})")
|
172
|
+
end
|
173
|
+
|
174
|
+
def get_frame_by_id(browser, strg, desc = '')
|
175
|
+
get_frame(browser, :id, strg, desc)
|
176
|
+
end
|
177
|
+
|
178
|
+
def get_frame_by_index(browser, index, desc = '')
|
179
|
+
get_frame(browser, :index, index, desc)
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_frame_by_name(browser, strg, desc = '')
|
183
|
+
get_frame(browser, :name, strg, desc)
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_span(browser, how, strg, desc = '')
|
187
|
+
begin
|
188
|
+
#TODO: use LegacyExtensions#wait_until
|
189
|
+
Watir::Wait.until { browser.span(how, strg).exists? }
|
190
|
+
rescue => e
|
191
|
+
if not rescue_me(e, __method__, "browser.span(#{how}, '#{strg}').exists?", "#{browser.class}")
|
192
|
+
raise e
|
193
|
+
end
|
194
|
+
end
|
195
|
+
begin
|
196
|
+
span = browser.span(how, strg)
|
197
|
+
rescue => e
|
198
|
+
if not rescue_me(e, __method__, "browser.span(#{how}, '#{strg}').exists?", "#{browser.class}")
|
199
|
+
raise e
|
200
|
+
end
|
201
|
+
end
|
202
|
+
if validate(browser, @myName, __LINE__)
|
203
|
+
passed_to_log("Span #{how}='#{strg}' found and returned. #{desc}")
|
204
|
+
return span
|
205
|
+
end
|
206
|
+
rescue
|
207
|
+
failed_to_log("Unable to return span #{how}='#{strg}'. #{desc}: '#{$!}' (#{__LINE__})")
|
208
|
+
end
|
209
|
+
|
210
|
+
def get_span_by_id(browser, strg, desc = '')
|
211
|
+
get_span(browser, :id, strg, desc)
|
212
|
+
end
|
213
|
+
|
214
|
+
=begin rdoc
|
215
|
+
:category: A_rdoc_test
|
216
|
+
Returns a reference to a table element. Used to assign a table element to a variable
|
217
|
+
which can then be used directly or passed to methods that require a *browser* or *table* parameter.
|
218
|
+
|
219
|
+
_Parameters_::
|
220
|
+
|
221
|
+
*browser* - a reference to the browser window or container element to be tested
|
222
|
+
|
223
|
+
*how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
|
224
|
+
Common values: :text, :id, :title, :name, :class, :href (:link only)
|
225
|
+
|
226
|
+
*what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
227
|
+
|
228
|
+
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
229
|
+
|
230
|
+
_Example_
|
231
|
+
|
232
|
+
a_table = get_table(browser, :id, 'table1')
|
233
|
+
a_table_cell = a_table[2][1] # The cell in the first column of the second row of the table
|
234
|
+
|
235
|
+
=end
|
236
|
+
|
237
|
+
def get_table(browser, how, what, desc = '')
|
238
|
+
msg = "Return table :#{how}='#{what}'. #{desc}"
|
239
|
+
tbl = browser.table(how, what)
|
240
|
+
if validate(browser, @myName, __LINE__)
|
241
|
+
passed_to_log(msg)
|
242
|
+
tbl
|
243
|
+
end
|
244
|
+
rescue
|
245
|
+
failed_to_log("#{msg}': '#{$!}'")
|
246
|
+
end
|
247
|
+
|
248
|
+
def get_table_by_id(browser, strg, desc = '')
|
249
|
+
get_table(browser, :id, strg, desc)
|
250
|
+
end
|
251
|
+
|
252
|
+
def get_table_by_index(browser, idx)
|
253
|
+
get_table(browser, :index, idx, desc)
|
254
|
+
end
|
255
|
+
|
256
|
+
def get_table_by_text(browser, strg)
|
257
|
+
get_table(browser, :text, strg, desc)
|
258
|
+
end
|
259
|
+
|
260
|
+
def get_table_headers(table, header_index = 1)
|
261
|
+
headers = Hash.new
|
262
|
+
headers['index'] = Hash.new
|
263
|
+
headers['name'] = Hash.new
|
264
|
+
count = 1
|
265
|
+
table[header_index].each do |cell|
|
266
|
+
if cell.text.length > 0
|
267
|
+
name = cell.text.gsub(/\s+/, ' ')
|
268
|
+
headers['index'][count] = name
|
269
|
+
headers['name'][name] = count
|
270
|
+
end
|
271
|
+
count += 1
|
272
|
+
end
|
273
|
+
#debug_to_log("#{__method__}:****** headers:\n#{headers.to_yaml}")
|
274
|
+
headers
|
275
|
+
rescue
|
276
|
+
failed_to_log("Unable to get content headers. '#{$!}'")
|
277
|
+
end
|
278
|
+
|
279
|
+
def get_element(browser, element, how, what, value = nil)
|
280
|
+
target = nil
|
281
|
+
what = Regexp.new(Regexp.escape(what)) unless how == :index or what.is_a?(Regexp)
|
282
|
+
case element
|
283
|
+
when :link
|
284
|
+
target = browser.link(how, what)
|
285
|
+
when :button
|
286
|
+
target = browser.button(how, what)
|
287
|
+
when :div
|
288
|
+
target = browser.div(how, what)
|
289
|
+
when :checkbox
|
290
|
+
target = browser.checkbox(how, what, value)
|
291
|
+
when :text_field, :textfield
|
292
|
+
target = browser.text_field(how, what)
|
293
|
+
when :image
|
294
|
+
target = browser.image(how, what)
|
295
|
+
when :file_field, :filefield
|
296
|
+
target = browser.file_field(how, what)
|
297
|
+
when :form
|
298
|
+
target = browser.form(how, what)
|
299
|
+
when :frame
|
300
|
+
target = browser.frame(how, what)
|
301
|
+
when :radio
|
302
|
+
target = browser.radio(how, what, value)
|
303
|
+
when :span
|
304
|
+
target = browser.span(how, what)
|
305
|
+
when :table
|
306
|
+
target = browser.table(how, what)
|
307
|
+
when :li
|
308
|
+
target = browser.li(how, what)
|
309
|
+
when :select_list, :selectlist
|
310
|
+
target = browser.select_list(how, what)
|
311
|
+
when :hidden
|
312
|
+
target = browser.hidden(how, what)
|
313
|
+
when :area
|
314
|
+
target = browser.area(how, what)
|
315
|
+
end
|
316
|
+
if target.exists?
|
317
|
+
target
|
318
|
+
else
|
319
|
+
nil
|
320
|
+
end
|
321
|
+
rescue => e
|
322
|
+
if not rescue_me(e, __method__, "browser.#{element}(#{how}, '#{what}')", "#{browser.class}", target)
|
323
|
+
raise e
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def get_objects(browser, which, dbg=false)
|
328
|
+
cnt = 0
|
329
|
+
case which
|
330
|
+
when :links
|
331
|
+
list = browser.links
|
332
|
+
sleep(1)
|
333
|
+
when :tables
|
334
|
+
list = browser.tables
|
335
|
+
when :divs
|
336
|
+
list = browser.divs
|
337
|
+
when :buttons
|
338
|
+
list = browser.buttons
|
339
|
+
when :checkboxes
|
340
|
+
list = browser.checkboxes
|
341
|
+
when :radios
|
342
|
+
list = browser.radios
|
343
|
+
when :selectlists
|
344
|
+
list = browser.selectlists
|
345
|
+
when :textfields
|
346
|
+
list = browser.textfields
|
347
|
+
when :lis
|
348
|
+
list = browser.lis
|
349
|
+
else
|
350
|
+
debug_to_log("Unrecognized dom object '#{which}'")
|
351
|
+
end
|
352
|
+
if dbg
|
353
|
+
list.each do |obj|
|
354
|
+
cnt += 1
|
355
|
+
debug_to_log("\n==========#{which}:\nindex: #{cnt}\n#{obj}\n#{obj.to_yaml}")
|
356
|
+
end
|
357
|
+
end
|
358
|
+
list
|
359
|
+
end
|
360
|
+
|
361
|
+
def get_ole(element)
|
362
|
+
ole = element.ole_object
|
363
|
+
if ole
|
364
|
+
passed_to_log("Found ole_object for #{element}.")
|
365
|
+
ole
|
366
|
+
else
|
367
|
+
failed_to_log("Did not find ole_object for #{element}.")
|
368
|
+
end
|
369
|
+
rescue
|
370
|
+
failed_to_log("Unable to find ole_object for #{element}. #{$!}")
|
371
|
+
end
|
372
|
+
|
373
|
+
def find_all_links_with_exact_href(browser, href)
|
374
|
+
links = browser.links
|
375
|
+
hash = Hash.new
|
376
|
+
idx = 0
|
377
|
+
links.each do |l|
|
378
|
+
idx += 1
|
379
|
+
an_href = href
|
380
|
+
my_href = l.href
|
381
|
+
if my_href == an_href
|
382
|
+
hash[idx] = l
|
383
|
+
debug_to_log("#{__method__}:#{idx}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
384
|
+
end
|
385
|
+
end
|
386
|
+
hash
|
387
|
+
end
|
388
|
+
|
389
|
+
def find_link_with_exact_href(browser, href)
|
390
|
+
links = browser.links
|
391
|
+
link = nil
|
392
|
+
index = 0
|
393
|
+
links.each do |l|
|
394
|
+
index += 1
|
395
|
+
an_href = href
|
396
|
+
my_href = l.href
|
397
|
+
if my_href == an_href
|
398
|
+
link = l
|
399
|
+
# debug_to_log("#{__method__}:#{__LINE__}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
400
|
+
break
|
401
|
+
end
|
402
|
+
end
|
403
|
+
link
|
404
|
+
end
|
405
|
+
|
406
|
+
def find_index_for_object(browser, obj, how, ord, strg)
|
407
|
+
obj_sym = (obj.to_s.pluralize).to_sym
|
408
|
+
how_str = how.to_s
|
409
|
+
ptrn = /#{how}:\s+#{strg}/i
|
410
|
+
list = get_objects(browser, obj_sym, true)
|
411
|
+
cnt = 0
|
412
|
+
idx = 0
|
413
|
+
list.each do |nty|
|
414
|
+
s = nty.to_s
|
415
|
+
# a = nty.to_a
|
416
|
+
if s =~ ptrn
|
417
|
+
cnt += 1
|
418
|
+
if cnt == ord
|
419
|
+
break
|
420
|
+
end
|
421
|
+
end
|
422
|
+
idx += 1
|
423
|
+
end
|
424
|
+
idx
|
425
|
+
end
|
426
|
+
|
427
|
+
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Awetestlib
|
2
|
+
module Regression
|
3
|
+
module Legacy
|
4
|
+
|
5
|
+
#--
|
6
|
+
##def open_log
|
7
|
+
# start = Time.now.to_f.to_s
|
8
|
+
#
|
9
|
+
# logTS = Time.at(@myRun.launched.to_f).strftime("%Y%m%d%H%M%S")
|
10
|
+
# xls = @myAppEnv.xls_name.gsub('.xls', '') + '_' if @myAppEnv.xls_name.length > 0
|
11
|
+
# @logFileSpec = "#{@myRoot}/#{logdir}/#{@myName}_#{@targetBrowser.abbrev}_#{xls}#{logTS}.log"
|
12
|
+
# init_logger(@logFileSpec, @myName)
|
13
|
+
#
|
14
|
+
# # message_tolog( self.inspect )
|
15
|
+
# message_to_log("#{@myName} launched at [#{@myRun.launched.to_f.to_s}][#{@myScript.id}][#{@myRun.id}][#{@myChild.id}]")
|
16
|
+
# debug_to_log("pid: #{$$}")
|
17
|
+
# message_to_log("#{@myName} begin at [#{start}]")
|
18
|
+
# message_to_log("#{@myName} environment [#{@myAppEnv.name}]")
|
19
|
+
# message_to_log("#{@myName} xls_name [#{@myAppEnv.xls_name}]") if @myAppEnv.xls_name.length > 0
|
20
|
+
# message_to_log("#{@myName} rootDir [#{@myRoot}]")
|
21
|
+
# message_to_log("#{@myName} Target Browser [#{@targetBrowser.name}]")
|
22
|
+
# mark_testlevel(@myParent.name, @myParent.level) # Module
|
23
|
+
# mark_testlevel(@myChild.name, @myChild.level) # SubModule
|
24
|
+
#
|
25
|
+
#end
|
26
|
+
#++
|
27
|
+
|
28
|
+
#def find_me(where, how, what)
|
29
|
+
# me = where.element(how, what)
|
30
|
+
# puts me.inspect
|
31
|
+
#rescue
|
32
|
+
# error_to_log("#{where.inspect} doesn't seem to respond to element() #{$!}")
|
33
|
+
#end
|
34
|
+
|
35
|
+
# def click_me(element)
|
36
|
+
# element.click
|
37
|
+
# rescue
|
38
|
+
# error_to_log("#{element.inspect} doesn't seem to respond to click() #{$!}")
|
39
|
+
# end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module Awetestlib
|
2
|
+
module Regression
|
3
|
+
module PageData
|
4
|
+
|
5
|
+
=begin rdoc
|
6
|
+
:category: Page Data
|
7
|
+
:tags: data, DOM, page
|
8
|
+
|
9
|
+
_Parameters_::
|
10
|
+
|
11
|
+
*browser* is any container element, usually the browser window or a div within it. Best to use is the smallest that contains the desired data.
|
12
|
+
|
13
|
+
*types* is an array that defaults to all of: :text, :textarea, :select_list, :span, :hidden, :checkbox, and :radio.
|
14
|
+
Set types to an array of a subset of these if fewer elements are desired.
|
15
|
+
|
16
|
+
No positive validations are reported but failure is rescued and reported.
|
17
|
+
=end
|
18
|
+
def capture_page_data(browser, types = [:text, :textarea, :select_list, :span, :hidden, :checkbox, :radio])
|
19
|
+
start = Time.now
|
20
|
+
debug_to_log("Begin #{__method__}")
|
21
|
+
data = Hash.new
|
22
|
+
data[:id] = Hash.new
|
23
|
+
data[:name] = Hash.new
|
24
|
+
data[:index] = Hash.new
|
25
|
+
types.each do |type|
|
26
|
+
#debug_to_log("#{__method__}: #{type}. . .")
|
27
|
+
data[:id][type], data[:name][type], data[:index][type] = parse_elements(browser, type)
|
28
|
+
end
|
29
|
+
data
|
30
|
+
rescue
|
31
|
+
failed_to_log("#{__method__}: '#{$!}'")
|
32
|
+
ensure
|
33
|
+
stop = Time.now
|
34
|
+
passed_to_log("#{__method__.to_s.titleize} finished. (#{"%.5f" % (stop - start)} secs)")
|
35
|
+
#debug_to_log("End #{__method__}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def compare_page_data(before, after, how, desc = '')
|
39
|
+
[:text, :textarea, :select_list, :span, :checkbox, :radio].each do |type|
|
40
|
+
before[how][type].each_key do |what|
|
41
|
+
msg = "#{desc} #{type} #{how}=#{what}: Expected '#{before[how][type][what]}'."
|
42
|
+
if after[how][type][what] == before[how][type][what]
|
43
|
+
passed_to_log(msg)
|
44
|
+
else
|
45
|
+
failed_to_log("#{msg} Found '#{after[how][type][what]}'")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue
|
50
|
+
failed_to_log("Unable to compare before and after page data. '#{$!}'")
|
51
|
+
end
|
52
|
+
|
53
|
+
=begin rdoc
|
54
|
+
:category: Page Data
|
55
|
+
:tags:data, DOM
|
56
|
+
|
57
|
+
*data* is the hash returned by capture_page_data().
|
58
|
+
|
59
|
+
*how* is one of :id, :name, :index
|
60
|
+
|
61
|
+
*what* is the target value for how. It can be a string or a regular expression
|
62
|
+
|
63
|
+
*type* is one of :text,:textarea,:select_list,:span,:hidden,:checkbox,:radio
|
64
|
+
|
65
|
+
*get_text* determines whether selected option's text or value is returned. Default is true, i.e., return the selected text.
|
66
|
+
This only applies when the *type* is :select_list.
|
67
|
+
|
68
|
+
=end
|
69
|
+
def fetch_page_data(data, how, what, type, get_text = true)
|
70
|
+
rslt = data[how][type][what]
|
71
|
+
if type == :select_list
|
72
|
+
value, text = rslt.split('::')
|
73
|
+
if get_text
|
74
|
+
rslt = text
|
75
|
+
else
|
76
|
+
rslt = value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
rslt
|
80
|
+
end
|
81
|
+
|
82
|
+
=begin rdoc
|
83
|
+
:category: Page Data
|
84
|
+
:tags:data, DOM
|
85
|
+
|
86
|
+
*browser* is any container element. best to use is the smallest that contains the desired data.
|
87
|
+
|
88
|
+
*type* is one of these symbols: :text,:textarea,:select_list,:span,:hidden,:checkbox,:radio
|
89
|
+
|
90
|
+
Returns three hashes: id[type][id] = value, name[type][id] = value, index[type][id] = value
|
91
|
+
|
92
|
+
A given element appears once in the set of hashes depending on how is is found: id first
|
93
|
+
then name, then index.
|
94
|
+
|
95
|
+
Select list value is in the form 'value::text'. parse with x.split('::')
|
96
|
+
|
97
|
+
No positive validations are reported but failure is rescued and reported.
|
98
|
+
=end
|
99
|
+
def parse_elements(browser, type)
|
100
|
+
id = Hash.new
|
101
|
+
name = Hash.new
|
102
|
+
index = Hash.new
|
103
|
+
idx = 0
|
104
|
+
#debug_to_log("#{__method__}: #{type}")
|
105
|
+
case type
|
106
|
+
when :span
|
107
|
+
collection = browser.spans
|
108
|
+
when :select_list
|
109
|
+
collection = browser.select_lists
|
110
|
+
when :radio
|
111
|
+
collection = browser.radios
|
112
|
+
when :checkbox
|
113
|
+
collection = browser.checkboxes
|
114
|
+
else
|
115
|
+
collection = browser.elements(:type, type.to_s)
|
116
|
+
end
|
117
|
+
#debug_to_log("#{__method__}: collection: #{collection.inspect}")
|
118
|
+
collection.each do |e|
|
119
|
+
case type
|
120
|
+
when :span
|
121
|
+
vlu = e.text
|
122
|
+
when :select_list
|
123
|
+
vlu = "#{e.value}::#{e.selected_options[0]}"
|
124
|
+
when :radio
|
125
|
+
vlu = e.set?
|
126
|
+
when :checkbox
|
127
|
+
vlu = e.set?
|
128
|
+
else
|
129
|
+
vlu = e.value
|
130
|
+
end
|
131
|
+
idx += 1
|
132
|
+
if e.id.length > 0 and not e.id =~ /^__[A-Z]/
|
133
|
+
id[e.id] = vlu
|
134
|
+
elsif e.name.length > 0 and not e.name =~ /^__[A-Z]/
|
135
|
+
name[e.name] = vlu
|
136
|
+
else
|
137
|
+
index[idx] = vlu if not type == :hidden
|
138
|
+
end
|
139
|
+
end
|
140
|
+
[id, name, index]
|
141
|
+
|
142
|
+
rescue
|
143
|
+
failed_to_log("#{__method__}: '#{$!}'")
|
144
|
+
end
|
145
|
+
|
146
|
+
def get_textfield_value(browser, how, what, desc = '')
|
147
|
+
msg = "Return value in textfield #{how}='#{what}'"
|
148
|
+
msg << " #{desc}" if desc.length > 0
|
149
|
+
tf = browser.text_field(how, what)
|
150
|
+
if validate(browser, @myName, __LINE__)
|
151
|
+
if tf
|
152
|
+
debug_to_log("#{tf.inspect}")
|
153
|
+
vlu = tf.value
|
154
|
+
passed_to_log("#{msg} Value='#{vlu}'")
|
155
|
+
vlu
|
156
|
+
else
|
157
|
+
failed_to_log("#{msg}")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
rescue
|
161
|
+
failed_to_log("Unable to #{msg}: '#{$!}'")
|
162
|
+
end
|
163
|
+
|
164
|
+
def get_textfield_value_by_name(browser, strg, desc = '')
|
165
|
+
get_textfield_value(browser, :name, strg, desc)
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_textfield_value_by_id(browser, strg)
|
169
|
+
get_textfield_value(browser, :id, strg)
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_element_text(browser, element, how, what, desc = '')
|
173
|
+
msg = "Return text in #{element} #{how}='#{what}'"
|
174
|
+
msg << " #{desc}" if desc.length > 0
|
175
|
+
text = browser.element(how, what).text
|
176
|
+
if validate(browser, @myName, __LINE__)
|
177
|
+
passed_to_log("#{msg} text='#{text}'")
|
178
|
+
text
|
179
|
+
end
|
180
|
+
rescue
|
181
|
+
failed_to_log("Unable to #{msg}: '#{$!}'")
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|