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.
@@ -0,0 +1,387 @@
1
+ module Waits
2
+
3
+ def sleep_for(seconds, dbg = true, desc = '')
4
+ msg = "Sleeping for #{seconds} seconds."
5
+ msg << " #{desc}" if desc.length > 0
6
+ msg << "\n#{get_debug_list}" if dbg
7
+ info_to_log(msg)
8
+ sleep(seconds)
9
+ end
10
+
11
+ # howLong is integer, whatFor is a browser object
12
+ =begin rdoc
13
+ :tags:wait
14
+ howLong is the number of seconds, text is a string to be found, threshold is the number of seconds
15
+ after which a fail message is generated even though the text was detected within the howLong limit.
16
+ Use this in place of wait_until_by_text when the wait time needs to be longer than the test automation default.
17
+ =end
18
+ def hold_for_text(browser, howLong, text, desc = '', threshold = 20, interval = 0.25)
19
+ countdown = howLong
20
+ while ((not browser.contains_text(text)) and countdown > 0)
21
+ sleep(interval)
22
+ countdown = countdown - interval
23
+ end
24
+ if countdown < howLong
25
+ waittime = howLong - countdown
26
+ passed_tolog("#{__method__} '#{text}' found after #{waittime} second(s) #{desc}")
27
+ if waittime > threshold
28
+ failed_tolog("#{__method__} '#{text}' took #{waittime} second(s). (threshold: #{threshold} seconds) #{desc}")
29
+ end
30
+ true
31
+ else
32
+ failed_tolog("#{__method__} '#{text}' not found after #{howLong} second(s) #{desc}")
33
+ false
34
+ end
35
+ rescue
36
+ failed_tolog("Unable to #{__method__} '#{text}'. '#{$!}' #{desc}")
37
+ end
38
+
39
+ alias wait_for_text hold_for_text
40
+
41
+ # howLong is integer, whatFor is a browser object
42
+ def wait_for_text(browser, howLong, text)
43
+ countdown = howLong
44
+ while ((not browser.contains_text(text)) and countdown > 0)
45
+ sleep(1)
46
+ countdown = countdown - 1
47
+ end
48
+ if countdown
49
+ passed_tolog("wait_for_text '#{text}' found after #{howLong} second(s)")
50
+ else
51
+ failed_tolog("wait_for_text '#{text}' not foundafter #{howLong} second(s)")
52
+ end
53
+ countdown
54
+ end
55
+
56
+ def wait_for_element_to_reappear(browser, how, what, desc = '', timeout = 20)
57
+ msg = "Element #{how}=#{what} exists. #{desc}"
58
+ wait_while(browser, "While: #{msg}", timeout) { browser.element(how, what).exists? }
59
+ wait_until(browser, "Until: #{msg}", timeout) { browser.element(how, what).exists? }
60
+ end
61
+
62
+ # howLong is integer, whatFor is a browser object
63
+ def wait_for_exists(howLong, whatFor)
64
+ wait_for(howLong, whatFor)
65
+ end
66
+
67
+ def wait_for(howLong, whatFor)
68
+ countdown = howLong
69
+ while ((not whatFor.exists?) and countdown > 0)
70
+ sleep(1)
71
+ puts whatFor.inspect+':'+countdown.to_s
72
+ countdown = countdown - 1
73
+ end
74
+ if countdown
75
+ puts 'found '+whatFor.inspect
76
+ passed_tolog("wait_for (#{howLong} found "+whatFor.inspect)
77
+ else
78
+ puts 'Did not find '+whatFor.inspect
79
+ failed_tolog("wait_for (#{howLong} did not find "+whatFor.inspect)
80
+ end
81
+ countdown
82
+ end
83
+
84
+ def wait_the_hard_way(browser, how, what, wait = 6, intvl = 0.25)
85
+ count = (wait / intvl).to_i + 1
86
+ tally = 0
87
+ ok = (1 / intvl).to_i + 1
88
+ debug_to_log("#{__method__}: wait: #{wait} secs; intvl: #{intvl} secs; count; #{count}; thresh: #{ok}")
89
+ (1..count).each do |x|
90
+ begin
91
+ if browser.element(how, what).exists?
92
+ tally += 1
93
+ debug_to_log("#{x}: #{(x - 1) * intvl}: #{what} exists.")
94
+ else
95
+ tally = 0
96
+ debug_to_log("#{x}: #{(x - 1) * intvl}: #{what} does not exist.")
97
+ end
98
+ rescue
99
+ tally = 0
100
+ debug_to_log("#{x}: #{(x - 1) * intvl}: #{what} rescue: #{$!}")
101
+ end
102
+ if tally >= ok
103
+ return true
104
+ end
105
+ sleep(intvl)
106
+ end
107
+ end
108
+
109
+ def wait_until_exists(browser, element, how, what, desc = '')
110
+ msg = "Wait until (#{element} :#{how}=>#{what}) exists."
111
+ msg << " #{desc}" if desc.length > 0
112
+ start = Time.now.to_f
113
+ # TODO: try Watir::Wait.until { browser.element(how, what).exists? } instead of this (cumbersome) case statement
114
+ # TODO: above fails on frame
115
+ begin
116
+ case element
117
+ when :link
118
+ Watir::Wait.until { browser.link(how, what).exists? }
119
+ when :button
120
+ Watir::Wait.until { browser.button(how, what).exists? }
121
+ when :radio
122
+ Watir::Wait.until { browser.radio(how, what).exists? }
123
+ when :checkbox
124
+ Watir::Wait.until { browser.checkbox(how, what).exists? }
125
+ when :div
126
+ Watir::Wait.until { browser.div(how, what).exists? }
127
+ when :select_list
128
+ Watir::Wait.until { browser.select_list(how, what).exists? }
129
+ when :text_field
130
+ Watir::Wait.until { browser.text_field(how, what).exists? }
131
+ when :frame
132
+ Watir::Wait.until { browser.frame(how, what).exists? }
133
+ when :form
134
+ Watir::Wait.until { browser.form(how, what).exists? }
135
+ when :cell
136
+ Watir::Wait.until { browser.cell(how, what).exists? }
137
+ when :image
138
+ Watir::Wait.until { browser.image(how, what).exists? }
139
+ else
140
+ Watir::Wait.until { browser.element(how, what).exists? }
141
+ end
142
+ rescue => e
143
+ if e.class.to_s =~ /TimeOutException/
144
+ failed_to_log("#{msg}: '#{$!}'")
145
+ return false
146
+ elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
147
+ raise e
148
+ end
149
+ end
150
+ stop = Time.now.to_f
151
+ #debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
152
+ # sleep 1
153
+ if validate(browser, @myName, __LINE__)
154
+ passed_to_log("#{msg} (#{stop - start} seconds)")
155
+ true
156
+ end
157
+ rescue
158
+ failed_to_log("Unable to complete #{msg}: '#{$!}'")
159
+ end
160
+
161
+ def wait_while(browser, desc, timeout = 45, &block)
162
+ #TODO: Would like to be able to see the block code in the log message instead of the identification
163
+ msg = "Wait while #{desc}:"
164
+ start = Time.now.to_f
165
+ begin
166
+ #Watir::Wait.until(timeout) { block.call(nil) }
167
+ if block.call(nil)
168
+ Watir::Wait.while(timeout) { block.call(nil) }
169
+ end
170
+ rescue => e
171
+ if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
172
+ failed_to_log("#{msg}: '#{$!}' ")
173
+ return false
174
+ elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
175
+ raise e
176
+ end
177
+ end
178
+ stop = Time.now.to_f
179
+ #debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
180
+ # sleep 1
181
+ if validate(browser, @myName, __LINE__)
182
+ passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") # {#{block.to_s}}")
183
+ true
184
+ end
185
+ rescue
186
+ failed_to_log("Unable to complete #{msg}. '#{$!}'")
187
+ end
188
+
189
+ alias wait_while_true wait_while
190
+
191
+ def wait_until(browser, desc, timeout = 45, skip_pass = false, &block)
192
+ #TODO: Would like to be able to see the block code in the log message instead of the identification
193
+ msg = "Wait until #{desc}"
194
+ start = Time.now.to_f
195
+ begin
196
+ Watir::Wait.until(timeout) { block.call(nil) }
197
+ rescue => e
198
+ if e.class.to_s =~ /TimeOutException/ or e.message =~ /timed out/
199
+ failed_to_log("#{msg} '#{$!}'")
200
+ return false
201
+ elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
202
+ raise e
203
+ end
204
+ end
205
+ stop = Time.now.to_f
206
+ #debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
207
+ # sleep 1
208
+ if validate(browser, @myName, __LINE__)
209
+ passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless skip_pass # {#{block.to_s}}")
210
+ true
211
+ end
212
+ rescue
213
+ failed_to_log("Unable to complete #{msg} '#{$!}'")
214
+ end
215
+
216
+ alias wait_until_true wait_until
217
+
218
+ def wait_until_by_radio_value(browser, strg, desc = '')
219
+ wait_until_exists(browser, :radio, :value, strg, desc)
220
+ end
221
+
222
+ def wait_until_ready(browser, how, what, desc = '', timeout = 90, verbose = false)
223
+ msg = "#{__method__.to_s.titleize}: element: #{how}='#{what}'"
224
+ msg << " #{desc}" if desc.length > 0
225
+ proc_exists = Proc.new { browser.element(how, what).exists? }
226
+ proc_enabled = Proc.new { browser.element(how, what).enabled? }
227
+ case how
228
+ when :href
229
+ proc_exists = Proc.new { browser.link(how, what).exists? }
230
+ proc_enabled = Proc.new { browser.link(how, what).enabled? }
231
+ end
232
+ if verbose
233
+ if wait_until(browser, "#{msg} Element exists.", timeout) { proc_exists.call(nil) }
234
+ if wait_until(browser, "#{msg} Element enabled.", timeout) { proc_enabled.call(nil) }
235
+ passed_to_log(msg)
236
+ true
237
+ else
238
+ failed_to_log(msg)
239
+ end
240
+ else
241
+ failed_to_log(msg)
242
+ end
243
+ else
244
+ start = Time.now.to_f
245
+ if Watir::Wait.until(timeout) { proc_exists.call(nil) }
246
+ if Watir::Wait.until(timeout) { proc_enabled.call(nil) }
247
+ stop = Time.now.to_f
248
+ #debug_to_log("#{__method__}: start:#{"%.5f" % start} stop:#{"%.5f" % stop}")
249
+ passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)")
250
+ true
251
+ else
252
+ failed_to_log(msg)
253
+ end
254
+ else
255
+ failed_to_log(msg)
256
+ end
257
+ end
258
+ rescue
259
+ failed_to_log("Unable to #{msg}. '#{$!}'")
260
+ end
261
+
262
+ def wait_until_ready_quiet(browser, how, what, desc = '', timeout = 45, quiet = true)
263
+ msg = "#{__method__.to_s.titleize}: element: #{how}='#{what}'"
264
+ msg << " #{desc}" if desc.length > 0
265
+ proc_exists = Proc.new { browser.element(how, what).exists? }
266
+ proc_enabled = Proc.new { browser.element(how, what).enabled? }
267
+ case how
268
+ when :href
269
+ proc_exists = Proc.new { browser.link(how, what).exists? }
270
+ proc_enabled = Proc.new { browser.link(how, what).enabled? }
271
+ end
272
+ start = Time.now.to_f
273
+ if Watir::Wait.until(timeout) { proc_exists.call(nil) }
274
+ if Watir::Wait.until(timeout) { proc_enabled.call(nil) }
275
+ stop = Time.now.to_f
276
+ #debug_to_log("#{msg}: start:#{"%.5f" % start} stop:#{"%.5f" % stop}")
277
+ passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless quiet
278
+ true
279
+ else
280
+ failed_to_log(msg)
281
+ end
282
+ else
283
+ failed_to_log(msg)
284
+ end
285
+ rescue
286
+ failed_to_log("Unable to #{msg}. '#{$!}'")
287
+ end
288
+
289
+ def wait_until_text(browser, strg, desc = '', timeout = 60)
290
+ if not strg.class.to_s.match('String')
291
+ raise "#{__method__} requires String for search target. #{strg.class} is not supported."
292
+ end
293
+ wait_until(browser, "'#{strg}' #{desc}", timeout) { browser.text.include? strg }
294
+ end
295
+
296
+ alias wait_until_by_text wait_until_text
297
+
298
+ def wait_until_by_link_text(browser, strg, desc = '')
299
+ wait_until_exists(browser, :link, :text, strg, desc)
300
+ end
301
+
302
+ def wait_until_enabled(browser, what, how, value, desc = '')
303
+ # TODO: This can be simplified
304
+ start = Time.now.to_f
305
+ begin
306
+ case what
307
+ when :link
308
+ Watir::Wait.until { browser.link(how, value).enabled? }
309
+ when :button
310
+ Watir::Wait.until { browser.button(how, value).enabled? }
311
+ when :radio
312
+ Watir::Wait.until { browser.radio(how, value).enabled? }
313
+ when :checkbox
314
+ Watir::Wait.until { browser.checkbox(how, value).enabled? }
315
+ when :div
316
+ Watir::Wait.until { browser.div(how, value).enabled? }
317
+ when :select_list
318
+ Watir::Wait.until { browser.select_list(how, value).enabled? }
319
+ when :text_field
320
+ Watir::Wait.until { browser.text_field(how, value).enabled? }
321
+ when :table
322
+ Watir::Wait.until { browser.table(how, value).enabled? }
323
+ else
324
+ raise "#{__method__}: Element #{what} not supported."
325
+ end
326
+ rescue => e
327
+ if e.class.to_s =~ /TimeOutException/
328
+ failed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}' #{desc}")
329
+ return false
330
+ elsif not rescue_me(e, __method__, "#{block.to_s}", "#{browser.class}")
331
+ raise e
332
+ end
333
+ end
334
+ stop = Time.now.to_f
335
+ #debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
336
+ # sleep 1
337
+ if validate(browser, @myName, __LINE__)
338
+ passed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc} (#{stop - start} seconds)")
339
+ true
340
+ end
341
+ rescue
342
+ failed_to_log("Unable to complete wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}'")
343
+ end
344
+
345
+ def wait_until_visible(browser, element, how, what, desc = '')
346
+ start = Time.now.to_f
347
+ Watir::Wait.until(20) { browser.element(how, what).exists? }
348
+ begin
349
+ case element
350
+ when :link
351
+ Watir::Wait.until { browser.link(how, what).visible? }
352
+ when :button
353
+ Watir::Wait.until { browser.button(how, what).visible? }
354
+ when :radio
355
+ Watir::Wait.until { browser.radio(how, what).visible? }
356
+ when :checkbox
357
+ Watir::Wait.until { browser.checkbox(how, what).visible? }
358
+ when :div
359
+ Watir::Wait.until { browser.div(how, what).visible? }
360
+ when :select_list
361
+ Watir::Wait.until { browser.select_list(how, what).visible? }
362
+ when :text_field
363
+ Watir::Wait.until { browser.text_field(how, what).visible? }
364
+ else
365
+ Watir::Wait.until { browser.element(how, what).visible? }
366
+ # raise "#{__method__}: Element #{what} not supported."
367
+ end
368
+ rescue => e
369
+ if e.class.to_s =~ /TimeOutException/
370
+ failed_to_log("Wait until (#{what} :#{how}=>#{what}) visible. #{desc}: '#{$!}' #{desc}")
371
+ return false
372
+ elsif not rescue_me(e, __method__, '', "#{browser.class}")
373
+ raise e
374
+ end
375
+ end
376
+ stop = Time.now.to_f
377
+ #debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
378
+ # sleep 1
379
+ if validate(browser, @myName, __LINE__)
380
+ passed_to_log("Wait until (#{element} :#{how}=>#{what}) visible. #{desc} (#{stop - start} seconds)")
381
+ true
382
+ end
383
+ rescue
384
+ failed_to_log("Unable to complete wait until (#{element} :#{how}=>#{what}) visible. #{desc}: '#{$!}'")
385
+ end
386
+
387
+ end
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Awetestlib
2
- VERSION = "0.0.3"
3
- VERSION_DATE = "2012-07-19"
2
+ VERSION = "0.1.0"
3
+ VERSION_DATE = "2012-08-14"
4
4
  end
data/rdoc_test.bat ADDED
@@ -0,0 +1 @@
1
+ rdoc --force-update -o c:/docs/rdoc_test --force-output lib/regression
@@ -0,0 +1,65 @@
1
+ module CreateZohoAccount1
2
+
3
+ def run_test(browser)
4
+ create_account_scenario_1(browser)
5
+ create_account_scenario_2(browser)
6
+ end
7
+
8
+ def create_account_scenario_1(browser)
9
+ create_account(browser)
10
+ create_blank_new_account(browser)
11
+ export_accounts(browser)
12
+ import_accounts(browser)
13
+ signout(browser)
14
+ end
15
+
16
+ def create_account_scenario_2(browser)
17
+ create_blank_new_account(browser)
18
+ reports(browser)
19
+ clone_account(browser)
20
+ pagination(browser)
21
+ verify_accounts(browser)
22
+ search_accounts(browser)
23
+ signout(browser)
24
+ end
25
+
26
+ def create_account(browser)
27
+ mark_testlevel('Create New Account', 1)
28
+ sleep_for(3)
29
+ click_text(browser, 'New Account')
30
+ wait_until_ready(browser, :name, /Account Name/)
31
+ set_textfield_by_name(browser, /Account Name/, "Test Account #1")
32
+ set_textfield_by_name(browser, /Phone/, "415-333-2311")
33
+
34
+ test_account_lookup(browser) #In Project Util
35
+ browser = attach_browser_by_url(browser, /ShowHomePage/)
36
+ select_option_by_name_and_option_text(browser, /Account Type/, "Analyst")
37
+ select_option_by_name_and_option_text(browser, /Industry/, "ASP")
38
+ set_textfield_by_name(browser, /Billing Street/, "201 Main St")
39
+ set_textfield_by_name(browser, /Billing City/, "San Francisco")
40
+ set_textfield_by_name(browser, /Billing State/, "CA")
41
+ set_textfield_by_name(browser, /Billing Code/, "94102")
42
+ set_textfield_by_name(browser, /Billing Country/, "USA")
43
+ #browser.cell(:text, 'Billing to Shipping').click
44
+ click(browser, :cell, :text, 'Billing to Shipping')
45
+ click_button_by_value(browser, 'Save')
46
+
47
+ wait_until_by_text(browser, 'Test Account #1')
48
+ validate_text(browser, "Test Account #1")
49
+ validate_text(browser, "random")
50
+ end
51
+
52
+ def test_account_lookup(browser)
53
+ mark_testlevel('Account Lookup', 1)
54
+ click(browser, :image, :title, 'Account Name Lookup')
55
+ sleep_for(5)
56
+ popup = attach_browser_by_url(browser, /Parent Account/)
57
+ set_textfield_by_name(popup, 'fldValue', 'test account #00')
58
+ click_button_by_value(popup, 'Go')
59
+ click(popup, :link, :text, 'Test Account #007')
60
+ browser = attach_browser_by_url(browser, /ShowHomePage/)
61
+ validate_textfield_value_by_name(browser, /Parent Account/, 'Test Account #007')
62
+ end
63
+
64
+
65
+ end