awetestlib 0.1.3-x86-mingw32 → 0.1.5-x86-mingw32

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.
Files changed (50) hide show
  1. data/awetestlib.windows.gemspec +1 -1
  2. data/bin/awetestlib +11 -4
  3. data/bin/awetestlib-helpers.rb +28 -1
  4. data/bin/awetestlib-netbeans-setup.rb +39 -0
  5. data/bin/awetestlib-rubymine-setup.rb +33 -0
  6. data/images/logo.png +0 -0
  7. data/lib/awetestlib/html_report.rb +171 -0
  8. data/lib/{regression → awetestlib}/logging.rb +10 -43
  9. data/lib/awetestlib/regression/browser.rb +1233 -0
  10. data/lib/awetestlib/regression/drag_and_drop.rb +379 -0
  11. data/lib/awetestlib/regression/find.rb +431 -0
  12. data/lib/awetestlib/regression/legacy.rb +45 -0
  13. data/lib/awetestlib/regression/page_data.rb +190 -0
  14. data/lib/awetestlib/regression/runner.rb +306 -0
  15. data/lib/awetestlib/regression/tables.rb +491 -0
  16. data/lib/awetestlib/regression/user_input.rb +1256 -0
  17. data/lib/awetestlib/regression/utilities.rb +895 -0
  18. data/lib/awetestlib/regression/validations.rb +1184 -0
  19. data/lib/awetestlib/regression/waits.rb +391 -0
  20. data/lib/awetestlib/runner.rb +16 -0
  21. data/lib/awetestlib.rb +4 -4
  22. data/lib/version.rb +2 -2
  23. data/setup_samples/sample_netbeans/demo.rb +86 -0
  24. data/setup_samples/sample_netbeans/nbproject/configs/Demo.properties +2 -0
  25. data/setup_samples/sample_netbeans/nbproject/private/config.properties +1 -0
  26. data/setup_samples/sample_netbeans/nbproject/private/configs/Demo.properties +1 -0
  27. data/setup_samples/sample_netbeans/nbproject/private/private.properties +2 -0
  28. data/setup_samples/sample_netbeans/nbproject/project.properties +5 -0
  29. data/setup_samples/sample_netbeans/nbproject/project.xml +13 -0
  30. data/setup_samples/sample_rubymine/.idea/.name +1 -0
  31. data/setup_samples/sample_rubymine/.idea/encodings.xml +5 -0
  32. data/setup_samples/sample_rubymine/.idea/misc.xml +5 -0
  33. data/setup_samples/sample_rubymine/.idea/modules.xml +9 -0
  34. data/setup_samples/sample_rubymine/.idea/sample_rubymine.iml +9 -0
  35. data/setup_samples/sample_rubymine/.idea/scopes/scope_settings.xml +5 -0
  36. data/setup_samples/sample_rubymine/.idea/vcs.xml +7 -0
  37. data/setup_samples/sample_rubymine/.idea/workspace.xml +213 -0
  38. data/setup_samples/sample_rubymine/demo.rb +86 -0
  39. metadata +44 -19
  40. data/lib/regression/browser.rb +0 -1259
  41. data/lib/regression/drag_and_drop.rb +0 -374
  42. data/lib/regression/find.rb +0 -426
  43. data/lib/regression/legacy.rb +0 -40
  44. data/lib/regression/page_data.rb +0 -185
  45. data/lib/regression/runner.rb +0 -278
  46. data/lib/regression/tables.rb +0 -486
  47. data/lib/regression/user_input.rb +0 -1255
  48. data/lib/regression/utilities.rb +0 -891
  49. data/lib/regression/validations.rb +0 -1179
  50. data/lib/regression/waits.rb +0 -387
@@ -0,0 +1,379 @@
1
+ module Awetestlib
2
+ module Regression
3
+ module DragAndDrop
4
+
5
+ def verify_element_inside(inner_element, outer_element, desc = '')
6
+ mark_testlevel("#{__method__.to_s.titleize}", 3)
7
+ msg = "#{inner_element.class.to_s} (:id=#{inner_element.id}) is fully enclosed by #{outer_element.class.to_s} (:id=#{outer_element.id})."
8
+ msg << " #{desc}" if desc.length > 0
9
+ if overlay?(inner_element, outer_element, :inside)
10
+ failed_to_log(msg)
11
+ else
12
+ passed_to_log(msg)
13
+ true
14
+ end
15
+ rescue
16
+ failed_to_log("Unable to verify that #{msg} '#{$!}'")
17
+ end
18
+
19
+ def verify_no_element_overlap(browser, above_element, above_how, above_what, below_element, below_how, below_what, side, desc = '')
20
+ mark_testlevel("#{__method__.to_s.titleize}", 3)
21
+ msg = "#{above_element.to_s.titleize} #{above_how}=>#{above_what} does not overlap "+
22
+ "#{below_element.to_s.titleize} #{below_how}=>#{below_what} at the #{side}."
23
+ msg << " #{desc}" if desc.length > 0
24
+ above = browser.element(above_how, above_what)
25
+ below = browser.element(below_how, below_what)
26
+ if overlay?(above, below, side)
27
+ failed_to_log(msg)
28
+ else
29
+ passed_to_log(msg)
30
+ true
31
+ end
32
+ rescue
33
+ failed_to_log("Unable to verify that #{msg} '#{$!}'")
34
+ end
35
+
36
+ def overlay?(inner, outer, side = :bottom)
37
+ #mark_testlevel("#{__method__.to_s.titleize}", 3)
38
+ inner_t, inner_b, inner_l, inner_r = inner.bounding_rectangle_offsets
39
+ outer_t, outer_b, outer_l, outer_r = outer.bounding_rectangle_offsets
40
+ #overlay = false
41
+ case side
42
+ when :bottom
43
+ overlay = inner_b > outer_t
44
+ when :top
45
+ overlay = inner_t > outer_t
46
+ when :left
47
+ overlay = inner_l < outer_r
48
+ when :right
49
+ overlay = inner_r > outer_r
50
+ when :inside
51
+ overlay = !(inner_t > outer_t and
52
+ inner_r < outer_r and
53
+ inner_l > outer_l and
54
+ inner_b < outer_b)
55
+ else
56
+ overlay = (inner_t > outer_b or
57
+ inner_r > outer_l or
58
+ inner_l < outer_r or
59
+ inner_b < outer_t)
60
+ end
61
+ overlay
62
+ rescue
63
+ failed_to_log("Unable to determine overlay. '#{$!}'")
64
+ end
65
+
66
+ def hover(browser, element, wait = 2)
67
+ w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
68
+ @ai.MoveMouse(xc1, yc1)
69
+ sleep_for(1)
70
+ end
71
+
72
+ def move_element_with_handle(browser, element, handle_id, dx, dy)
73
+ # msg = "Move element "
74
+ # w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
75
+ # newx = w1 + dx
76
+ # newy = h1 + dy
77
+ # msg << " by [#{dx}, #{dy}] to expected [[#{newx}, #{newy}] "
78
+ # handle = get_resize_handle(element, handle_id)
79
+ # hw, hh, hx, hy, hxc, hyc, hxlr, hylr = get_element_coordinates(browser, handle, true)
80
+
81
+ # drag_and_drop(hxc, hyc, dx, dy)
82
+
83
+ # w2, h2, x2, y2, xc2, yc2, xlr2, ylr2 = get_element_coordinates(browser, element, true)
84
+
85
+ # xerr = x2 - newx
86
+ # yerr = y2 - newy
87
+ # xdsp = (x1 - x2).abs
88
+ # ydsp = (y1 - y2).abs
89
+
90
+ # if x2 == newx and y2 == newy
91
+ # msg << "succeeded."
92
+ # passed_to_log(msg)
93
+ # else
94
+ # msg << "failed. "
95
+ # failed_to_log(msg)
96
+ # debug_to_log("x: actual #{x2}, error #{xerr}, displace #{xdsp}. y: actual #{y2}, error #{yerr}, displace #{ydsp}.")
97
+ # end
98
+
99
+ end
100
+
101
+ def resize_element_with_handle(browser, element, target, dx, dy=nil)
102
+ #TODO enhance to accept differing percentages in each direction
103
+ msg = "Resize element "
104
+ w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
105
+ if dy
106
+ deltax = dx
107
+ deltay = dy
108
+ neww = w1 + dx
109
+ newh = h1 + dy
110
+ msg << " by [#{dx}, #{dy}] " #"" to expected dimension [#{neww}, #{newh}] "
111
+ else
112
+ deltax, deltay, neww, newh = adjust_dimensions_by_percent(w1, h1, dx, true)
113
+ msg << "by #{dx} percent " #"" to expected dimension [#{neww}, #{newh}] "
114
+ end
115
+ handle = get_resize_handle_by_class(element, target) #, true)
116
+ sleep_for(0.5)
117
+ hw, hh, hx, hy, hxc, hyc, hxlr, hylr = get_element_coordinates(browser, handle, true)
118
+ hxlr_diff = 0
119
+ hylr_diff = 0
120
+
121
+ # TODO These adjustments are adhoc and empirical. Need to be derived more rigorously
122
+ if @browserAbbrev == 'IE'
123
+ hxlr_diff = (xlr1 - hxlr)
124
+ hylr_diff = (ylr1 - hylr)
125
+ x_start = hxlr - 2
126
+ y_start = hylr - 2
127
+ else
128
+ hxlr_diff = (xlr1 - hxlr) / 2 unless (xlr1 - hxlr) == 0
129
+ hylr_diff = (ylr1 - hylr) / 2 unless (ylr1 - hylr) == 0
130
+ x_start = hxlr
131
+ y_start = hylr
132
+ end
133
+
134
+ newxlr = xlr1 + deltax
135
+ newylr = ylr1 + deltay
136
+ # msg << ", lower right [#{newxlr}, #{newylr}] - "
137
+ sleep_for(0.5)
138
+
139
+ drag_and_drop(x_start, y_start, deltax, deltay)
140
+
141
+ sleep_for(1.5)
142
+ w2, h2, x2, y2, xc2, yc2, xlr2, ylr2 = get_element_coordinates(browser, element, true)
143
+
144
+ werr = w2 - neww
145
+ herr = h2 - newh
146
+
147
+ # TODO This adjustment is adhoc and empirical. Needs to be derived more rigorously
148
+ xlrerr = xlr2 - newxlr + hxlr_diff
149
+ ylrerr = ylr2 - newylr + hylr_diff
150
+
151
+ xlrdsp = (xlr1 - xlr2).abs
152
+ ylrdsp = (ylr1 - ylr2).abs
153
+
154
+ debug_to_log("\n" +
155
+ "\t\t hxlr_diff: #{hxlr_diff}\n" +
156
+ "\t\t hylr_diff: #{hylr_diff}\n" +
157
+ "\t\t werr: #{werr}\n" +
158
+ "\t\t herr: #{herr}\n" +
159
+ "\t\t xlrerr: #{xlrerr}\n" +
160
+ "\t\t ylrerr: #{ylrerr}\n" +
161
+ "\t\t xlrdsp: #{xlrdsp}\n" +
162
+ "\t\t ylrdsp: #{ylrdsp}\n" +
163
+ "\t\t @min_width: #{@min_width}\n" +
164
+ "\t\t@min_height: #{@min_height}\n" +
165
+ "\t\t x tol: #{@x_tolerance}\n" +
166
+ "\t\t y tol: #{@y_tolerance}\n"
167
+ )
168
+
169
+ #TODO Add check that window _was_ resized.
170
+ x_ok, x_msg = validate_move(w2, xlrerr, @x_tolerance, @min_width, xlr2)
171
+ y_ok, y_msg = validate_move(h2, ylrerr, @y_tolerance, @min_height, ylr2)
172
+ msg = msg + "x: #{x_msg}, y: #{y_msg}"
173
+
174
+ if x_ok and y_ok
175
+ passed_to_log(msg)
176
+ else
177
+ failed_to_log(msg)
178
+ debug_to_log("x - actual #{xlr2}, error #{xlrerr}, displace #{xlrdsp}, y - actual #{ylr2}, error #{ylrerr}, displace #{ylrdsp}.")
179
+ end
180
+ sleep_for(1)
181
+ rescue
182
+ failed_to_log("Unable to validate resize. #{$!} (#{__LINE__})")
183
+ sleep_for(1)
184
+ end
185
+
186
+ # :category: GUI
187
+ def get_resize_handle_by_id(element, id, dbg=nil)
188
+ handle = get_div_by_id(element, id, dbg)
189
+ sleep_for(1)
190
+ handle.flash(5)
191
+ return handle
192
+ end
193
+
194
+ # :category: GUI
195
+ def get_resize_handle_by_class(element, strg, dbg=nil)
196
+ handle = get_div_by_class(element, strg, dbg)
197
+ sleep_for(0.5)
198
+ handle.flash(5)
199
+ return handle
200
+ end
201
+
202
+ # :category: GUI
203
+ def get_element_coordinates(browser, element, dbg=nil)
204
+ bx, by, bw, bh = get_browser_coord(browser, dbg)
205
+ if @browserAbbrev == 'IE'
206
+ x_hack = @horizontal_hack_ie
207
+ y_hack = @vertical_hack_ie
208
+ elsif @browserAbbrev == 'FF'
209
+ x_hack = @horizontal_hack_ff
210
+ y_hack = @vertical_hack_ff
211
+ end
212
+ sleep_for(1)
213
+ w, h = element.dimensions.to_a
214
+ xc, yc = element.client_offset.to_a
215
+ # xcc, ycc = element.client_center.to_a
216
+ xcc = xc + w/2
217
+ ycc = yc + h/2
218
+ # screen offset:
219
+ xs = bx + x_hack + xc - 1
220
+ ys = by + y_hack + yc - 1
221
+ # screen center:
222
+ xsc = xs + w/2
223
+ ysc = ys + h/2
224
+ xslr = xs + w
225
+ yslr = ys + h
226
+ if dbg
227
+ debug_to_log(
228
+ "\n\t\tElement: #{element.inspect}"+
229
+ "\n\t\tbrowser screen offset: x: #{bx} y: #{by}"+
230
+ "\n\t\t dimensions: x: #{w} y: #{h}"+
231
+ "\n\t\t client offset x: #{xc} y: #{yc}"+
232
+ "\n\t\t screen offset x: #{xs} y: #{ys}"+
233
+ "\n\t\t client center x: #{xcc} y: #{ycc}"+
234
+ "\n\t\t screen center x: #{xsc} y: #{ysc}"+
235
+ "\n\t\t screen lower right x: #{xslr} y: #{yslr}")
236
+ end
237
+ [w, h, xs, ys, xsc, ysc, xslr, yslr]
238
+ end
239
+
240
+ def adjust_dimensions_by_percent(w, h, p, returnnew=nil)
241
+ p += 100
242
+ nw = (w * (p/100.0)).to_i
243
+ nh = (h * (p/100.0)).to_i
244
+ deltaw = nw - w
245
+ deltah = nh - h
246
+ if returnnew
247
+ [deltaw, deltah, nw, nh]
248
+ else
249
+ [deltaw, deltah]
250
+ end
251
+ end
252
+
253
+ def get_browser_coord(browser=nil, dbg=nil)
254
+ browser = @myBrowser if not browser
255
+ title = browser.title
256
+ x = @ai.WinGetPosX(title)
257
+ y = @ai.WinGetPosY(title)
258
+ w = @ai.WinGetPosWidth(title)
259
+ h = @ai.WinGetPosHeight(title)
260
+ if dbg
261
+ debug_to_log("\n\t\tBrowser #{browser.inspect}\n"+
262
+ "\t\tdimensions: x: #{w} y: #{h}"+
263
+ "\t\tscreen offset x: #{x} y: #{y}")
264
+ end
265
+ [x, y, w, h]
266
+ end
267
+
268
+ def drag_and_drop(x1, y1, dx, dy, speed=nil)
269
+ speed = 10 if not speed
270
+ x2 = x1 + dx
271
+ y2 = y1 + dy
272
+ debug_to_log("drag_and_drop: start: [#{x1}, #{y1}] end: [#{x2}, #{y2}]")
273
+
274
+ @ai.MouseMove(x1, y1, speed)
275
+ @ai.MouseClick("primary", x1, y1)
276
+ sleep_for(0.5)
277
+ @ai.MouseClick("primary", x1, y1)
278
+ sleep_for(0.5)
279
+ @ai.MouseClickDrag("primary", x1, y1, x2, y2, speed)
280
+ end
281
+
282
+ def drag_and_drop_element(browser, element, dx, dy, speed = nil)
283
+ speed = 10 if not speed
284
+ w1, h1, x1, y1, xc1, yc1, xlr1, ylr1 = get_element_coordinates(browser, element, true)
285
+ msg = "Move #{element} by [#{dx}, #{dy}] from center[#{xc1}, #{yc1}] "
286
+ newxc = xc1 + dx
287
+ newyc = yc1 + dy
288
+ msg << "to center[[#{newxc}, #{newyc}]"
289
+ sleep_for(0.5)
290
+
291
+ drag_and_drop(xc1, yc1, dx, dy)
292
+
293
+ sleep_for(1)
294
+ w2, h2, x2, y2, xc2, yc2, xlr2, ylr2 = get_element_coordinates(browser, element, true)
295
+
296
+ # TODO This adjustment is adhoc and empirical. Needs to be derived more rigorously
297
+ xcerr = xc2 - xc1
298
+ ycerr = yc2 - yc1
299
+
300
+ debug_to_log("\n" +
301
+ "\t\t xc1: #{xc1}\n" +
302
+ "\t\t yc1: #{yc1}\n" +
303
+ "\t\t xc2: #{xc2}\n" +
304
+ "\t\t yc2: #{yc2}\n" +
305
+ "\t\t xcerr: #{xlrerr}\n" +
306
+ "\t\t ycerr: #{ylrerr}\n" +
307
+ "\t\t x tol: #{@x_tolerance}\n" +
308
+ "\t\t y tol: #{@y_tolerance}\n"
309
+ )
310
+
311
+ #TODO Add check that window _was_ resized.
312
+ x_ok, x_msg = validate_drag_drop(xcerr, @x_tolerance, newxc, xc2)
313
+ y_ok, y_msg = validate_drag_drop(ycerr, @y_tolerance, newyc, yc2)
314
+ msg = msg + "x: #{x_msg}, y: #{y_msg}"
315
+
316
+ if x_ok and y_ok
317
+ passed_to_log(msg)
318
+ else
319
+ failed_to_log(msg)
320
+ end
321
+ sleep_for(1)
322
+ rescue
323
+ failed_to_log("Unable to validate drag and drop. #{$!} (#{__LINE__})")
324
+ sleep_for(1)
325
+ end
326
+
327
+ def right_click(element)
328
+ x = element.left_edge_absolute + 2
329
+ y = element.top_edge_absolute + 2
330
+ @ai.MouseClick("secondary", x, y)
331
+ end
332
+
333
+ def left_click(element)
334
+ x = element.left_edge_absolute + 2
335
+ y = element.top_edge_absolute + 2
336
+ @ai.MouseClick("primary", x, y)
337
+ end
338
+
339
+ def screen_offset(element, browser=nil)
340
+ bx, by, bw, bh = get_browser_coord(browser)
341
+ ex = element.left_edge
342
+ ey = element.top_edge
343
+ [bx + ex, by + ey]
344
+ end
345
+
346
+ def screen_center(element, browser=nil)
347
+ bx, by, bw, bh = get_browser_coord(browser)
348
+ w, h = element.dimensions.to_a
349
+ cx = bx + w/2
350
+ cy = by + h/2
351
+ [cx, cy]
352
+ end
353
+
354
+ def screen_lower_right(element, browser=nil)
355
+ bx, by, bw, bh = get_browser_coord(browser)
356
+ w, h = element.dimensions.to_a
357
+ [bx + w, by + h]
358
+ end
359
+
360
+ def verify_resize(d, err, tol, min, act)
361
+ ary = [false, "failed, actual #{act} err #{err}"]
362
+ if err == 0
363
+ ary = [true, 'succeeded ']
364
+ #TODO need to find way to calculate this adjustment
365
+ elsif d <= min + 4
366
+ ary = [true, "reached minimum (#{min}) "]
367
+ elsif err.abs <= tol
368
+ ary = [true, "within tolerance (+-#{tol}px) "]
369
+ end
370
+ ary
371
+ end
372
+
373
+ alias validate_move verify_resize
374
+ alias validate_resize verify_resize
375
+
376
+ end
377
+ end
378
+ end
379
+