awetestlib 0.0.3-x86-mingw32 → 0.1.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +22 -0
- data/.gitignore +2 -3
- data/AwetestLib Instructions.rtf +0 -0
- data/ext/Rakefile +1 -0
- data/lib/regression/browser.rb +1259 -0
- data/lib/regression/drag_and_drop.rb +374 -0
- data/lib/regression/find.rb +426 -0
- data/lib/regression/legacy.rb +10 -4693
- data/lib/regression/page_data.rb +185 -0
- data/lib/regression/runner.rb +16 -2
- data/lib/regression/tables.rb +486 -0
- data/lib/regression/user_input.rb +1255 -0
- data/lib/regression/utilities.rb +891 -0
- data/lib/regression/validations.rb +179 -508
- data/lib/regression/waits.rb +387 -0
- data/lib/version.rb +2 -2
- data/rdoc_test.bat +1 -0
- data/test/create_zoho.rb +65 -0
- data/{create_zoho_account1.rb → test/create_zoho_account1.rb} +0 -0
- data/{create_zoho_account2.rb → test/create_zoho_account2.rb} +2 -1
- data/{demo.rb → test/demo.rb} +0 -0
- data/{google_search1.rb → test/google_search1.rb} +0 -0
- data/{google_search2.rb → test/google_search2.rb} +0 -0
- data/{zoho_util.rb → test/zoho_util.rb} +0 -0
- data/{zoho_variables.xls → test/zoho_variables.xls} +0 -0
- metadata +27 -12
@@ -0,0 +1,374 @@
|
|
1
|
+
module DragAndDrop
|
2
|
+
|
3
|
+
def verify_element_inside(inner_element, outer_element, desc = '')
|
4
|
+
mark_testlevel("#{__method__.to_s.titleize}", 3)
|
5
|
+
msg = "#{inner_element.class.to_s} (:id=#{inner_element.id}) is fully enclosed by #{outer_element.class.to_s} (:id=#{outer_element.id})."
|
6
|
+
msg << " #{desc}" if desc.length > 0
|
7
|
+
if overlay?(inner_element, outer_element, :inside)
|
8
|
+
failed_to_log(msg)
|
9
|
+
else
|
10
|
+
passed_to_log(msg)
|
11
|
+
true
|
12
|
+
end
|
13
|
+
rescue
|
14
|
+
failed_to_log("Unable to verify that #{msg} '#{$!}'")
|
15
|
+
end
|
16
|
+
|
17
|
+
def verify_no_element_overlap(browser, above_element, above_how, above_what, below_element, below_how, below_what, side, desc = '')
|
18
|
+
mark_testlevel("#{__method__.to_s.titleize}", 3)
|
19
|
+
msg = "#{above_element.to_s.titleize} #{above_how}=>#{above_what} does not overlap "+
|
20
|
+
"#{below_element.to_s.titleize} #{below_how}=>#{below_what} at the #{side}."
|
21
|
+
msg << " #{desc}" if desc.length > 0
|
22
|
+
above = browser.element(above_how, above_what)
|
23
|
+
below = browser.element(below_how, below_what)
|
24
|
+
if overlay?(above, below, side)
|
25
|
+
failed_to_log(msg)
|
26
|
+
else
|
27
|
+
passed_to_log(msg)
|
28
|
+
true
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
failed_to_log("Unable to verify that #{msg} '#{$!}'")
|
32
|
+
end
|
33
|
+
|
34
|
+
def overlay?(inner, outer, side = :bottom)
|
35
|
+
#mark_testlevel("#{__method__.to_s.titleize}", 3)
|
36
|
+
inner_t, inner_b, inner_l, inner_r = inner.bounding_rectangle_offsets
|
37
|
+
outer_t, outer_b, outer_l, outer_r = outer.bounding_rectangle_offsets
|
38
|
+
#overlay = false
|
39
|
+
case side
|
40
|
+
when :bottom
|
41
|
+
overlay = inner_b > outer_t
|
42
|
+
when :top
|
43
|
+
overlay = inner_t > outer_t
|
44
|
+
when :left
|
45
|
+
overlay = inner_l < outer_r
|
46
|
+
when :right
|
47
|
+
overlay = inner_r > outer_r
|
48
|
+
when :inside
|
49
|
+
overlay = !(inner_t > outer_t and
|
50
|
+
inner_r < outer_r and
|
51
|
+
inner_l > outer_l and
|
52
|
+
inner_b < outer_b)
|
53
|
+
else
|
54
|
+
overlay = (inner_t > outer_b or
|
55
|
+
inner_r > outer_l or
|
56
|
+
inner_l < outer_r or
|
57
|
+
inner_b < outer_t)
|
58
|
+
end
|
59
|
+
overlay
|
60
|
+
rescue
|
61
|
+
failed_to_log("Unable to determine overlay. '#{$!}'")
|
62
|
+
end
|
63
|
+
|
64
|
+
def hover(browser, element, wait = 2)
|
65
|
+
w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
|
66
|
+
@ai.MoveMouse(xc1, yc1)
|
67
|
+
sleep_for(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
def move_element_with_handle(browser, element, handle_id, dx, dy)
|
71
|
+
# msg = "Move element "
|
72
|
+
# w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
|
73
|
+
# newx = w1 + dx
|
74
|
+
# newy = h1 + dy
|
75
|
+
# msg << " by [#{dx}, #{dy}] to expected [[#{newx}, #{newy}] "
|
76
|
+
# handle = get_resize_handle(element, handle_id)
|
77
|
+
# hw, hh, hx, hy, hxc, hyc, hxlr, hylr = get_element_coordinates(browser, handle, true)
|
78
|
+
|
79
|
+
# drag_and_drop(hxc, hyc, dx, dy)
|
80
|
+
|
81
|
+
# w2, h2, x2, y2, xc2, yc2, xlr2, ylr2 = get_element_coordinates(browser, element, true)
|
82
|
+
|
83
|
+
# xerr = x2 - newx
|
84
|
+
# yerr = y2 - newy
|
85
|
+
# xdsp = (x1 - x2).abs
|
86
|
+
# ydsp = (y1 - y2).abs
|
87
|
+
|
88
|
+
# if x2 == newx and y2 == newy
|
89
|
+
# msg << "succeeded."
|
90
|
+
# passed_to_log(msg)
|
91
|
+
# else
|
92
|
+
# msg << "failed. "
|
93
|
+
# failed_to_log(msg)
|
94
|
+
# debug_to_log("x: actual #{x2}, error #{xerr}, displace #{xdsp}. y: actual #{y2}, error #{yerr}, displace #{ydsp}.")
|
95
|
+
# end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
def resize_element_with_handle(browser, element, target, dx, dy=nil)
|
100
|
+
#TODO enhance to accept differing percentages in each direction
|
101
|
+
msg = "Resize element "
|
102
|
+
w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
|
103
|
+
if dy
|
104
|
+
deltax = dx
|
105
|
+
deltay = dy
|
106
|
+
neww = w1 + dx
|
107
|
+
newh = h1 + dy
|
108
|
+
msg << " by [#{dx}, #{dy}] " #"" to expected dimension [#{neww}, #{newh}] "
|
109
|
+
else
|
110
|
+
deltax, deltay, neww, newh = adjust_dimensions_by_percent(w1, h1, dx, true)
|
111
|
+
msg << "by #{dx} percent " #"" to expected dimension [#{neww}, #{newh}] "
|
112
|
+
end
|
113
|
+
handle = get_resize_handle_by_class(element, target) #, true)
|
114
|
+
sleep_for(0.5)
|
115
|
+
hw, hh, hx, hy, hxc, hyc, hxlr, hylr = get_element_coordinates(browser, handle, true)
|
116
|
+
hxlr_diff = 0
|
117
|
+
hylr_diff = 0
|
118
|
+
|
119
|
+
# TODO These adjustments are adhoc and empirical. Need to be derived more rigorously
|
120
|
+
if @browserAbbrev == 'IE'
|
121
|
+
hxlr_diff = (xlr1 - hxlr)
|
122
|
+
hylr_diff = (ylr1 - hylr)
|
123
|
+
x_start = hxlr - 2
|
124
|
+
y_start = hylr - 2
|
125
|
+
else
|
126
|
+
hxlr_diff = (xlr1 - hxlr) / 2 unless (xlr1 - hxlr) == 0
|
127
|
+
hylr_diff = (ylr1 - hylr) / 2 unless (ylr1 - hylr) == 0
|
128
|
+
x_start = hxlr
|
129
|
+
y_start = hylr
|
130
|
+
end
|
131
|
+
|
132
|
+
newxlr = xlr1 + deltax
|
133
|
+
newylr = ylr1 + deltay
|
134
|
+
# msg << ", lower right [#{newxlr}, #{newylr}] - "
|
135
|
+
sleep_for(0.5)
|
136
|
+
|
137
|
+
drag_and_drop(x_start, y_start, deltax, deltay)
|
138
|
+
|
139
|
+
sleep_for(1.5)
|
140
|
+
w2, h2, x2, y2, xc2, yc2, xlr2, ylr2 = get_element_coordinates(browser, element, true)
|
141
|
+
|
142
|
+
werr = w2 - neww
|
143
|
+
herr = h2 - newh
|
144
|
+
|
145
|
+
# TODO This adjustment is adhoc and empirical. Needs to be derived more rigorously
|
146
|
+
xlrerr = xlr2 - newxlr + hxlr_diff
|
147
|
+
ylrerr = ylr2 - newylr + hylr_diff
|
148
|
+
|
149
|
+
xlrdsp = (xlr1 - xlr2).abs
|
150
|
+
ylrdsp = (ylr1 - ylr2).abs
|
151
|
+
|
152
|
+
debug_to_log("\n" +
|
153
|
+
"\t\t hxlr_diff: #{hxlr_diff}\n" +
|
154
|
+
"\t\t hylr_diff: #{hylr_diff}\n" +
|
155
|
+
"\t\t werr: #{werr}\n" +
|
156
|
+
"\t\t herr: #{herr}\n" +
|
157
|
+
"\t\t xlrerr: #{xlrerr}\n" +
|
158
|
+
"\t\t ylrerr: #{ylrerr}\n" +
|
159
|
+
"\t\t xlrdsp: #{xlrdsp}\n" +
|
160
|
+
"\t\t ylrdsp: #{ylrdsp}\n" +
|
161
|
+
"\t\t @min_width: #{@min_width}\n" +
|
162
|
+
"\t\t@min_height: #{@min_height}\n" +
|
163
|
+
"\t\t x tol: #{@x_tolerance}\n" +
|
164
|
+
"\t\t y tol: #{@y_tolerance}\n"
|
165
|
+
)
|
166
|
+
|
167
|
+
#TODO Add check that window _was_ resized.
|
168
|
+
x_ok, x_msg = validate_move(w2, xlrerr, @x_tolerance, @min_width, xlr2)
|
169
|
+
y_ok, y_msg = validate_move(h2, ylrerr, @y_tolerance, @min_height, ylr2)
|
170
|
+
msg = msg + "x: #{x_msg}, y: #{y_msg}"
|
171
|
+
|
172
|
+
if x_ok and y_ok
|
173
|
+
passed_to_log(msg)
|
174
|
+
else
|
175
|
+
failed_to_log(msg)
|
176
|
+
debug_to_log("x - actual #{xlr2}, error #{xlrerr}, displace #{xlrdsp}, y - actual #{ylr2}, error #{ylrerr}, displace #{ylrdsp}.")
|
177
|
+
end
|
178
|
+
sleep_for(1)
|
179
|
+
rescue
|
180
|
+
failed_to_log("Unable to validate resize. #{$!} (#{__LINE__})")
|
181
|
+
sleep_for(1)
|
182
|
+
end
|
183
|
+
|
184
|
+
# :category: GUI
|
185
|
+
def get_resize_handle_by_id(element, id, dbg=nil)
|
186
|
+
handle = get_div_by_id(element, id, dbg)
|
187
|
+
sleep_for(1)
|
188
|
+
handle.flash(5)
|
189
|
+
return handle
|
190
|
+
end
|
191
|
+
|
192
|
+
# :category: GUI
|
193
|
+
def get_resize_handle_by_class(element, strg, dbg=nil)
|
194
|
+
handle = get_div_by_class(element, strg, dbg)
|
195
|
+
sleep_for(0.5)
|
196
|
+
handle.flash(5)
|
197
|
+
return handle
|
198
|
+
end
|
199
|
+
|
200
|
+
# :category: GUI
|
201
|
+
def get_element_coordinates(browser, element, dbg=nil)
|
202
|
+
bx, by, bw, bh = get_browser_coord(browser, dbg)
|
203
|
+
if @browserAbbrev == 'IE'
|
204
|
+
x_hack = @horizontal_hack_ie
|
205
|
+
y_hack = @vertical_hack_ie
|
206
|
+
elsif @browserAbbrev == 'FF'
|
207
|
+
x_hack = @horizontal_hack_ff
|
208
|
+
y_hack = @vertical_hack_ff
|
209
|
+
end
|
210
|
+
sleep_for(1)
|
211
|
+
w, h = element.dimensions.to_a
|
212
|
+
xc, yc = element.client_offset.to_a
|
213
|
+
# xcc, ycc = element.client_center.to_a
|
214
|
+
xcc = xc + w/2
|
215
|
+
ycc = yc + h/2
|
216
|
+
# screen offset:
|
217
|
+
xs = bx + x_hack + xc - 1
|
218
|
+
ys = by + y_hack + yc - 1
|
219
|
+
# screen center:
|
220
|
+
xsc = xs + w/2
|
221
|
+
ysc = ys + h/2
|
222
|
+
xslr = xs + w
|
223
|
+
yslr = ys + h
|
224
|
+
if dbg
|
225
|
+
debug_to_log(
|
226
|
+
"\n\t\tElement: #{element.inspect}"+
|
227
|
+
"\n\t\tbrowser screen offset: x: #{bx} y: #{by}"+
|
228
|
+
"\n\t\t dimensions: x: #{w} y: #{h}"+
|
229
|
+
"\n\t\t client offset x: #{xc} y: #{yc}"+
|
230
|
+
"\n\t\t screen offset x: #{xs} y: #{ys}"+
|
231
|
+
"\n\t\t client center x: #{xcc} y: #{ycc}"+
|
232
|
+
"\n\t\t screen center x: #{xsc} y: #{ysc}"+
|
233
|
+
"\n\t\t screen lower right x: #{xslr} y: #{yslr}")
|
234
|
+
end
|
235
|
+
[w, h, xs, ys, xsc, ysc, xslr, yslr]
|
236
|
+
end
|
237
|
+
|
238
|
+
def adjust_dimensions_by_percent(w, h, p, returnnew=nil)
|
239
|
+
p += 100
|
240
|
+
nw = (w * (p/100.0)).to_i
|
241
|
+
nh = (h * (p/100.0)).to_i
|
242
|
+
deltaw = nw - w
|
243
|
+
deltah = nh - h
|
244
|
+
if returnnew
|
245
|
+
[deltaw, deltah, nw, nh]
|
246
|
+
else
|
247
|
+
[deltaw, deltah]
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def get_browser_coord(browser=nil, dbg=nil)
|
252
|
+
browser = @myBrowser if not browser
|
253
|
+
title = browser.title
|
254
|
+
x = @ai.WinGetPosX(title)
|
255
|
+
y = @ai.WinGetPosY(title)
|
256
|
+
w = @ai.WinGetPosWidth(title)
|
257
|
+
h = @ai.WinGetPosHeight(title)
|
258
|
+
if dbg
|
259
|
+
debug_to_log("\n\t\tBrowser #{browser.inspect}\n"+
|
260
|
+
"\t\tdimensions: x: #{w} y: #{h}"+
|
261
|
+
"\t\tscreen offset x: #{x} y: #{y}")
|
262
|
+
end
|
263
|
+
[x, y, w, h]
|
264
|
+
end
|
265
|
+
|
266
|
+
def drag_and_drop(x1, y1, dx, dy, speed=nil)
|
267
|
+
speed = 10 if not speed
|
268
|
+
x2 = x1 + dx
|
269
|
+
y2 = y1 + dy
|
270
|
+
debug_to_log("drag_and_drop: start: [#{x1}, #{y1}] end: [#{x2}, #{y2}]")
|
271
|
+
|
272
|
+
@ai.MouseMove(x1, y1, speed)
|
273
|
+
@ai.MouseClick("primary", x1, y1)
|
274
|
+
sleep_for(0.5)
|
275
|
+
@ai.MouseClick("primary", x1, y1)
|
276
|
+
sleep_for(0.5)
|
277
|
+
@ai.MouseClickDrag("primary", x1, y1, x2, y2, speed)
|
278
|
+
end
|
279
|
+
|
280
|
+
def drag_and_drop_element(browser, element, dx, dy, speed = nil)
|
281
|
+
speed = 10 if not speed
|
282
|
+
w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
|
283
|
+
msg = "Move #{element} by [#{dx}, #{dy}] from center[#{xc1}, #{yc1}] "
|
284
|
+
newxc = xc1 + dx
|
285
|
+
newyc = yc1 + dy
|
286
|
+
msg << "to center[[#{newxc}, #{newyc}]"
|
287
|
+
sleep_for(0.5)
|
288
|
+
|
289
|
+
drag_and_drop(xc1, yc1, dx, dy)
|
290
|
+
|
291
|
+
sleep_for(1)
|
292
|
+
w2, h2, x2, y2, xc2, yc2, xlr2, ylr2 = get_element_coordinates(browser, element, true)
|
293
|
+
|
294
|
+
# TODO This adjustment is adhoc and empirical. Needs to be derived more rigorously
|
295
|
+
xcerr = xc2 - xc1
|
296
|
+
ycerr = yc2 - yc1
|
297
|
+
|
298
|
+
debug_to_log("\n" +
|
299
|
+
"\t\t xc1: #{xc1}\n" +
|
300
|
+
"\t\t yc1: #{yc1}\n" +
|
301
|
+
"\t\t xc2: #{xc2}\n" +
|
302
|
+
"\t\t yc2: #{yc2}\n" +
|
303
|
+
"\t\t xcerr: #{xlrerr}\n" +
|
304
|
+
"\t\t ycerr: #{ylrerr}\n" +
|
305
|
+
"\t\t x tol: #{@x_tolerance}\n" +
|
306
|
+
"\t\t y tol: #{@y_tolerance}\n"
|
307
|
+
)
|
308
|
+
|
309
|
+
#TODO Add check that window _was_ resized.
|
310
|
+
x_ok, x_msg = validate_drag_drop(xcerr, @x_tolerance, newxc, xc2)
|
311
|
+
y_ok, y_msg = validate_drag_drop(ycerr, @y_tolerance, newyc, yc2)
|
312
|
+
msg = msg + "x: #{x_msg}, y: #{y_msg}"
|
313
|
+
|
314
|
+
if x_ok and y_ok
|
315
|
+
passed_to_log(msg)
|
316
|
+
else
|
317
|
+
failed_to_log(msg)
|
318
|
+
end
|
319
|
+
sleep_for(1)
|
320
|
+
rescue
|
321
|
+
failed_to_log("Unable to validate drag and drop. #{$!} (#{__LINE__})")
|
322
|
+
sleep_for(1)
|
323
|
+
end
|
324
|
+
|
325
|
+
def right_click(element)
|
326
|
+
x = element.left_edge_absolute + 2
|
327
|
+
y = element.top_edge_absolute + 2
|
328
|
+
@ai.MouseClick("secondary", x, y)
|
329
|
+
end
|
330
|
+
|
331
|
+
def left_click(element)
|
332
|
+
x = element.left_edge_absolute + 2
|
333
|
+
y = element.top_edge_absolute + 2
|
334
|
+
@ai.MouseClick("primary", x, y)
|
335
|
+
end
|
336
|
+
|
337
|
+
def screen_offset(element, browser=nil)
|
338
|
+
bx, by, bw, bh = get_browser_coord(browser)
|
339
|
+
ex = element.left_edge
|
340
|
+
ey = element.top_edge
|
341
|
+
[bx + ex, by + ey]
|
342
|
+
end
|
343
|
+
|
344
|
+
def screen_center(element, browser=nil)
|
345
|
+
bx, by, bw, bh = get_browser_coord(browser)
|
346
|
+
w, h = element.dimensions.to_a
|
347
|
+
cx = bx + w/2
|
348
|
+
cy = by + h/2
|
349
|
+
[cx, cy]
|
350
|
+
end
|
351
|
+
|
352
|
+
def screen_lower_right(element, browser=nil)
|
353
|
+
bx, by, bw, bh = get_browser_coord(browser)
|
354
|
+
w, h = element.dimensions.to_a
|
355
|
+
[bx + w, by + h]
|
356
|
+
end
|
357
|
+
|
358
|
+
def verify_resize(d, err, tol, min, act)
|
359
|
+
ary = [false, "failed, actual #{act} err #{err}"]
|
360
|
+
if err == 0
|
361
|
+
ary = [true, 'succeeded ']
|
362
|
+
#TODO need to find way to calculate this adjustment
|
363
|
+
elsif d <= min + 4
|
364
|
+
ary = [true, "reached minimum (#{min}) "]
|
365
|
+
elsif err.abs <= tol
|
366
|
+
ary = [true, "within tolerance (+-#{tol}px) "]
|
367
|
+
end
|
368
|
+
ary
|
369
|
+
end
|
370
|
+
|
371
|
+
alias validate_move verify_resize
|
372
|
+
alias validate_resize verify_resize
|
373
|
+
|
374
|
+
end
|
@@ -0,0 +1,426 @@
|
|
1
|
+
module Find
|
2
|
+
|
3
|
+
def get_select_list(browser, how, what, desc = '')
|
4
|
+
list = browser.select_list(how, what)
|
5
|
+
if validate(browser, @myName, __LINE__)
|
6
|
+
passed_to_log("Select list #{how}='#{what}' found and returned.")
|
7
|
+
return list
|
8
|
+
end
|
9
|
+
rescue
|
10
|
+
failed_to_log("Unable to return select list #{how}='#{what}': '#{$!}' (#{__LINE__})")
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_select_options(browser, how, what, dump = false)
|
14
|
+
list = browser.select_list(how, what)
|
15
|
+
dump_select_list_options(list) if dump
|
16
|
+
list.options
|
17
|
+
rescue
|
18
|
+
failed_to_log("Unable to get select options for #{how}=>#{what}. '#{$!}'")
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_select_options_by_id(browser, strg, dump = false)
|
22
|
+
get_select_options(browser, :id, strg, dump)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_select_options_by_name(browser, strg, dump = false)
|
26
|
+
get_select_options(browser, :name, strg, dump)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_selected_options(browser, how, what)
|
30
|
+
begin
|
31
|
+
list = browser.select_list(how, what)
|
32
|
+
rescue => e
|
33
|
+
if not rescue_me(e, __method__, "browser.select_list(#{how}, '#{what}')", "#{browser.class}")
|
34
|
+
raise e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
list.selected_options
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_selected_options_by_id(browser, strg)
|
41
|
+
get_selected_options(browser, :id, strg)
|
42
|
+
end
|
43
|
+
|
44
|
+
alias get_selected_option_by_id get_selected_options_by_id
|
45
|
+
|
46
|
+
def get_selected_options_by_name(browser, strg)
|
47
|
+
get_selected_options(browser, :name, strg)
|
48
|
+
end
|
49
|
+
|
50
|
+
alias get_selected_option_by_name get_selected_options_by_name
|
51
|
+
|
52
|
+
=begin rdoc
|
53
|
+
:category: A_rdoc_test
|
54
|
+
Returns a reference to a division element. Used to assign a div element to a variable
|
55
|
+
which can then be passed to methods that require a *browser* parameter.
|
56
|
+
|
57
|
+
_Parameters_::
|
58
|
+
|
59
|
+
*browser* - a reference to the browser window or container element to be tested
|
60
|
+
|
61
|
+
*how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
|
62
|
+
Common values: :text, :id, :title, :name, :class, :href (:link only)
|
63
|
+
|
64
|
+
*what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
65
|
+
|
66
|
+
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
67
|
+
|
68
|
+
_Example_
|
69
|
+
|
70
|
+
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
71
|
+
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
72
|
+
popup = attach_browser(mainwindow, :url, '[url of new window]') *or*
|
73
|
+
popup = attach_browser(mainwindow, :title, '[title of new window]')
|
74
|
+
|
75
|
+
=end
|
76
|
+
|
77
|
+
def get_div(browser, how, what, desc = '', dbg = false)
|
78
|
+
msg = "Get division #{how}=>#{what}."
|
79
|
+
msg << " #{desc}" if desc.length > 0
|
80
|
+
Watir::Wait.until { browser.div(how, what).exists? }
|
81
|
+
div = browser.div(how, what)
|
82
|
+
debug_to_log(div.inspect) if dbg
|
83
|
+
if validate(browser, @myName, __LINE__)
|
84
|
+
if div
|
85
|
+
passed_to_log(msg)
|
86
|
+
return div
|
87
|
+
else
|
88
|
+
failed_to_log(msg)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
rescue
|
92
|
+
failed_to_log("Unable to '#{msg}' '#{$!}'")
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_div_by_id(browser, strg, desc = '', dbg = false)
|
96
|
+
get_div(browser, :id, strg, desc, dbg)
|
97
|
+
end
|
98
|
+
|
99
|
+
=begin rdoc
|
100
|
+
:category: A_rdoc_test
|
101
|
+
Returns a reference to a division element identified by the value in its class attribute. Calls get_div()
|
102
|
+
|
103
|
+
_Parameters_::
|
104
|
+
|
105
|
+
*browser* - a reference to the browser window or container element to be tested
|
106
|
+
|
107
|
+
*strg* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
108
|
+
|
109
|
+
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
110
|
+
|
111
|
+
_Example_
|
112
|
+
|
113
|
+
mainwindow = open_browser('www.myapp.com') # open a browser to www.google.com
|
114
|
+
click(mainwindow, :button, :id, 'an id string') # click a button that opens another browser window
|
115
|
+
popup = attach_browser(mainwindow, :url, '[url of new window]') *or*
|
116
|
+
popup = attach_browser(mainwindow, :title, '[title of new window]')
|
117
|
+
|
118
|
+
=end
|
119
|
+
|
120
|
+
def get_div_by_class(browser, strg, desc = '', dbg = false)
|
121
|
+
get_div(browser, :class, strg, desc, dbg)
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_div_by_text(browser, strg, desc = '', dbg = false)
|
125
|
+
get_div(browser, :text, strg, desc, dbg)
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_form(browser, how, strg)
|
129
|
+
begin
|
130
|
+
# Watir::Wait.until( browser.form(how, strg).exists? ) # fails in wait_until
|
131
|
+
rescue => e
|
132
|
+
if not rescue_me(e, __method__, "browser.form(#{how}, '#{strg}').exists?", "#{browser.class}")
|
133
|
+
raise e
|
134
|
+
end
|
135
|
+
end
|
136
|
+
myForm = browser.form(how, strg)
|
137
|
+
if validate(browser, @myName, __LINE__)
|
138
|
+
passed_to_log("Form #{how}='#{strg}' found and returned.")
|
139
|
+
return myForm
|
140
|
+
end
|
141
|
+
rescue
|
142
|
+
failed_to_log("Unable to return form #{how}='#{strg}': '#{$!}' (#{__LINE__})")
|
143
|
+
end
|
144
|
+
|
145
|
+
def get_form_by_id(browser, strg)
|
146
|
+
get_form(browser, :id, strg)
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_frame(browser, how, strg, desc = '')
|
150
|
+
# begin
|
151
|
+
# Watir::Wait.until(browser.frame(how, strg).exists?) # fails in wait_until
|
152
|
+
# rescue => e
|
153
|
+
# if not rescue_me(e, __method__, "browser.frame(#{how}, '#{strg}').exists?", "#{browser.class}")
|
154
|
+
# raise e
|
155
|
+
# end
|
156
|
+
# end
|
157
|
+
begin
|
158
|
+
frame = browser.frame(how, strg)
|
159
|
+
rescue => e
|
160
|
+
if not rescue_me(e, __method__, "browser.frame(#{how}, '#{strg}').exists?", "#{browser.class}")
|
161
|
+
raise e
|
162
|
+
end
|
163
|
+
end
|
164
|
+
if validate(browser, @myName, __LINE__)
|
165
|
+
passed_to_log("Frame #{how}='#{strg}' found and returned. #{desc}")
|
166
|
+
return frame
|
167
|
+
end
|
168
|
+
rescue
|
169
|
+
failed_to_log("Unable to return frame #{how}='#{strg}'. #{desc}: '#{$!}' (#{__LINE__})")
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_frame_by_id(browser, strg, desc = '')
|
173
|
+
get_frame(browser, :id, strg, desc)
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_frame_by_index(browser, index, desc = '')
|
177
|
+
get_frame(browser, :index, index, desc)
|
178
|
+
end
|
179
|
+
|
180
|
+
def get_frame_by_name(browser, strg, desc = '')
|
181
|
+
get_frame(browser, :name, strg, desc)
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_span(browser, how, strg, desc = '')
|
185
|
+
begin
|
186
|
+
#TODO: use LegacyExtensions#wait_until
|
187
|
+
Watir::Wait.until { browser.span(how, strg).exists? }
|
188
|
+
rescue => e
|
189
|
+
if not rescue_me(e, __method__, "browser.span(#{how}, '#{strg}').exists?", "#{browser.class}")
|
190
|
+
raise e
|
191
|
+
end
|
192
|
+
end
|
193
|
+
begin
|
194
|
+
span = browser.span(how, strg)
|
195
|
+
rescue => e
|
196
|
+
if not rescue_me(e, __method__, "browser.span(#{how}, '#{strg}').exists?", "#{browser.class}")
|
197
|
+
raise e
|
198
|
+
end
|
199
|
+
end
|
200
|
+
if validate(browser, @myName, __LINE__)
|
201
|
+
passed_to_log("Span #{how}='#{strg}' found and returned. #{desc}")
|
202
|
+
return span
|
203
|
+
end
|
204
|
+
rescue
|
205
|
+
failed_to_log("Unable to return span #{how}='#{strg}'. #{desc}: '#{$!}' (#{__LINE__})")
|
206
|
+
end
|
207
|
+
|
208
|
+
def get_span_by_id(browser, strg, desc = '')
|
209
|
+
get_span(browser, :id, strg, desc)
|
210
|
+
end
|
211
|
+
|
212
|
+
=begin rdoc
|
213
|
+
:category: A_rdoc_test
|
214
|
+
Returns a reference to a table element. Used to assign a table element to a variable
|
215
|
+
which can then be used directly or passed to methods that require a *browser* or *table* parameter.
|
216
|
+
|
217
|
+
_Parameters_::
|
218
|
+
|
219
|
+
*browser* - a reference to the browser window or container element to be tested
|
220
|
+
|
221
|
+
*how* - the element attribute used to identify the specific element. Valid values depend on the kind of element.
|
222
|
+
Common values: :text, :id, :title, :name, :class, :href (:link only)
|
223
|
+
|
224
|
+
*what* - a string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
|
225
|
+
|
226
|
+
*desc* - a string containing a message or description intended to appear in the log and/or report output
|
227
|
+
|
228
|
+
_Example_
|
229
|
+
|
230
|
+
a_table = get_table(browser, :id, 'table1')
|
231
|
+
a_table_cell = a_table[2][1] # The cell in the first column of the second row of the table
|
232
|
+
|
233
|
+
=end
|
234
|
+
|
235
|
+
def get_table(browser, how, what, desc = '')
|
236
|
+
msg = "Return table :#{how}='#{what}'. #{desc}"
|
237
|
+
tbl = browser.table(how, what)
|
238
|
+
if validate(browser, @myName, __LINE__)
|
239
|
+
passed_to_log(msg)
|
240
|
+
tbl
|
241
|
+
end
|
242
|
+
rescue
|
243
|
+
failed_to_log("#{msg}': '#{$!}'")
|
244
|
+
end
|
245
|
+
|
246
|
+
def get_table_by_id(browser, strg, desc = '')
|
247
|
+
get_table(browser, :id, strg, desc)
|
248
|
+
end
|
249
|
+
|
250
|
+
def get_table_by_index(browser, idx)
|
251
|
+
get_table(browser, :index, idx, desc)
|
252
|
+
end
|
253
|
+
|
254
|
+
def get_table_by_text(browser, strg)
|
255
|
+
get_table(browser, :text, strg, desc)
|
256
|
+
end
|
257
|
+
|
258
|
+
def get_table_headers(table, header_index = 1)
|
259
|
+
headers = Hash.new
|
260
|
+
headers['index'] = Hash.new
|
261
|
+
headers['name'] = Hash.new
|
262
|
+
count = 1
|
263
|
+
table[header_index].each do |cell|
|
264
|
+
if cell.text.length > 0
|
265
|
+
name = cell.text.gsub(/\s+/, ' ')
|
266
|
+
headers['index'][count] = name
|
267
|
+
headers['name'][name] = count
|
268
|
+
end
|
269
|
+
count += 1
|
270
|
+
end
|
271
|
+
#debug_to_log("#{__method__}:****** headers:\n#{headers.to_yaml}")
|
272
|
+
headers
|
273
|
+
rescue
|
274
|
+
failed_to_log("Unable to get content headers. '#{$!}'")
|
275
|
+
end
|
276
|
+
|
277
|
+
def get_element(browser, element, how, what, value = nil)
|
278
|
+
target = nil
|
279
|
+
what = Regexp.new(Regexp.escape(what)) unless how == :index or what.is_a?(Regexp)
|
280
|
+
case element
|
281
|
+
when :link
|
282
|
+
target = browser.link(how, what)
|
283
|
+
when :button
|
284
|
+
target = browser.button(how, what)
|
285
|
+
when :div
|
286
|
+
target = browser.div(how, what)
|
287
|
+
when :checkbox
|
288
|
+
target = browser.checkbox(how, what, value)
|
289
|
+
when :text_field, :textfield
|
290
|
+
target = browser.text_field(how, what)
|
291
|
+
when :image
|
292
|
+
target = browser.image(how, what)
|
293
|
+
when :file_field, :filefield
|
294
|
+
target = browser.file_field(how, what)
|
295
|
+
when :form
|
296
|
+
target = browser.form(how, what)
|
297
|
+
when :frame
|
298
|
+
target = browser.frame(how, what)
|
299
|
+
when :radio
|
300
|
+
target = browser.radio(how, what, value)
|
301
|
+
when :span
|
302
|
+
target = browser.span(how, what)
|
303
|
+
when :table
|
304
|
+
target = browser.table(how, what)
|
305
|
+
when :li
|
306
|
+
target = browser.li(how, what)
|
307
|
+
when :select_list, :selectlist
|
308
|
+
target = browser.select_list(how, what)
|
309
|
+
when :hidden
|
310
|
+
target = browser.hidden(how, what)
|
311
|
+
when :area
|
312
|
+
target = browser.area(how, what)
|
313
|
+
end
|
314
|
+
if target.exists?
|
315
|
+
target
|
316
|
+
else
|
317
|
+
nil
|
318
|
+
end
|
319
|
+
rescue => e
|
320
|
+
if not rescue_me(e, __method__, "browser.#{element}(#{how}, '#{what}')", "#{browser.class}", target)
|
321
|
+
raise e
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
def get_objects(browser, which, dbg=false)
|
326
|
+
cnt = 0
|
327
|
+
case which
|
328
|
+
when :links
|
329
|
+
list = browser.links
|
330
|
+
sleep(1)
|
331
|
+
when :tables
|
332
|
+
list = browser.tables
|
333
|
+
when :divs
|
334
|
+
list = browser.divs
|
335
|
+
when :buttons
|
336
|
+
list = browser.buttons
|
337
|
+
when :checkboxes
|
338
|
+
list = browser.checkboxes
|
339
|
+
when :radios
|
340
|
+
list = browser.radios
|
341
|
+
when :selectlists
|
342
|
+
list = browser.selectlists
|
343
|
+
when :textfields
|
344
|
+
list = browser.textfields
|
345
|
+
when :lis
|
346
|
+
list = browser.lis
|
347
|
+
else
|
348
|
+
debug_to_log("Unrecognized dom object '#{which}'")
|
349
|
+
end
|
350
|
+
if dbg
|
351
|
+
list.each do |obj|
|
352
|
+
cnt += 1
|
353
|
+
debug_to_log("\n==========#{which}:\nindex: #{cnt}\n#{obj}\n#{obj.to_yaml}")
|
354
|
+
end
|
355
|
+
end
|
356
|
+
list
|
357
|
+
end
|
358
|
+
|
359
|
+
def get_ole(element)
|
360
|
+
ole = element.ole_object
|
361
|
+
if ole
|
362
|
+
passed_to_log("Found ole_object for #{element}.")
|
363
|
+
ole
|
364
|
+
else
|
365
|
+
failed_to_log("Did not find ole_object for #{element}.")
|
366
|
+
end
|
367
|
+
rescue
|
368
|
+
failed_to_log("Unable to find ole_object for #{element}. #{$!}")
|
369
|
+
end
|
370
|
+
|
371
|
+
def find_all_links_with_exact_href(browser, href)
|
372
|
+
links = browser.links
|
373
|
+
hash = Hash.new
|
374
|
+
idx = 0
|
375
|
+
links.each do |l|
|
376
|
+
idx += 1
|
377
|
+
an_href = href
|
378
|
+
my_href = l.href
|
379
|
+
if my_href == an_href
|
380
|
+
hash[idx] = l
|
381
|
+
debug_to_log("#{__method__}:#{idx}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
382
|
+
end
|
383
|
+
end
|
384
|
+
hash
|
385
|
+
end
|
386
|
+
|
387
|
+
def find_link_with_exact_href(browser, href)
|
388
|
+
links = browser.links
|
389
|
+
link = nil
|
390
|
+
index = 0
|
391
|
+
links.each do |l|
|
392
|
+
index += 1
|
393
|
+
an_href = href
|
394
|
+
my_href = l.href
|
395
|
+
if my_href == an_href
|
396
|
+
link = l
|
397
|
+
# debug_to_log("#{__method__}:#{__LINE__}\n********\n#{l.to_s}\n\n#{l.to_yaml}")
|
398
|
+
break
|
399
|
+
end
|
400
|
+
end
|
401
|
+
link
|
402
|
+
end
|
403
|
+
|
404
|
+
def find_index_for_object(browser, obj, how, ord, strg)
|
405
|
+
obj_sym = (obj.to_s.pluralize).to_sym
|
406
|
+
how_str = how.to_s
|
407
|
+
ptrn = /#{how}:\s+#{strg}/i
|
408
|
+
list = get_objects(browser, obj_sym, true)
|
409
|
+
cnt = 0
|
410
|
+
idx = 0
|
411
|
+
list.each do |nty|
|
412
|
+
s = nty.to_s
|
413
|
+
# a = nty.to_a
|
414
|
+
if s =~ ptrn
|
415
|
+
cnt += 1
|
416
|
+
if cnt == ord
|
417
|
+
break
|
418
|
+
end
|
419
|
+
end
|
420
|
+
idx += 1
|
421
|
+
end
|
422
|
+
idx
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
end
|