awetestlib 0.1.13-x86-mingw32 → 0.1.14-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,83 +1,86 @@
1
1
  module Awetestlib
2
2
  module Regression
3
+ # Methods for waiting until something has happened in the browser or DOM.
4
+ # sleep_for() is the basic technique. Its disadvantage is that it needs to be set for the longest likely wait time.
5
+ # The wait methods take advantage of the Watir and Watir Webdriver wait functionality to pause only as long as necessary for
6
+ # the element in question to be in the state needed.
3
7
  module Waits
4
8
 
9
+ # Sleep for +seconds+ seconds before continuing execution of the script.
10
+ # A message is logged (but not reported) which, by default, includes a trace showing where in the script the sleep was invoked.
11
+ # @param [Fixnum] seconds The number of seconds to wait.
12
+ # @param [Boolean] dbg If true, includes a trace in the message
13
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output.
5
14
  def sleep_for(seconds, dbg = true, desc = '')
6
- msg = "Sleeping for #{seconds} seconds."
7
- msg << " #{desc}" if desc.length > 0
15
+ trace = "\n#{get_debug_list}" if dbg
16
+ msg = build_message("Sleeping for #{seconds} seconds.", desc, trace)
8
17
  info_to_log(msg)
9
18
  sleep(seconds)
10
19
  end
11
20
 
12
- # howLong is integer, whatFor is a browser object
13
- =begin rdoc
14
- :tags:wait
15
- howLong is the number of seconds, text is a string to be found, threshold is the number of seconds
16
- after which a fail message is generated even though the text was detected within the howLong limit.
17
- Use this in place of wait_until_by_text when the wait time needs to be longer than the test automation default.
18
- =end
19
- def hold_for_text(browser, howLong, text, desc = '', threshold = 20, interval = 0.25)
20
- countdown = howLong
21
+ # Wait for a specific text to appear in the +browser+.
22
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
23
+ # @param [String, Regexp] text A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
24
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
25
+ # @param [Fixnum] threshold The number of seconds after which a warning is added to the report message.
26
+ # @param [Fixnum] interval The time between checks that the text exists.
27
+ # @return [Boolean] Returns true if the text appears before +how_long+ has expired.
28
+ def hold_for_text(browser, how_long, text, desc = '', threshold = 20, interval = 0.25)
29
+ countdown = how_long
21
30
  while ((not browser.contains_text(text)) and countdown > 0)
22
31
  sleep(interval)
23
32
  countdown = countdown - interval
24
33
  end
25
- if countdown < howLong
26
- waittime = howLong - countdown
27
- passed_tolog("#{__method__} '#{text}' found after #{waittime} second(s) #{desc}")
34
+ if countdown < how_long
35
+ waittime = how_long - countdown
36
+ passed_to_log("#{__method__} '#{text}' found after #{waittime} second(s) #{desc}")
28
37
  if waittime > threshold
29
- failed_tolog("#{__method__} '#{text}' took #{waittime} second(s). (threshold: #{threshold} seconds) #{desc}")
38
+ failed_to_log("#{__method__} '#{text}' took #{waittime} second(s). (threshold: #{threshold} seconds) #{desc}")
30
39
  end
31
40
  true
32
41
  else
33
- failed_tolog("#{__method__} '#{text}' not found after #{howLong} second(s) #{desc}")
42
+ failed_to_log("#{__method__} '#{text}' not found after #{how_long} second(s) #{desc}")
34
43
  false
35
44
  end
36
45
  rescue
37
- failed_tolog("Unable to #{__method__} '#{text}'. '#{$!}' #{desc}")
46
+ failed_to_log("Unable to #{__method__} '#{text}'. '#{$!}' #{desc}")
38
47
  end
39
48
 
40
49
  alias wait_for_text hold_for_text
41
50
 
42
- # howLong is integer, whatFor is a browser object
43
- def wait_for_text(browser, howLong, text)
44
- countdown = howLong
45
- while ((not browser.contains_text(text)) and countdown > 0)
46
- sleep(1)
47
- countdown = countdown - 1
48
- end
49
- if countdown
50
- passed_tolog("wait_for_text '#{text}' found after #{howLong} second(s)")
51
- else
52
- failed_tolog("wait_for_text '#{text}' not foundafter #{howLong} second(s)")
53
- end
54
- countdown
55
- end
56
-
51
+ # Wait while an element identified by attribute +how+ with value +what+ 1) exists, disappears, and exists again.
52
+ # @param [Watir::Browser] browser A reference to the browser window or container element to be tested.
53
+ # @param [Symbol] how The element attribute used to identify the specific element.
54
+ # Valid values depend on the kind of element.
55
+ # Common values: :text, :id, :title, :name, :class, :href (:link only)
56
+ # @param [String, Regexp] what A string or a regular expression to be found in the *how* attribute that uniquely identifies the element.
57
+ # @param [String] desc Contains a message or description intended to appear in the log and/or report output
58
+ # @param [Fixnum] timeout
59
+ # @return [Boolean] Returns true if disappears and reappears, each within the +timeout+ limit
57
60
  def wait_for_element_to_reappear(browser, how, what, desc = '', timeout = 20)
58
61
  msg = "Element #{how}=#{what} exists. #{desc}"
59
62
  wait_while(browser, "While: #{msg}", timeout) { browser.element(how, what).exists? }
60
63
  wait_until(browser, "Until: #{msg}", timeout) { browser.element(how, what).exists? }
61
64
  end
62
65
 
63
- # howLong is integer, whatFor is a browser object
64
- def wait_for_exists(howLong, whatFor)
65
- wait_for(howLong, whatFor)
66
+ # how_long is integer, what_for is a browser object
67
+ def wait_for_exists(how_long, what_for)
68
+ wait_for(how_long, what_for)
66
69
  end
67
70
 
68
- def wait_for(howLong, whatFor)
69
- countdown = howLong
70
- while ((not whatFor.exists?) and countdown > 0)
71
+ def wait_for(how_long, what_for)
72
+ countdown = how_long
73
+ while ((not what_for.exists?) and countdown > 0)
71
74
  sleep(1)
72
- puts whatFor.inspect+':'+countdown.to_s
75
+ puts what_for.inspect+':'+countdown.to_s
73
76
  countdown = countdown - 1
74
77
  end
75
78
  if countdown
76
- puts 'found '+whatFor.inspect
77
- passed_tolog("wait_for (#{howLong} found "+whatFor.inspect)
79
+ puts 'found '+what_for.inspect
80
+ passed_tolog("wait_for (#{how_long} found "+what_for.inspect)
78
81
  else
79
- puts 'Did not find '+whatFor.inspect
80
- failed_tolog("wait_for (#{howLong} did not find "+whatFor.inspect)
82
+ puts 'Did not find '+what_for.inspect
83
+ failed_tolog("wait_for (#{how_long} did not find "+what_for.inspect)
81
84
  end
82
85
  countdown
83
86
  end
@@ -151,10 +154,8 @@ Use this in place of wait_until_by_text when the wait time needs to be longer th
151
154
  stop = Time.now.to_f
152
155
  #debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
153
156
  # sleep 1
154
- if validate(browser, @myName, __LINE__)
155
- passed_to_log("#{msg} (#{stop - start} seconds)")
156
- true
157
- end
157
+ passed_to_log("#{msg} (#{stop - start} seconds)")
158
+ true
158
159
  rescue
159
160
  failed_to_log("Unable to complete #{msg}: '#{$!}'")
160
161
  end
@@ -178,11 +179,9 @@ Use this in place of wait_until_by_text when the wait time needs to be longer th
178
179
  end
179
180
  stop = Time.now.to_f
180
181
  #debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
181
- # sleep 1
182
- if validate(browser, @myName, __LINE__)
183
- passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") # {#{block.to_s}}")
184
- true
185
- end
182
+ # sleep 1
183
+ passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") # {#{block.to_s}}")
184
+ true
186
185
  rescue
187
186
  failed_to_log("Unable to complete #{msg}. '#{$!}'")
188
187
  end
@@ -205,11 +204,9 @@ Use this in place of wait_until_by_text when the wait time needs to be longer th
205
204
  end
206
205
  stop = Time.now.to_f
207
206
  #debug_to_log("#{__method__}: start:#{start} stop:#{stop} block: #{block.to_s}")
208
- # sleep 1
209
- if validate(browser, @myName, __LINE__)
210
- passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless skip_pass # {#{block.to_s}}")
211
- true
212
- end
207
+ # sleep 1
208
+ passed_to_log("#{msg} (#{"%.5f" % (stop - start)} seconds)") unless skip_pass # {#{block.to_s}}")
209
+ true
213
210
  rescue
214
211
  failed_to_log("Unable to complete #{msg} '#{$!}'")
215
212
  end
@@ -335,10 +332,8 @@ Use this in place of wait_until_by_text when the wait time needs to be longer th
335
332
  stop = Time.now.to_f
336
333
  #debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
337
334
  # sleep 1
338
- if validate(browser, @myName, __LINE__)
339
- passed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc} (#{stop - start} seconds)")
340
- true
341
- end
335
+ passed_to_log("Wait until (#{what} :#{how}=>#{value}) enabled. #{desc} (#{stop - start} seconds)")
336
+ true
342
337
  rescue
343
338
  failed_to_log("Unable to complete wait until (#{what} :#{how}=>#{value}) enabled. #{desc}: '#{$!}'")
344
339
  end
@@ -364,7 +359,7 @@ Use this in place of wait_until_by_text when the wait time needs to be longer th
364
359
  Watir::Wait.until { browser.text_field(how, what).visible? }
365
360
  else
366
361
  Watir::Wait.until { browser.element(how, what).visible? }
367
- # raise "#{__method__}: Element #{what} not supported."
362
+ # raise "#{__method__}: Element #{what} not supported."
368
363
  end
369
364
  rescue => e
370
365
  if e.class.to_s =~ /TimeOutException/
@@ -377,10 +372,8 @@ Use this in place of wait_until_by_text when the wait time needs to be longer th
377
372
  stop = Time.now.to_f
378
373
  #debug_to_log("#{__method__}: start:#{start} stop:#{stop}")
379
374
  # sleep 1
380
- if validate(browser, @myName, __LINE__)
381
- passed_to_log("Wait until (#{element} :#{how}=>#{what}) visible. #{desc} (#{stop - start} seconds)")
382
- true
383
- end
375
+ passed_to_log("Wait until (#{element} :#{how}=>#{what}) visible. #{desc} (#{stop - start} seconds)")
376
+ true
384
377
  rescue
385
378
  failed_to_log("Unable to complete wait until (#{element} :#{how}=>#{what}) visible. #{desc}: '#{$!}'")
386
379
  end
@@ -1,3 +1,4 @@
1
+ require 'open-uri'
1
2
  module Awetestlib
2
3
  class Runner
3
4
  def initialize(options = {})
data/lib/awetestlib.rb CHANGED
@@ -20,7 +20,7 @@ module Awetestlib
20
20
 
21
21
  if USING_WINDOWS
22
22
  #require 'win32ole' <-- We'll load this later in Shamisen::AwetestLegacy::Runner. It has to be loaded after watir, see https://www.pivotaltracker.com/story/show/19249981
23
- require 'win32/screenshot'
23
+ require 'win32/screenshot' # triggering segmentation fault 10sep2012 pmn
24
24
  end
25
25
  #require 'active_support/inflector'
26
26
  #require 'active_support/core_ext/object'
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Awetestlib
2
- VERSION = "0.1.13"
3
- VERSION_DATE = "2012-09-18"
2
+ VERSION = "0.1.14"
3
+ VERSION_DATE = "2012-09-19"
4
4
  end
data/test/create_zoho.rb CHANGED
@@ -1,3 +1,4 @@
1
+ $watir_script = true
1
2
  module CreateZohoAccount1
2
3
 
3
4
  def run_test(browser)
@@ -1,3 +1,5 @@
1
+ #include 'pry'
2
+ $watir_script = true
1
3
  module CreateZohoAccount1
2
4
 
3
5
  def run_test(browser)
@@ -1,3 +1,4 @@
1
+ $watir_script = true
1
2
  module CreateZohoAccount2
2
3
 
3
4
  def run_test(browser)
data/test/zoho_util.rb CHANGED
@@ -35,7 +35,9 @@ module ZohoUtil
35
35
  end
36
36
 
37
37
  def zoho_login(browser, userid, password, url, validation = 'Welcome joeklienwatir at Software')
38
- mark_testlevel("#{__method__.to_s.titleize}", 8)
38
+ msg = build_message("#{__method__.to_s.titleize}", "userid:'#{userid}",
39
+ "password:'#{password}", "URL:#{url}")
40
+ mark_testlevel(msg, 8)
39
41
  set_textfield_by_name(browser, 'lid', userid)
40
42
  set_textfield_by_name(browser, 'pwd', password)
41
43
  click_button_by_value(browser, 'Sign In')
@@ -64,7 +66,7 @@ module ZohoUtil
64
66
  validate_text(browser, 'Create Account')
65
67
  click_button_by_value(browser, 'Save')
66
68
  sleep(1)
67
- close_popup('Message from webpage')
69
+ close_popup(browser, 'Message from webpage')
68
70
  end
69
71
 
70
72
  def export_accounts(browser)
@@ -76,7 +78,7 @@ module ZohoUtil
76
78
  select_option_by_name_and_option_value(browser, 'module', 'Accounts')
77
79
  if @use_sikuli
78
80
  run_sikuli_script("exportaccounts")
79
- close_popup('File Download')
81
+ close_popup(browser, 'File Download')
80
82
  else
81
83
  #click_button_no_wait_by_value(browser, 'Export')
82
84
  # Make sure popups are allowed by browser
@@ -93,12 +95,12 @@ module ZohoUtil
93
95
 
94
96
  click_button_no_wait_by_value(browser, 'Export')
95
97
  sleep_for(5)
96
- close_popup('Message from webpage', 'Are you sure?')
98
+ close_popup(browser, 'Message from webpage', 'Are you sure?')
97
99
  sleep_for(1)
98
100
 
99
101
  click_button_no_wait_by_value(browser, 'Export')
100
102
  sleep_for(3)
101
- close_popup('Message from webpage', 'Are you sure?')
103
+ close_popup(browser, 'Message from webpage', 'Are you sure?')
102
104
  sleep_for(3)
103
105
 
104
106
  save_file1(filepath)
@@ -277,7 +279,7 @@ module ZohoUtil
277
279
  sleep(1)
278
280
  click_button_by_value(browser, 'Delete')
279
281
  sleep(1)
280
- close_popup('Message from webpage')
282
+ close_popup(browser, 'Message from webpage')
281
283
  end
282
284
 
283
285
  def find_lead_reports(browser) ## Find Lead Reports by Source
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awetestlib
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 13
10
- version: 0.1.13
9
+ - 14
10
+ version: 0.1.14
11
11
  platform: x86-mingw32
12
12
  authors:
13
13
  - Anthony Woo
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-09-18 00:00:00 Z
19
+ date: 2012-09-19 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: watir-webdriver