webdriver_utils 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72a8bce6e0af6fdcd715074d606523077408e6be
4
- data.tar.gz: c836cc054701dee05717a29dd3a0d93f41216ef8
3
+ metadata.gz: b543262ea87886ef0de254e527866bc26096e6a8
4
+ data.tar.gz: 7ab995596496a179980dee6fca730a48f63d5e95
5
5
  SHA512:
6
- metadata.gz: b42927a3975d2e72bb4d4b265a15b70228736d3491cbacc2a4e4647bf4ae81b9a9bd69fb65dc09acdf767ff5d4d697512f6359891638f0b75a98f39db260cd84
7
- data.tar.gz: 5568553d8b64f6cd2b95d9abcdc4910617cf15db456fdd362b7e9952d8a52eb979fca393130fe30c037e0c563dd28a8dbbd67c014047137e3d6b1c35f199312f
6
+ metadata.gz: a14a74004015a133b2b3e5d878bdd99e792c300f3a61fb4c9b1cdc54f5a4cf1d7f369b24b0a2580fd72d8fc6cb0fe8857e155145b48f25c6ee4e7f6a401bc7bf
7
+ data.tar.gz: e96bb755e81eb1a1acede0a444c339a451fa8cc4c188ee38588af517c937629ce19a6fc639dfd1ff9fe5a77daf2f6e29c63b6f924c5146d256a25bb6de9f94a2
@@ -1,4 +1,4 @@
1
1
  module WebDriverUtils
2
- VERSION = '0.0.3' unless defined? ::WebDriverUtils::VERSION
3
- DATE = '2015-05-12' unless defined? ::WebDriverUtils::DATE
2
+ VERSION = '0.0.4' unless defined? ::WebDriverUtils::VERSION
3
+ DATE = '2015-05-23' unless defined? ::WebDriverUtils::DATE
4
4
  end
@@ -6,26 +6,38 @@ module WebDriverUtils
6
6
  # Note that the Ruby timeout module is avoided. timeout has problems.
7
7
  # https://coderwall.com/p/1novga
8
8
 
9
+ # bubble - if set, the last exception will be raised if it exists
9
10
  # Wait code from the selenium Ruby gem
10
11
  # https://github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
11
12
  def _generic_wait(opts = {}, &block)
12
- valid_keys = [:timeout, :interval, :message, :ignore, :return_if_true]
13
+ valid_keys = [:timeout, :interval, :message, :ignore, :return_if_true, :bubble]
13
14
  invalid_keys = []
14
15
  opts.keys.each { |key| invalid_keys << key unless valid_keys.include?(key) }
15
16
  # [:one, :two] => :one, :two
16
17
  fail "Invalid keys #{invalid_keys.to_s[1..-2]}. Valid keys are #{valid_keys.to_s[1..-2]}" unless invalid_keys.empty?
17
18
 
19
+ # ensure negative timeout and interval are set to zero.
18
20
  timeout = opts.fetch(:timeout, 30)
21
+ timeout = timeout < 0 ? 0 : timeout
19
22
  interval = opts.fetch(:interval, 0.2)
23
+ interval = interval < 0 ? 0 : interval
20
24
  message = opts[:message]
21
25
  ignored = Array(opts[:ignore] || ::Exception)
22
26
  return_if_true = opts[:return_if_true]
27
+ bubble = !!opts.fetch(:bubble, false)
23
28
 
24
29
  start_time = Time.now
25
30
  end_time = start_time + timeout
26
31
  last_error = nil
27
32
 
28
- until Time.now > end_time
33
+ # design note, ::TypeError, ::NameError, ::NoMethodError are not
34
+ # rescued then raised like ECONNREFUSED because they can legitimately
35
+ # occur inside a block and self correct depending on the method return
36
+ # value. This is unlike ECONNREFUSED which will always fail.
37
+
38
+ # use do..while format to ensure the block always executes at least once
39
+ # even if timeout is zero.
40
+ begin
29
41
  begin
30
42
  if return_if_true
31
43
  result = block.call
@@ -40,18 +52,23 @@ module WebDriverUtils
40
52
  end
41
53
 
42
54
  sleep interval
43
- end
55
+ end until Time.now > end_time
56
+
57
+ elapsed_time = (Time.now - start_time).round
58
+ default_message = "timed out after #{elapsed_time} seconds (timeout: #{timeout})"
44
59
 
45
60
  if message
46
- msg = message.dup
61
+ msg = "#{message.dup} [#{default_message}]"
47
62
  else
48
- elapsed_time = (Time.now - start_time).round
49
- msg = "timed out after #{elapsed_time} seconds (timeout: #{timeout})"
63
+ msg = default_message
50
64
  end
51
65
 
52
66
  msg << " (#{last_error.message})" if last_error
53
67
 
54
- fail Selenium::WebDriver::Error::TimeOutError, msg
68
+ fail_error = last_error if bubble
69
+ fail_error ||= Selenium::WebDriver::Error::TimeOutError
70
+
71
+ fail fail_error, msg
55
72
  end
56
73
 
57
74
  # process opts before calling _generic_wait
data/readme.md CHANGED
@@ -4,6 +4,12 @@ WebDriver utility methods.
4
4
 
5
5
  - `require 'webdriver_utils'`
6
6
 
7
+ #### example
8
+
9
+ [Example tests that use webdriver_utils](https://github.com/bootstraponline/sauce_connect_ruby). This repo is part of a larger [angular_automation](https://github.com/bootstraponline/angular_automation) effort although it can be used standalone.
10
+
11
+ #### methods
12
+
7
13
  method | description
8
14
  --- | ---
9
15
  **sauce_user** | returns ENV['SAUCE_USERNAME']
data/release_notes.md ADDED
@@ -0,0 +1,26 @@
1
+ #### v0.0.4 2015-05-23
2
+
3
+ - [9c8cc07](https://github.com/bootstraponline/webdriver_utils/commit/9c8cc07043fdd5de3b1e8159cee36987c6d88787) Release 0.0.4
4
+ - [02b7f46](https://github.com/bootstraponline/webdriver_utils/commit/02b7f465a7736f3eb1c9e6df4dd96f4dfaff4358) Test wait edge cases
5
+ - [4994bf5](https://github.com/bootstraponline/webdriver_utils/commit/4994bf57b483b79b58da7a368a6ed8fa3728de67) Ensure block executes at least once
6
+ - [fec9983](https://github.com/bootstraponline/webdriver_utils/commit/fec99832b43c59c23ef1c7795267a0fa85f7d4f5) Restore old rescue behavior
7
+ - [5ec2baf](https://github.com/bootstraponline/webdriver_utils/commit/5ec2baf01bffc54a9b626afbd25667acc691c7b6) Test wait bubble
8
+ - [7c60a42](https://github.com/bootstraponline/webdriver_utils/commit/7c60a428dffc9587b2b956c97186a5e5e01846d9) Update wait error and add bubble option
9
+ - [02aa9a3](https://github.com/bootstraponline/webdriver_utils/commit/02aa9a38d7a087866427f08903e8667e2f233668) Link example
10
+
11
+
12
+ #### v0.0.3 2015-05-12
13
+
14
+ - [00d66ad](https://github.com/bootstraponline/webdriver_utils/commit/00d66adafe1b979ab1228b73bb6887cea71ceaf4) Add Travis badge
15
+ - [5eb6ac0](https://github.com/bootstraponline/webdriver_utils/commit/5eb6ac036c7494dc4132917ba8d17777cce9e3e8) Fix bundle exec thor spec
16
+ - [88f7a2f](https://github.com/bootstraponline/webdriver_utils/commit/88f7a2fda6b099374e51f2a02c86433b08914ae0) Bump version to 0.0.3
17
+ - [d4acd77](https://github.com/bootstraponline/webdriver_utils/commit/d4acd77567ec2e92ee2cff013e928a67a9da9d59) Create .travis.yml
18
+ - [ca7eaa7](https://github.com/bootstraponline/webdriver_utils/commit/ca7eaa79c45109e81785f70dad41c7b62eb0f05e) Update timeout error message
19
+ - [a18d651](https://github.com/bootstraponline/webdriver_utils/commit/a18d65144981cd57eb22fceb9602d6e4be438b9e) Port wait from appium_lib gem
20
+
21
+
22
+ #### v0.0.2 2015-05-10
23
+
24
+ - [c6becae](https://github.com/bootstraponline/webdriver_utils/commit/c6becae39ed81a634246e8e6492e7c625cdeb15f) Release 0.0.2
25
+ - [058247a](https://github.com/bootstraponline/webdriver_utils/commit/058247af673e5137f53dfccc9b4c8a1cb1aa21ae) Fix sauce? method
26
+ - [45239de](https://github.com/bootstraponline/webdriver_utils/commit/45239de7f80949265f6d4ba3eb89f4f422384371) Add gem badge
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdriver_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -114,6 +114,7 @@ files:
114
114
  - lib/webdriver_utils/version.rb
115
115
  - lib/webdriver_utils/wait.rb
116
116
  - readme.md
117
+ - release_notes.md
117
118
  - webdriver_utils.gemspec
118
119
  homepage: https://github.com/bootstraponline/webdriver_utils
119
120
  licenses: