webdriver_utils 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/Gemfile +2 -0
- data/lib/webdriver_utils/version.rb +2 -2
- data/lib/webdriver_utils/wait.rb +77 -80
- data/lib/webdriver_utils.rb +1 -0
- data/readme.md +1 -1
- data/webdriver_utils.gemspec +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72a8bce6e0af6fdcd715074d606523077408e6be
|
4
|
+
data.tar.gz: c836cc054701dee05717a29dd3a0d93f41216ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b42927a3975d2e72bb4d4b265a15b70228736d3491cbacc2a4e4647bf4ae81b9a9bd69fb65dc09acdf767ff5d4d697512f6359891638f0b75a98f39db260cd84
|
7
|
+
data.tar.gz: 5568553d8b64f6cd2b95d9abcdc4910617cf15db456fdd362b7e9952d8a52eb979fca393130fe30c037e0c563dd28a8dbbd67c014047137e3d6b1c35f199312f
|
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
sudo: false
|
2
|
+
cache: bundler
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- 2.2.2
|
6
|
+
before_install: gem update --remote bundler
|
7
|
+
install:
|
8
|
+
- bundle install --retry=3
|
9
|
+
script:
|
10
|
+
- bundle exec thor spec
|
11
|
+
notifications:
|
12
|
+
email:
|
13
|
+
on_success: never
|
14
|
+
on_failure: never
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
module WebDriverUtils
|
2
|
-
VERSION = '0.0.
|
3
|
-
DATE = '2015-05-
|
2
|
+
VERSION = '0.0.3' unless defined? ::WebDriverUtils::VERSION
|
3
|
+
DATE = '2015-05-12' unless defined? ::WebDriverUtils::DATE
|
4
4
|
end
|
data/lib/webdriver_utils/wait.rb
CHANGED
@@ -1,111 +1,108 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed to the Software Freedom Conservancy (SFC) under one
|
4
|
-
# or more contributor license agreements. See the NOTICE file
|
5
|
-
# distributed with this work for additional information
|
6
|
-
# regarding copyright ownership. The SFC licenses this file
|
7
|
-
# to you under the Apache License, Version 2.0 (the
|
8
|
-
# "License"); you may not use this file except in compliance
|
9
|
-
# with the License. You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing,
|
14
|
-
# software distributed under the License is distributed on an
|
15
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
-
# KIND, either express or implied. See the License for the
|
17
|
-
# specific language governing permissions and limitations
|
18
|
-
# under the License.
|
19
|
-
|
1
|
+
# wait code from my appium ruby gem:
|
2
|
+
# https://github.com/appium/ruby_lib/blob/252e83806318df7df28e9060d3f8e1e56dc732ba/lib/appium_lib/common/wait.rb
|
20
3
|
module WebDriverUtils
|
21
|
-
class
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
# @option opts [Numeric] :timeout (5) Seconds to wait before timing out.
|
31
|
-
# @option opts [Numeric] :interval (0.2) Seconds to sleep between polls.
|
32
|
-
# @option opts [String] :message Exception mesage if timed out.
|
33
|
-
# @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Error::NoSuchElementError)
|
34
|
-
#
|
35
|
-
|
36
|
-
def initialize(opts = {})
|
37
|
-
# Validate all options to prevent typos such as 'ignored'
|
38
|
-
# instead of 'ignore'
|
39
|
-
|
40
|
-
# code from my appium gem
|
41
|
-
# https://github.com/appium/ruby_lib/blob/252e83806318df7df28e9060d3f8e1e56dc732ba/lib/appium_lib/common/wait.rb#L10
|
42
|
-
valid_keys = [:timeout, :interval, :message, :ignore]
|
4
|
+
class << self
|
5
|
+
# http://mudge.name/2011/01/26/passing-blocks-in-ruby-without-block.html
|
6
|
+
# Note that the Ruby timeout module is avoided. timeout has problems.
|
7
|
+
# https://coderwall.com/p/1novga
|
8
|
+
|
9
|
+
# Wait code from the selenium Ruby gem
|
10
|
+
# https://github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
|
11
|
+
def _generic_wait(opts = {}, &block)
|
12
|
+
valid_keys = [:timeout, :interval, :message, :ignore, :return_if_true]
|
43
13
|
invalid_keys = []
|
44
14
|
opts.keys.each { |key| invalid_keys << key unless valid_keys.include?(key) }
|
45
15
|
# [:one, :two] => :one, :two
|
46
16
|
fail "Invalid keys #{invalid_keys.to_s[1..-2]}. Valid keys are #{valid_keys.to_s[1..-2]}" unless invalid_keys.empty?
|
47
17
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
# Wait until the given block returns a true value.
|
56
|
-
#
|
57
|
-
# @raise [Error::TimeOutError]
|
58
|
-
# @return [Object] the result of the block
|
59
|
-
#
|
18
|
+
timeout = opts.fetch(:timeout, 30)
|
19
|
+
interval = opts.fetch(:interval, 0.2)
|
20
|
+
message = opts[:message]
|
21
|
+
ignored = Array(opts[:ignore] || ::Exception)
|
22
|
+
return_if_true = opts[:return_if_true]
|
60
23
|
|
61
|
-
|
62
|
-
end_time =
|
24
|
+
start_time = Time.now
|
25
|
+
end_time = start_time + timeout
|
63
26
|
last_error = nil
|
64
27
|
|
65
28
|
until Time.now > end_time
|
66
29
|
begin
|
67
|
-
|
68
|
-
|
69
|
-
|
30
|
+
if return_if_true
|
31
|
+
result = block.call
|
32
|
+
return result if result
|
33
|
+
else
|
34
|
+
return block.call
|
35
|
+
end
|
36
|
+
rescue ::Errno::ECONNREFUSED => e
|
37
|
+
raise e
|
38
|
+
rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions
|
70
39
|
# swallowed
|
71
40
|
end
|
72
41
|
|
73
|
-
sleep
|
42
|
+
sleep interval
|
74
43
|
end
|
75
44
|
|
76
|
-
|
77
|
-
|
78
|
-
msg = @message.dup
|
45
|
+
if message
|
46
|
+
msg = message.dup
|
79
47
|
else
|
80
|
-
|
48
|
+
elapsed_time = (Time.now - start_time).round
|
49
|
+
msg = "timed out after #{elapsed_time} seconds (timeout: #{timeout})"
|
81
50
|
end
|
82
51
|
|
83
52
|
msg << " (#{last_error.message})" if last_error
|
84
53
|
|
85
|
-
|
54
|
+
fail Selenium::WebDriver::Error::TimeOutError, msg
|
86
55
|
end
|
87
56
|
|
88
|
-
|
57
|
+
# process opts before calling _generic_wait
|
58
|
+
def _process_wait_opts(opts)
|
59
|
+
opts = { timeout: opts } if opts.is_a?(Numeric)
|
60
|
+
fail 'opts must be a hash' unless opts.is_a? Hash
|
61
|
+
opts
|
62
|
+
end
|
63
|
+
end # class << self
|
89
64
|
end # module WebDriverUtils
|
90
65
|
|
66
|
+
# Check every interval seconds to see if block.call returns a truthy value.
|
67
|
+
# Note this isn't a strict boolean true, any truthy value is accepted.
|
68
|
+
# false and nil are considered failures.
|
69
|
+
# Give up after timeout seconds.
|
91
70
|
#
|
92
|
-
#
|
71
|
+
# Wait code from the selenium Ruby gem
|
72
|
+
# https://github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
|
93
73
|
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# See wait class above for docs
|
74
|
+
# If only a number is provided then it's treated as the timeout value.
|
97
75
|
#
|
76
|
+
# @param [Hash] opts Options
|
77
|
+
# @option opts [Numeric] :timeout (30) Seconds to wait before timing out.
|
78
|
+
# @option opts [Numeric] :interval (0.5) Seconds to sleep between polls.
|
79
|
+
# @option opts [String] :message Exception message if timed out.
|
80
|
+
# @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Exception)
|
81
|
+
def wait_true(opts = {}, &block)
|
82
|
+
opts = WebDriverUtils._process_wait_opts(opts).merge(return_if_true: true)
|
83
|
+
WebDriverUtils._generic_wait opts, &block
|
84
|
+
end
|
98
85
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
86
|
+
# Check every interval seconds to see if block.call doesn't raise an exception.
|
87
|
+
# Give up after timeout seconds.
|
88
|
+
#
|
89
|
+
# Wait code from the selenium Ruby gem
|
90
|
+
# https://github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
|
91
|
+
#
|
92
|
+
# If only a number is provided then it's treated as the timeout value.
|
93
|
+
#
|
94
|
+
# @param [Hash] opts Options
|
95
|
+
# @option opts [Numeric] :timeout (30) Seconds to wait before timing out.
|
96
|
+
# @option opts [Numeric] :interval (0.5) Seconds to sleep between polls.
|
97
|
+
# @option opts [String] :message Exception message if timed out.
|
98
|
+
# @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Exception)
|
99
|
+
def wait(opts = {}, &block)
|
100
|
+
opts = WebDriverUtils._process_wait_opts(opts).merge(return_if_true: false)
|
101
|
+
WebDriverUtils._generic_wait opts, &block
|
102
|
+
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
# Return block.call and ignore any exceptions.
|
105
|
+
def ignore(&block)
|
106
|
+
block.call
|
107
|
+
rescue Exception # rubocop:disable Lint/HandleExceptions, Lint/RescueException
|
111
108
|
end
|
data/lib/webdriver_utils.rb
CHANGED
data/readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# webdriver_utils [![Gem Version](https://badge.fury.io/rb/webdriver_utils.svg)](https://rubygems.org/gems/webdriver_utils)
|
1
|
+
# webdriver_utils [![Gem Version](https://badge.fury.io/rb/webdriver_utils.svg)](https://rubygems.org/gems/webdriver_utils) [![Build Status](https://travis-ci.org/bootstraponline/webdriver_utils.svg?branch=master)](https://travis-ci.org/bootstraponline/webdriver_utils)
|
2
2
|
|
3
3
|
WebDriver utility methods.
|
4
4
|
|
data/webdriver_utils.gemspec
CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
+
spec.add_runtime_dependency 'selenium-webdriver', '>= 2.45.0'
|
20
|
+
|
19
21
|
spec.add_development_dependency 'pry', '~> 0.10.1'
|
20
22
|
spec.add_development_dependency 'appium_thor', '~> 0.0.7'
|
21
23
|
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webdriver_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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-
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: selenium-webdriver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.45.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.45.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: pry
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +102,7 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
91
106
|
- Gemfile
|
92
107
|
- LICENSE
|
93
108
|
- Rakefile
|