webdrivers 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e32a6aea7b04e41ab9bc26885196189a0a09abed
4
- data.tar.gz: '0493cc2da6b73a8a73ca389ef10e5d5e6748f551'
3
+ metadata.gz: f3e2cdd947c31a0a97e4679da3b987d008a240c1
4
+ data.tar.gz: 40cb38781d815e54008e917667ea22de595fc755
5
5
  SHA512:
6
- metadata.gz: 9d940d9c3ac8af8ae23d1ce6dda7a571a2841d98f854e8b393e6daa2f4c0c6e35728d54d297acb88a32de8085fbb2946ec6bb94a045a458e0d614a9f720bd9f6
7
- data.tar.gz: f86a5a08083cc2b955eead1a0c2a3b5b38a106f613b228ef46f2cacf85edde389f4a54fdefa30efe06a34bf438a933d0a125db7643dd8e031888396d34bc5249
6
+ metadata.gz: d73bd319ce124e487211a5150406c219e2572b2cf6eb9e836492c81e9d7270a7324d0d04b7e6a924499e8610ce87a5476c155df410635749916c916637d92e63
7
+ data.tar.gz: f83caf1cecc3f29b55c84f20edcc53115327d1e6197d52f5159cd8b3a0bf8eee42f7d897635a382bfff5fdf190669fd49a9c94ad6469c61a8055325beea2d7a0
@@ -1,3 +1,7 @@
1
+ ### 3.1.0 (2017-08-21)
2
+
3
+ * Implemented Logging functionality
4
+
1
5
  ### 3.0.1 (2017-08-18)
2
6
 
3
7
  * Create ~/.webdrivers directory if doesn't already exist
@@ -1,6 +1,13 @@
1
1
  require "webdrivers/selenium"
2
+ require "webdrivers/logger"
2
3
  require "webdrivers/common"
3
4
  require "webdrivers/chromedriver"
4
5
  require "webdrivers/geckodriver"
5
6
  require "webdrivers/iedriver"
6
7
  require "webdrivers/mswebdriver"
8
+
9
+ module Webdrivers
10
+ def self.logger
11
+ @logger ||= Webdrivers::Logger.new
12
+ end
13
+ end
@@ -7,10 +7,10 @@ module Webdrivers
7
7
  class << self
8
8
 
9
9
  def current
10
+ Webdrivers.logger.debug "Checking current version"
10
11
  return nil unless downloaded?
11
- puts binary
12
12
  string = %x(#{binary} --version)
13
- puts string
13
+ Webdrivers.logger.debug "Current version of #{binary} is #{string}"
14
14
  normalize string.match(/ChromeDriver (\d\.\d+)/)[1]
15
15
  end
16
16
 
@@ -29,16 +29,19 @@ module Webdrivers
29
29
  end
30
30
 
31
31
  def downloads
32
- raise StandardError, "Can not reach site" unless site_available?
32
+ raise StandardError, "Can not download from website" unless site_available?
33
+ Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
33
34
 
34
35
  @downloads ||= begin
35
36
  doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
36
37
  items = doc.css("Contents Key").collect(&:text)
37
38
  items.select! {|item| item.include?(platform)}
38
- items.each_with_object({}) do |item, hash|
39
+ ds = items.each_with_object({}) do |item, hash|
39
40
  key = normalize item[/^[^\/]+/]
40
41
  hash[key] = "#{base_url}/#{item}"
41
42
  end
43
+ Webdrivers.logger.debug "Versions now located on downloads site: #{ds.keys}"
44
+ ds
42
45
  end
43
46
  end
44
47
 
@@ -19,6 +19,7 @@ module Webdrivers
19
19
  end
20
20
 
21
21
  def remove
22
+ Webdrivers.logger.debug "Deleting #{binary}"
22
23
  FileUtils.rm_f binary
23
24
  end
24
25
 
@@ -35,12 +36,21 @@ module Webdrivers
35
36
  end
36
37
  end
37
38
  raise "Could not download #{url}" unless File.exists? filename
39
+ Webdrivers.logger.debug "Successfully downloaded #{filename}"
38
40
  dcf = decompress_file(filename)
39
- FileUtils.rm_f filename if dcf
40
- extract_file(dcf) if respond_to? :extract_file
41
+ Webdrivers.logger.debug "Decompression Complete"
42
+ if dcf
43
+ Webdrivers.logger.debug "Deleting #{filename}"
44
+ FileUtils.rm_f filename
45
+ end
46
+ if respond_to? :extract_file
47
+ Webdrivers.logger.debug "Extracting #{dcf}"
48
+ extract_file(dcf)
49
+ end
41
50
  end
42
- raise "Could not unzip #{filename} to get #{binary}" unless File.exists?(binary)
51
+ raise "Could not decompress #{filename} to get #{binary}" unless File.exists?(binary)
43
52
  FileUtils.chmod "ugo+rx", binary
53
+ Webdrivers.logger.debug "Completed download and processing of #{binary}"
44
54
  binary
45
55
  end
46
56
 
@@ -51,17 +61,22 @@ module Webdrivers
51
61
  end
52
62
 
53
63
  def downloaded?
54
- File.exist? binary
64
+ result = File.exist? binary
65
+ Webdrivers.logger.debug "File is already downloaded: #{result}"
66
+ result
55
67
  end
56
68
 
57
69
  def binary
58
70
  File.join install_dir, file_name
59
71
  end
60
72
 
73
+ # TODO - specify what gets rescued
61
74
  def site_available?
62
- true if open(base_url)
75
+ open(base_url)
76
+ Webdrivers.logger.debug "Found Site: #{base_url}"
77
+ true
63
78
  rescue
64
- Webdrivers.logger.info "Site Not Available: #{base_url}"
79
+ Webdrivers.logger.debug "Site Not Available: #{base_url}"
65
80
  false
66
81
  end
67
82
 
@@ -80,12 +95,18 @@ module Webdrivers
80
95
  def decompress_file(filename)
81
96
  case filename
82
97
  when /tar\.gz$/
98
+ Webdrivers.logger.debug "Decompressing tar"
83
99
  untargz_file(filename)
84
100
  when /tar\.bz2$/
101
+ Webdrivers.logger.debug "Decompressing bz2"
85
102
  system "tar xjf #{filename}"
86
103
  filename.gsub('.tar.bz2', '')
87
104
  when /\.zip$/
105
+ Webdrivers.logger.debug "Decompressing zip"
88
106
  unzip_file(filename)
107
+ else
108
+ Webdrivers.logger.debug "No Decompression needed"
109
+ nil
89
110
  end
90
111
  end
91
112
 
@@ -6,29 +6,34 @@ module Webdrivers
6
6
  class << self
7
7
 
8
8
  def current
9
+ Webdrivers.logger.debug "Checking current version"
9
10
  return nil unless downloaded?
10
- puts binary
11
11
  string = %x(#{binary} --version)
12
- puts string
12
+ Webdrivers.logger.debug "Current version of #{binary} is #{string}"
13
13
  normalize string.match(/geckodriver (\d+\.\d+\.\d+)/)[1]
14
14
  end
15
15
 
16
16
  private
17
17
 
18
18
  def normalize(string)
19
- string.match(/(\d+)\.(\d+\.\d+)/).to_a.map {|v| v.tr('.', '') }[1..-1].join('.').to_f
19
+ string.match(/(\d+)\.(\d+\.\d+)/).to_a.map {|v| v.tr('.', '')}[1..-1].join('.').to_f
20
20
  end
21
21
 
22
22
  def downloads
23
23
  raise StandardError, "Can not reach site" unless site_available?
24
-
25
- doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
26
- items = doc.css(".release-downloads a").collect {|item| item["href"]}
27
- items.reject! {|item| item.include?('archive')}
28
- items.select! {|item| item.include?(platform)}
29
- items.each_with_object({}) do |item, hash|
30
- key = normalize item[/v(\d+\.\d+\.\d+)/, 1]
31
- hash[key] = "https://github.com#{item}"
24
+ Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
25
+
26
+ @downloads ||= begin
27
+ doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
28
+ items = doc.css(".release-downloads a").collect {|item| item["href"]}
29
+ items.reject! {|item| item.include?('archive')}
30
+ items.select! {|item| item.include?(platform)}
31
+ ds = items.each_with_object({}) do |item, hash|
32
+ key = normalize item[/v(\d+\.\d+\.\d+)/, 1]
33
+ hash[key] = "https://github.com#{item}"
34
+ end
35
+ Webdrivers.logger.debug "Versions now located on downloads site: #{ds.keys}"
36
+ ds
32
37
  end
33
38
  end
34
39
 
@@ -6,10 +6,10 @@ module Webdrivers
6
6
  class << self
7
7
 
8
8
  def current
9
+ Webdrivers.logger.debug "Checking current version"
9
10
  return nil unless downloaded?
10
- puts binary
11
11
  string = %x(#{binary} --version)
12
- puts string
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
15
15
 
@@ -29,15 +29,18 @@ module Webdrivers
29
29
 
30
30
  def downloads
31
31
  raise StandardError, "Can not reach site" unless site_available?
32
+ Webdrivers.logger.debug "Versions previously located on downloads site: #{@downloads.keys}" if @downloads
32
33
 
33
34
  @downloads ||= begin
34
35
  doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
35
36
  items = doc.css("Key").collect(&:text)
36
37
  items.select! { |item| item.include?('IEDriverServer_Win32') }
37
- items.each_with_object({}) do |item, hash|
38
+ ds = items.each_with_object({}) do |item, hash|
38
39
  key = normalize item[/^[^\/]+/]
39
40
  hash[key] = "#{base_url}#{item}"
40
41
  end
42
+ Webdrivers.logger.debug "Versions now located on downloads site: #{ds.keys}"
43
+ ds
41
44
  end
42
45
  end
43
46
 
@@ -0,0 +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
@@ -6,7 +6,9 @@ module Webdrivers
6
6
  class << self
7
7
 
8
8
  def current
9
+ Webdrivers.logger.debug "Checking current version"
9
10
  version = %x(ver)
11
+ Webdrivers.logger.debug "Current version of Windows Build is #{version}"
10
12
  version[/\d+\.\d+\.\d+/][/[^\.]\d+$/]
11
13
  end
12
14
 
@@ -17,7 +19,7 @@ module Webdrivers
17
19
  private
18
20
 
19
21
  def normalize(string)
20
- string.match(/(\d+)\.(\d+\.\d+)/).to_a.map {|v| v.tr('.', '') }[1..-1].join('.').to_f
22
+ string.match(/(\d+)\.(\d+\.\d+)/).to_a.map {|v| v.tr('.', '')}[1..-1].join('.').to_f
21
23
  end
22
24
 
23
25
  def file_name
@@ -27,10 +29,22 @@ module Webdrivers
27
29
  def download_url(_version = nil)
28
30
  raise StandardError, "Can not reach site" unless site_available?
29
31
 
30
- if current.to_i >= 16257
31
- 'https://download.microsoft.com/download/1/4/1/14156DA0-D40F-460A-B14D-1B264CA081A5/MicrosoftWebDriver.exe'
32
+ case current.to_i
33
+ when 10240
34
+ Webdrivers.logger.debug "Attempting to Download Build for 10240"
35
+ "https://download.microsoft.com/download/8/D/0/8D0D08CF-790D-4586-B726-C6469A9ED49C/MicrosoftWebDriver.msi"
36
+ when 10586
37
+ Webdrivers.logger.debug "Attempting to Download Build for 10586"
38
+ "https://download.microsoft.com/download/C/0/7/C07EBF21-5305-4EC8-83B1-A6FCC8F93F45/MicrosoftWebDriver.msi"
39
+ when 14393
40
+ Webdrivers.logger.debug "Attempting to Download Build for 14393"
41
+ "https://download.microsoft.com/download/3/2/D/32D3E464-F2EF-490F-841B-05D53C848D15/MicrosoftWebDriver.exe"
42
+ when 15063
43
+ Webdrivers.logger.debug "Attempting to Download Build for 15063"
44
+ "https://download.microsoft.com/download/3/4/2/342316D7-EBE0-4F10-ABA2-AE8E0CDF36DD/MicrosoftWebDriver.exe"
32
45
  else
33
- 'https://download.microsoft.com/download/3/2/D/32D3E464-F2EF-490F-841B-05D53C848D15/MicrosoftWebDriver.exe'
46
+ Webdrivers.logger.debug "Attempting to Download Latest Insider's Version"
47
+ "https://download.microsoft.com/download/1/4/1/14156DA0-D40F-460A-B14D-1B264CA081A5/MicrosoftWebDriver.exe"
34
48
  end
35
49
  end
36
50
 
@@ -34,11 +34,11 @@ describe Webdrivers::Chromedriver do
34
34
  before { allow(chromedriver).to receive(:site_available?).and_return(false) }
35
35
 
36
36
  it 'raises exception finding latest version' do
37
- expect {chromedriver.latest}.to raise_error(StandardError, "Can not reach site")
37
+ expect {chromedriver.latest}.to raise_error(StandardError, "Can not download from website")
38
38
  end
39
39
 
40
40
  it 'raises exception downloading' do
41
- expect {chromedriver.download}.to raise_error(StandardError, "Can not reach site")
41
+ expect {chromedriver.download}.to raise_error(StandardError, "Can not download from website")
42
42
  end
43
43
  end
44
44
 
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "webdrivers"
6
- s.version = "3.0.1"
6
+ s.version = "3.1.0"
7
7
  s.authors = ["Titus Fortner"]
8
8
  s.email = ["titusfortner@gmail.com"]
9
9
  s.homepage = "https://github.com/titusfortner/webdrivers"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdrivers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-19 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -100,6 +100,7 @@ files:
100
100
  - lib/webdrivers/common.rb
101
101
  - lib/webdrivers/geckodriver.rb
102
102
  - lib/webdrivers/iedriver.rb
103
+ - lib/webdrivers/logger.rb
103
104
  - lib/webdrivers/mswebdriver.rb
104
105
  - lib/webdrivers/selenium.rb
105
106
  - spec/chromedriver_spec.rb
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  version: '0'
129
130
  requirements: []
130
131
  rubyforge_project:
131
- rubygems_version: 2.5.2
132
+ rubygems_version: 2.6.11
132
133
  signing_key:
133
134
  specification_version: 4
134
135
  summary: Easy download and use of browser drivers.