webdrivers 3.0.0.beta1 → 3.0.0.beta2
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/webdrivers/chromedriver.rb +2 -104
- data/lib/webdrivers/common.rb +114 -0
- data/lib/webdrivers/geckodriver.rb +46 -0
- data/lib/webdrivers/selenium.rb +6 -0
- data/lib/webdrivers.rb +2 -0
- data/spec/chromedriver_spec.rb +1 -0
- data/spec/geckodriver_spec.rb +40 -0
- data/webdrivers.gemspec +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617d5fa4e06abcdbf66ad776593c1e409303f4a7
|
4
|
+
data.tar.gz: f92d3f5b6e78c7f4de29b3cee38e17dfb1e7bb5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219decd97dc9bf88005d95605133a77b325841e0eb933fd6c47527d4de5ac0be2ed47bb2be57e8c8b15fe6a52ab145eeffaedd8ad656e2ab77f2011e833f817f
|
7
|
+
data.tar.gz: 892b73d4f0d90c26f5b39bbb4afe58901282817ac6a4c49a1397ac30e7d0084c48626c3f7bc99d9e233a0df1a766cef267e8bc88684255785d65833de0388fbb
|
data/CHANGELOG.md
CHANGED
@@ -2,19 +2,10 @@ require 'nokogiri'
|
|
2
2
|
require 'open-uri'
|
3
3
|
require 'zip'
|
4
4
|
|
5
|
-
|
6
5
|
module Webdrivers
|
7
|
-
class Chromedriver
|
6
|
+
class Chromedriver < Common
|
8
7
|
class << self
|
9
8
|
|
10
|
-
def update
|
11
|
-
unless site_available?
|
12
|
-
return current.nil? ? nil : binary
|
13
|
-
end
|
14
|
-
return binary if current == latest
|
15
|
-
remove && download
|
16
|
-
end
|
17
|
-
|
18
9
|
def current
|
19
10
|
return nil unless downloaded?
|
20
11
|
puts binary
|
@@ -23,34 +14,6 @@ module Webdrivers
|
|
23
14
|
normalize string.match(/ChromeDriver (\d\.\d+)/)[1]
|
24
15
|
end
|
25
16
|
|
26
|
-
def latest
|
27
|
-
downloads.keys.sort.last
|
28
|
-
end
|
29
|
-
|
30
|
-
def remove
|
31
|
-
FileUtils.rm_f binary
|
32
|
-
end
|
33
|
-
|
34
|
-
def download(version = nil)
|
35
|
-
url = downloads[version || latest]
|
36
|
-
filename = File.basename url
|
37
|
-
|
38
|
-
Dir.chdir install_dir do
|
39
|
-
FileUtils.rm_f filename
|
40
|
-
File.open(filename, "wb") do |saved_file|
|
41
|
-
URI.parse(url).open("rb") do |read_file|
|
42
|
-
saved_file.write(read_file.read)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
raise "Could not download #{url}" unless File.exists? filename
|
46
|
-
dcf = decompress_file(filename)
|
47
|
-
extract_file(dcf) if respond_to? :extract_file
|
48
|
-
end
|
49
|
-
raise "Could not unzip #{filename} to get #{binary}" unless File.exists?(binary)
|
50
|
-
FileUtils.chmod "ugo+rx", binary
|
51
|
-
binary
|
52
|
-
end
|
53
|
-
|
54
17
|
private
|
55
18
|
|
56
19
|
def normalize(string)
|
@@ -61,82 +24,17 @@ module Webdrivers
|
|
61
24
|
'chromedriver'
|
62
25
|
end
|
63
26
|
|
64
|
-
def downloaded?
|
65
|
-
File.exist? binary
|
66
|
-
end
|
67
|
-
|
68
|
-
def binary
|
69
|
-
File.join install_dir, file_name
|
70
|
-
end
|
71
|
-
|
72
27
|
def base_url
|
73
28
|
'http://chromedriver.storage.googleapis.com'
|
74
29
|
end
|
75
30
|
|
76
|
-
def site_available?
|
77
|
-
true if open(base_url)
|
78
|
-
rescue
|
79
|
-
false
|
80
|
-
end
|
81
|
-
|
82
|
-
def platform
|
83
|
-
cfg = RbConfig::CONFIG
|
84
|
-
case cfg['host_os']
|
85
|
-
when /linux/
|
86
|
-
cfg['host_cpu'] =~ /x86_64|amd64/ ? "linux64" : "linux32"
|
87
|
-
when /darwin/
|
88
|
-
"mac"
|
89
|
-
else
|
90
|
-
"win"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def decompress_file(filename)
|
95
|
-
case filename
|
96
|
-
when /tar\.gz$/
|
97
|
-
untargz_file(filename)
|
98
|
-
when /tar\.bz2$/
|
99
|
-
system "tar xjf #{filename}"
|
100
|
-
filename.gsub('.tar.bz2', '')
|
101
|
-
when /\.zip$/
|
102
|
-
unzip_file(filename)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def untargz_file(filename)
|
107
|
-
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(filename))
|
108
|
-
tar_extract.rewind
|
109
|
-
|
110
|
-
ucf = File.open(file_name, "w+")
|
111
|
-
tar_extract.each {|entry| ucf << entry.read}
|
112
|
-
ucf.close
|
113
|
-
File.basename ucf
|
114
|
-
end
|
115
|
-
|
116
|
-
def unzip_file(filename)
|
117
|
-
Zip::File.open("#{Dir.pwd}/#{filename}") do |zip_file|
|
118
|
-
zip_file.each do |f|
|
119
|
-
@top_path ||= f.name
|
120
|
-
f_path = File.join(Dir.pwd, f.name)
|
121
|
-
FileUtils.rm_rf(f_path) if File.exist?(f_path)
|
122
|
-
FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
|
123
|
-
zip_file.extract(f, f_path)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
@top_path
|
127
|
-
end
|
128
|
-
|
129
|
-
def install_dir
|
130
|
-
File.expand_path(File.join(ENV['HOME'], ".webdrivers")).tap {|dir| FileUtils.mkdir_p dir}
|
131
|
-
end
|
132
|
-
|
133
31
|
def downloads
|
134
32
|
raise StandardError, "Can not reach site" unless site_available?
|
135
33
|
|
136
34
|
@downloads ||= begin
|
137
35
|
doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
|
138
36
|
items = doc.css("Contents Key").collect(&:text)
|
139
|
-
items.select! {|item| item.include?(
|
37
|
+
items.select! {|item| item.include?(platform)}
|
140
38
|
items.each_with_object({}) do |item, hash|
|
141
39
|
key = normalize item[/^[^\/]+/]
|
142
40
|
hash[key] = "#{base_url}/#{item}"
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rubygems/package'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'zip'
|
5
|
+
|
6
|
+
module Webdrivers
|
7
|
+
class Common
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def update
|
11
|
+
unless site_available?
|
12
|
+
return current.nil? ? nil : binary
|
13
|
+
end
|
14
|
+
return binary if current == latest
|
15
|
+
remove && download
|
16
|
+
end
|
17
|
+
|
18
|
+
def latest
|
19
|
+
downloads.keys.sort.last
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove
|
23
|
+
FileUtils.rm_f binary
|
24
|
+
end
|
25
|
+
|
26
|
+
def download(version = nil)
|
27
|
+
url = downloads[version || latest]
|
28
|
+
filename = File.basename url
|
29
|
+
|
30
|
+
Dir.chdir install_dir do
|
31
|
+
FileUtils.rm_f filename
|
32
|
+
File.open(filename, "wb") do |saved_file|
|
33
|
+
URI.parse(url).open("rb") do |read_file|
|
34
|
+
saved_file.write(read_file.read)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
raise "Could not download #{url}" unless File.exists? filename
|
38
|
+
dcf = decompress_file(filename)
|
39
|
+
extract_file(dcf) if respond_to? :extract_file
|
40
|
+
end
|
41
|
+
raise "Could not unzip #{filename} to get #{binary}" unless File.exists?(binary)
|
42
|
+
FileUtils.chmod "ugo+rx", binary
|
43
|
+
binary
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def downloaded?
|
49
|
+
File.exist? binary
|
50
|
+
end
|
51
|
+
|
52
|
+
def binary
|
53
|
+
File.join install_dir, file_name
|
54
|
+
end
|
55
|
+
|
56
|
+
def site_available?
|
57
|
+
true if open(base_url)
|
58
|
+
rescue
|
59
|
+
false
|
60
|
+
end
|
61
|
+
|
62
|
+
def platform
|
63
|
+
cfg = RbConfig::CONFIG
|
64
|
+
case cfg['host_os']
|
65
|
+
when /linux/
|
66
|
+
cfg['host_cpu'] =~ /x86_64|amd64/ ? "linux64" : "linux32"
|
67
|
+
when /darwin/
|
68
|
+
"mac"
|
69
|
+
else
|
70
|
+
"win"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def decompress_file(filename)
|
75
|
+
case filename
|
76
|
+
when /tar\.gz$/
|
77
|
+
untargz_file(filename)
|
78
|
+
when /tar\.bz2$/
|
79
|
+
system "tar xjf #{filename}"
|
80
|
+
filename.gsub('.tar.bz2', '')
|
81
|
+
when /\.zip$/
|
82
|
+
unzip_file(filename)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def untargz_file(filename)
|
87
|
+
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(filename))
|
88
|
+
tar_extract.rewind
|
89
|
+
|
90
|
+
ucf = File.open(file_name, "w+")
|
91
|
+
tar_extract.each {|entry| ucf << entry.read}
|
92
|
+
ucf.close
|
93
|
+
File.basename ucf
|
94
|
+
end
|
95
|
+
|
96
|
+
def unzip_file(filename)
|
97
|
+
Zip::File.open("#{Dir.pwd}/#{filename}") do |zip_file|
|
98
|
+
zip_file.each do |f|
|
99
|
+
@top_path ||= f.name
|
100
|
+
f_path = File.join(Dir.pwd, f.name)
|
101
|
+
FileUtils.rm_rf(f_path) if File.exist?(f_path)
|
102
|
+
FileUtils.mkdir_p(File.dirname(f_path)) unless File.exist?(File.dirname(f_path))
|
103
|
+
zip_file.extract(f, f_path)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
@top_path
|
107
|
+
end
|
108
|
+
|
109
|
+
def install_dir
|
110
|
+
File.expand_path(File.join(ENV['HOME'], ".webdrivers")).tap {|dir| FileUtils.mkdir_p dir}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'zip'
|
4
|
+
|
5
|
+
module Webdrivers
|
6
|
+
class Geckodriver < Common
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def current
|
10
|
+
return nil unless downloaded?
|
11
|
+
puts binary
|
12
|
+
string = %x(#{binary} --version)
|
13
|
+
puts string
|
14
|
+
normalize string.match(/geckodriver (\d+\.\d+\.\d+)/)[1]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def normalize(string)
|
20
|
+
string.match(/(\d+)\.(\d+\.\d+)/).to_a.map {|v| v.tr('.', '') }[1..-1].join('.').to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
def downloads
|
24
|
+
raise StandardError, "Can not reach site" unless site_available?
|
25
|
+
|
26
|
+
doc = Nokogiri::XML.parse(OpenURI.open_uri(base_url))
|
27
|
+
items = doc.css(".release-downloads a").collect {|item| item["href"]}
|
28
|
+
items.reject! {|item| item.include?('archive')}
|
29
|
+
items.select! {|item| item.include?(platform)}
|
30
|
+
items.each_with_object({}) do |item, hash|
|
31
|
+
key = normalize item[/v(\d+\.\d+\.\d+)/, 1]
|
32
|
+
hash[key] = "https://github.com#{item}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_name
|
37
|
+
'geckodriver'
|
38
|
+
end
|
39
|
+
|
40
|
+
def base_url
|
41
|
+
'https://github.com/mozilla/geckodriver/releases'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/webdrivers/selenium.rb
CHANGED
data/lib/webdrivers.rb
CHANGED
data/spec/chromedriver_spec.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Webdrivers::Geckodriver do
|
4
|
+
|
5
|
+
let(:geckodriver) { Webdrivers::Geckodriver }
|
6
|
+
|
7
|
+
it 'finds latest version' do
|
8
|
+
expect(geckodriver.latest).to be > 0.17
|
9
|
+
expect(geckodriver.latest).to be < 0.2
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'downloads latest version by default' do
|
13
|
+
geckodriver.download
|
14
|
+
expect(geckodriver.current).to eq geckodriver.latest
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'downloads specified version' do
|
18
|
+
geckodriver.remove
|
19
|
+
geckodriver.download(0.17)
|
20
|
+
expect(geckodriver.current).to eq 0.17
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'removes geckodriver' do
|
24
|
+
geckodriver.remove
|
25
|
+
expect(geckodriver.current).to be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when offline' do
|
29
|
+
before { allow(geckodriver).to receive(:site_available?).and_return(false) }
|
30
|
+
|
31
|
+
it 'raises exception finding latest version' do
|
32
|
+
expect {geckodriver.latest}.to raise_error(StandardError, "Can not reach site")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises exception downloading' do
|
36
|
+
expect {geckodriver.download}.to raise_error(StandardError, "Can not reach site")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/webdrivers.gemspec
CHANGED
@@ -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.0.
|
6
|
+
s.version = "3.0.0.beta2"
|
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.0.
|
4
|
+
version: 3.0.0.beta2
|
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-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -97,8 +97,11 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- lib/webdrivers.rb
|
99
99
|
- lib/webdrivers/chromedriver.rb
|
100
|
+
- lib/webdrivers/common.rb
|
101
|
+
- lib/webdrivers/geckodriver.rb
|
100
102
|
- lib/webdrivers/selenium.rb
|
101
103
|
- spec/chromedriver_spec.rb
|
104
|
+
- spec/geckodriver_spec.rb
|
102
105
|
- spec/spec_helper.rb
|
103
106
|
- webdrivers.gemspec
|
104
107
|
homepage: https://github.com/titusfortner/webdrivers
|
@@ -127,4 +130,5 @@ specification_version: 4
|
|
127
130
|
summary: Easy download and use of browser drivers.
|
128
131
|
test_files:
|
129
132
|
- spec/chromedriver_spec.rb
|
133
|
+
- spec/geckodriver_spec.rb
|
130
134
|
- spec/spec_helper.rb
|