webdrivers 3.7.1 → 3.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -6
- data/.rubocop.yml +19 -0
- data/.travis.yml +6 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +69 -24
- data/Rakefile +9 -6
- data/lib/webdrivers.rb +8 -10
- data/lib/webdrivers/chromedriver.rb +26 -19
- data/lib/webdrivers/common.rb +36 -35
- data/lib/webdrivers/geckodriver.rb +8 -9
- data/lib/webdrivers/iedriver.rb +6 -7
- data/lib/webdrivers/logger.rb +109 -109
- data/lib/webdrivers/mswebdriver.rb +8 -9
- data/lib/webdrivers/selenium.rb +29 -29
- data/spec/spec_helper.rb +5 -2
- data/spec/{chromedriver_spec.rb → webdrivers/chromedriver_spec.rb} +19 -8
- data/spec/{geckodriver_spec.rb → webdrivers/geckodriver_spec.rb} +5 -7
- data/spec/{iedriver_spec.rb → webdrivers/i_edriver_spec.rb} +6 -8
- data/spec/{mswebdriver_spec.rb → webdrivers/ms_webdriver_spec.rb} +4 -6
- data/spec/webdrivers_proxy_support_spec.rb +45 -0
- data/webdrivers.gemspec +4 -3
- metadata +51 -8
- data/spec/proxy_support_spec.rb +0 -45
@@ -3,11 +3,11 @@ require 'nokogiri'
|
|
3
3
|
module Webdrivers
|
4
4
|
class Geckodriver < Common
|
5
5
|
class << self
|
6
|
-
|
7
6
|
def current_version
|
8
|
-
Webdrivers.logger.debug
|
7
|
+
Webdrivers.logger.debug 'Checking current version'
|
9
8
|
return nil unless downloaded?
|
10
|
-
|
9
|
+
|
10
|
+
string = `#{binary} --version`
|
11
11
|
Webdrivers.logger.debug "Current version of #{binary} is #{string}"
|
12
12
|
normalize string.match(/geckodriver (\d+\.\d+\.\d+)/)[1]
|
13
13
|
end
|
@@ -19,9 +19,9 @@ module Webdrivers
|
|
19
19
|
|
20
20
|
@downloads ||= begin
|
21
21
|
doc = Nokogiri::HTML.parse(get(base_url))
|
22
|
-
items = doc.css(
|
23
|
-
items.reject! {|item| item.include?('archive')}
|
24
|
-
items.select! {|item| item.include?(platform)}
|
22
|
+
items = doc.css('.py-1 a').collect { |item| item['href'] }
|
23
|
+
items.reject! { |item| item.include?('archive') }
|
24
|
+
items.select! { |item| item.include?(platform) }
|
25
25
|
ds = items.each_with_object({}) do |item, hash|
|
26
26
|
key = normalize item[/v(\d+\.\d+\.\d+)/, 1]
|
27
27
|
hash[key] = "https://github.com#{item}"
|
@@ -32,13 +32,12 @@ module Webdrivers
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def file_name
|
35
|
-
platform ==
|
35
|
+
platform == 'win' ? 'geckodriver.exe' : 'geckodriver'
|
36
36
|
end
|
37
37
|
|
38
38
|
def base_url
|
39
39
|
'https://github.com/mozilla/geckodriver/releases'
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
end
|
44
|
-
end
|
43
|
+
end
|
data/lib/webdrivers/iedriver.rb
CHANGED
@@ -4,11 +4,11 @@ require 'rubygems/version'
|
|
4
4
|
module Webdrivers
|
5
5
|
class IEdriver < Common
|
6
6
|
class << self
|
7
|
-
|
8
7
|
def current_version
|
9
|
-
Webdrivers.logger.debug
|
8
|
+
Webdrivers.logger.debug 'Checking current version'
|
10
9
|
return nil unless downloaded?
|
11
|
-
|
10
|
+
|
11
|
+
string = `#{binary} --version`
|
12
12
|
Webdrivers.logger.debug "Current version of #{binary} is #{string}"
|
13
13
|
normalize string.match(/IEDriverServer.exe (\d\.\d+\.\d*\.\d*)/)[1]
|
14
14
|
end
|
@@ -16,7 +16,7 @@ module Webdrivers
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def file_name
|
19
|
-
|
19
|
+
'IEDriverServer.exe'
|
20
20
|
end
|
21
21
|
|
22
22
|
def base_url
|
@@ -28,7 +28,7 @@ module Webdrivers
|
|
28
28
|
|
29
29
|
@downloads ||= begin
|
30
30
|
doc = Nokogiri::XML.parse(get(base_url))
|
31
|
-
items = doc.css(
|
31
|
+
items = doc.css('Key').collect(&:text)
|
32
32
|
items.select! { |item| item.include?('IEDriverServer_Win32') }
|
33
33
|
ds = items.each_with_object({}) do |item, hash|
|
34
34
|
key = normalize item[/([^_]+)\.zip/, 1]
|
@@ -38,7 +38,6 @@ module Webdrivers
|
|
38
38
|
ds
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
end
|
44
|
-
end
|
43
|
+
end
|
data/lib/webdrivers/logger.rb
CHANGED
@@ -1,109 +1,109 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
# Code adapted from Selenium Implementation
|
5
|
-
# https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/logger.rb
|
6
|
-
|
7
|
-
module Webdrivers
|
8
|
-
#
|
9
|
-
# @example Enable full logging
|
10
|
-
# Webdrivers.logger.level = :debug
|
11
|
-
#
|
12
|
-
# @example Log to file
|
13
|
-
# Webdrivers.logger.output = 'webdrivers.log'
|
14
|
-
#
|
15
|
-
# @example Use logger manually
|
16
|
-
# Webdrivers.logger.info('This is info message')
|
17
|
-
# Webdrivers.logger.warn('This is warning message')
|
18
|
-
#
|
19
|
-
class Logger
|
20
|
-
extend Forwardable
|
21
|
-
include ::Logger::Severity
|
22
|
-
|
23
|
-
def_delegators :@logger, :debug, :debug?,
|
24
|
-
:info, :info?,
|
25
|
-
:warn, :warn?,
|
26
|
-
:error, :error?,
|
27
|
-
:fatal, :fatal?,
|
28
|
-
:level
|
29
|
-
|
30
|
-
def initialize
|
31
|
-
@logger = create_logger($stdout)
|
32
|
-
end
|
33
|
-
|
34
|
-
def output=(io)
|
35
|
-
# `Logger#reopen` was added in Ruby 2.3
|
36
|
-
if @logger.respond_to?(:reopen)
|
37
|
-
@logger.reopen(io)
|
38
|
-
else
|
39
|
-
@logger = create_logger(io)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# For Ruby < 2.3 compatibility
|
45
|
-
# Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250
|
46
|
-
#
|
47
|
-
|
48
|
-
def level=(severity)
|
49
|
-
if severity.is_a?(Integer)
|
50
|
-
@logger.level = severity
|
51
|
-
else
|
52
|
-
case severity.to_s.downcase
|
53
|
-
when 'debug'.freeze
|
54
|
-
@logger.level = DEBUG
|
55
|
-
when 'info'.freeze
|
56
|
-
@logger.level = INFO
|
57
|
-
when 'warn'.freeze
|
58
|
-
@logger.level = WARN
|
59
|
-
when 'error'.freeze
|
60
|
-
@logger.level = ERROR
|
61
|
-
when 'fatal'.freeze
|
62
|
-
@logger.level = FATAL
|
63
|
-
when 'unknown'.freeze
|
64
|
-
@logger.level = UNKNOWN
|
65
|
-
else
|
66
|
-
raise ArgumentError, "invalid log level: #{severity}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Returns IO object used by logger internally.
|
73
|
-
#
|
74
|
-
# Normally, we would have never needed it, but we want to
|
75
|
-
# use it as IO object for all child processes to ensure their
|
76
|
-
# output is redirected there.
|
77
|
-
#
|
78
|
-
# It is only used in debug level, in other cases output is suppressed.
|
79
|
-
#
|
80
|
-
# @api private
|
81
|
-
#
|
82
|
-
def io
|
83
|
-
@logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Marks code as deprecated with replacement.
|
88
|
-
#
|
89
|
-
# @param [String] old
|
90
|
-
# @param [String] new
|
91
|
-
#
|
92
|
-
def deprecate(old, new)
|
93
|
-
warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def create_logger(output)
|
99
|
-
logger = ::Logger.new(output)
|
100
|
-
logger.progname = 'Webdrivers'
|
101
|
-
logger.level = ($DEBUG ? DEBUG : WARN)
|
102
|
-
logger.formatter = proc do |severity, time, progname, msg|
|
103
|
-
"#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
|
104
|
-
end
|
105
|
-
|
106
|
-
logger
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
1
|
+
require 'forwardable'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
# Code adapted from Selenium Implementation
|
5
|
+
# https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/common/logger.rb
|
6
|
+
|
7
|
+
module Webdrivers
|
8
|
+
#
|
9
|
+
# @example Enable full logging
|
10
|
+
# Webdrivers.logger.level = :debug
|
11
|
+
#
|
12
|
+
# @example Log to file
|
13
|
+
# Webdrivers.logger.output = 'webdrivers.log'
|
14
|
+
#
|
15
|
+
# @example Use logger manually
|
16
|
+
# Webdrivers.logger.info('This is info message')
|
17
|
+
# Webdrivers.logger.warn('This is warning message')
|
18
|
+
#
|
19
|
+
class Logger
|
20
|
+
extend Forwardable
|
21
|
+
include ::Logger::Severity
|
22
|
+
|
23
|
+
def_delegators :@logger, :debug, :debug?,
|
24
|
+
:info, :info?,
|
25
|
+
:warn, :warn?,
|
26
|
+
:error, :error?,
|
27
|
+
:fatal, :fatal?,
|
28
|
+
:level
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@logger = create_logger($stdout)
|
32
|
+
end
|
33
|
+
|
34
|
+
def output=(io)
|
35
|
+
# `Logger#reopen` was added in Ruby 2.3
|
36
|
+
if @logger.respond_to?(:reopen)
|
37
|
+
@logger.reopen(io)
|
38
|
+
else
|
39
|
+
@logger = create_logger(io)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# For Ruby < 2.3 compatibility
|
45
|
+
# Based on https://github.com/ruby/ruby/blob/ruby_2_3/lib/logger.rb#L250
|
46
|
+
#
|
47
|
+
|
48
|
+
def level=(severity)
|
49
|
+
if severity.is_a?(Integer)
|
50
|
+
@logger.level = severity
|
51
|
+
else
|
52
|
+
case severity.to_s.downcase
|
53
|
+
when 'debug'.freeze
|
54
|
+
@logger.level = DEBUG
|
55
|
+
when 'info'.freeze
|
56
|
+
@logger.level = INFO
|
57
|
+
when 'warn'.freeze
|
58
|
+
@logger.level = WARN
|
59
|
+
when 'error'.freeze
|
60
|
+
@logger.level = ERROR
|
61
|
+
when 'fatal'.freeze
|
62
|
+
@logger.level = FATAL
|
63
|
+
when 'unknown'.freeze
|
64
|
+
@logger.level = UNKNOWN
|
65
|
+
else
|
66
|
+
raise ArgumentError, "invalid log level: #{severity}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Returns IO object used by logger internally.
|
73
|
+
#
|
74
|
+
# Normally, we would have never needed it, but we want to
|
75
|
+
# use it as IO object for all child processes to ensure their
|
76
|
+
# output is redirected there.
|
77
|
+
#
|
78
|
+
# It is only used in debug level, in other cases output is suppressed.
|
79
|
+
#
|
80
|
+
# @api private
|
81
|
+
#
|
82
|
+
def io
|
83
|
+
@logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Marks code as deprecated with replacement.
|
88
|
+
#
|
89
|
+
# @param [String] old
|
90
|
+
# @param [String] new
|
91
|
+
#
|
92
|
+
def deprecate(old, new)
|
93
|
+
warn "[DEPRECATION] #{old} is deprecated. Use #{new} instead."
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def create_logger(output)
|
99
|
+
logger = ::Logger.new(output)
|
100
|
+
logger.progname = 'Webdrivers'
|
101
|
+
logger.level = ($DEBUG ? DEBUG : WARN)
|
102
|
+
logger.formatter = proc do |severity, time, progname, msg|
|
103
|
+
"#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
logger
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Webdrivers
|
2
2
|
class MSWebdriver < Common
|
3
|
-
|
4
3
|
class << self
|
5
|
-
|
6
4
|
def windows_version
|
7
|
-
Webdrivers.logger.debug
|
5
|
+
Webdrivers.logger.debug 'Checking current version'
|
8
6
|
|
9
7
|
# current_version() from other webdrivers returns the version from the webdriver EXE.
|
10
8
|
# Unfortunately, MicrosoftWebDriver.exe does not have an option to get the version.
|
11
9
|
# To work around it we query the currently installed version of Microsoft Edge instead
|
12
10
|
# and compare it to the list of available downloads.
|
13
11
|
version = `powershell (Get-AppxPackage -Name Microsoft.MicrosoftEdge).Version`
|
14
|
-
raise
|
12
|
+
raise 'Failed to check Microsoft Edge version.' if version.empty? # Package name changed?
|
13
|
+
|
15
14
|
Webdrivers.logger.debug "Current version of Microsoft Edge is #{version.chomp!}"
|
16
15
|
|
17
16
|
build = version.split('.')[1] # "41.16299.248.0" => "16299"
|
@@ -22,22 +21,23 @@ module Webdrivers
|
|
22
21
|
# Webdriver binaries for Microsoft Edge are not backwards compatible.
|
23
22
|
# For this reason, instead of downloading the latest binary we download the correct one for the
|
24
23
|
# currently installed browser version.
|
25
|
-
alias
|
24
|
+
alias version windows_version
|
26
25
|
|
27
26
|
def version=(*)
|
28
|
-
raise
|
27
|
+
raise 'Version can not be set for MSWebdriver because it is dependent on the version of Edge'
|
29
28
|
end
|
30
29
|
|
31
30
|
private
|
32
31
|
|
33
32
|
def file_name
|
34
|
-
|
33
|
+
'MicrosoftWebDriver.exe'
|
35
34
|
end
|
36
35
|
|
37
36
|
def downloads
|
38
37
|
array = Nokogiri::HTML(get(base_url)).xpath("//li[@class='driver-download']/a")
|
39
38
|
array.each_with_object({}) do |link, hash|
|
40
39
|
next if link.text == 'Insiders'
|
40
|
+
|
41
41
|
key = normalize link.text.scan(/\d+/).first.to_i
|
42
42
|
hash[key] = link['href']
|
43
43
|
end
|
@@ -52,7 +52,6 @@ module Webdrivers
|
|
52
52
|
def correct_binary?
|
53
53
|
File.exist?(binary)
|
54
54
|
end
|
55
|
-
|
56
55
|
end
|
57
56
|
end
|
58
|
-
end
|
57
|
+
end
|
data/lib/webdrivers/selenium.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'selenium-webdriver'
|
2
|
-
|
3
|
-
module Selenium
|
4
|
-
module WebDriver
|
5
|
-
module Chrome
|
6
|
-
def self.driver_path
|
7
|
-
@driver_path ||= Webdrivers::Chromedriver.update
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module Firefox
|
12
|
-
def self.driver_path
|
13
|
-
@driver_path ||= Webdrivers::Geckodriver.update
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module Edge
|
18
|
-
def self.driver_path
|
19
|
-
@driver_path ||= Webdrivers::MSWebdriver.update
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module IE
|
24
|
-
def self.driver_path
|
25
|
-
@driver_path ||= Webdrivers::IEdriver.update
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
require 'selenium-webdriver'
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
module WebDriver
|
5
|
+
module Chrome
|
6
|
+
def self.driver_path
|
7
|
+
@driver_path ||= Webdrivers::Chromedriver.update
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Firefox
|
12
|
+
def self.driver_path
|
13
|
+
@driver_path ||= Webdrivers::Geckodriver.update
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Edge
|
18
|
+
def self.driver_path
|
19
|
+
@driver_path ||= Webdrivers::MSWebdriver.update
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module IE
|
24
|
+
def self.driver_path
|
25
|
+
@driver_path ||= Webdrivers::IEdriver.update
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Webdrivers::Chromedriver do
|
4
|
-
|
5
|
-
let(:chromedriver) { Webdrivers::Chromedriver }
|
4
|
+
let(:chromedriver) { described_class }
|
6
5
|
|
7
6
|
it 'updates' do
|
8
7
|
chromedriver.update
|
@@ -64,21 +63,33 @@ describe Webdrivers::Chromedriver do
|
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
66
|
+
# Workaround for Google Chrome when using Jruby on Windows.
|
67
|
+
# @see https://github.com/titusfortner/webdrivers/issues/41
|
68
|
+
if RUBY_PLATFORM == 'java' && Selenium::WebDriver::Platform.windows?
|
69
|
+
context 'when using Jruby on Windows' do
|
70
|
+
it 'uses Jruby specific workaround to retrieve the Google Chrome version' do
|
71
|
+
chromedriver.remove
|
72
|
+
chromedriver.update
|
73
|
+
expect(chromedriver.current_version).not_to be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
67
78
|
context 'when offline' do
|
68
79
|
before { allow(chromedriver).to receive(:site_available?).and_return(false) }
|
69
80
|
|
70
81
|
it 'raises exception finding latest version' do
|
71
|
-
expect {chromedriver.latest_version}.to raise_error(StandardError,
|
82
|
+
expect { chromedriver.latest_version }.to raise_error(StandardError, 'Can not reach site')
|
72
83
|
end
|
73
84
|
|
74
85
|
it 'raises exception downloading' do
|
75
|
-
expect {chromedriver.download}.to raise_error(StandardError,
|
86
|
+
expect { chromedriver.download }.to raise_error(StandardError, 'Can not reach site')
|
76
87
|
end
|
77
88
|
end
|
78
89
|
|
79
90
|
it 'allows setting of install directory' do
|
80
91
|
begin
|
81
|
-
install_dir = File.expand_path(File.join(ENV['HOME'],
|
92
|
+
install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers2'))
|
82
93
|
Webdrivers.install_dir = install_dir
|
83
94
|
expect(chromedriver.install_dir).to eq install_dir
|
84
95
|
ensure
|
@@ -87,7 +98,7 @@ describe Webdrivers::Chromedriver do
|
|
87
98
|
end
|
88
99
|
|
89
100
|
it 'returns full location of binary' do
|
90
|
-
install_dir = File.expand_path(File.join(ENV['HOME'],
|
91
|
-
expect(chromedriver.binary).to match
|
101
|
+
install_dir = File.expand_path(File.join(ENV['HOME'], '.webdrivers'))
|
102
|
+
expect(chromedriver.binary).to match %r{#{install_dir}/chromedriver}
|
92
103
|
end
|
93
104
|
end
|