chauffeur 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.overcommit.yml +33 -0
  4. data/.rubocop.yml +13 -0
  5. data/Gemfile +8 -0
  6. data/Readme.md +94 -0
  7. data/bin/chauffeur +52 -0
  8. data/chauffeur.gemspec +24 -0
  9. data/lib/chauffeur/config.yml +30 -0
  10. data/lib/chauffeur/downloaders/chromedriver_downloader.rb +43 -0
  11. data/lib/chauffeur/downloaders/edgedriver_downloader.rb +44 -0
  12. data/lib/chauffeur/downloaders/firefoxdriver_downloader.rb +42 -0
  13. data/lib/chauffeur/downloaders/iedriver_downloader.rb +44 -0
  14. data/lib/chauffeur/driver_downloader.rb +177 -0
  15. data/lib/chauffeur/help.txt +60 -0
  16. data/lib/chauffeur/path_expander.rb +90 -0
  17. data/lib/chauffeur/requires.rb +15 -0
  18. data/lib/chauffeur/setup.rb +36 -0
  19. data/lib/chauffeur/unknown_platform_error.rb +10 -0
  20. data/lib/chauffeur/unknown_version_error.rb +7 -0
  21. data/lib/chauffeur.rb +83 -0
  22. data/lib/pry_playground.rb +4 -0
  23. data/spec/chromedriver_downloader_spec.rb +82 -0
  24. data/spec/chromedriver_downloader_specs/chromedriver_downloader_overridden_methods_spec.rb +79 -0
  25. data/spec/chromedriver_downloader_specs/chromedriver_downloader_simple_spec.rb +22 -0
  26. data/spec/driver_downloader_specs/driver_downloader_error_spec.rb +26 -0
  27. data/spec/driver_versions_spec.rb +29 -0
  28. data/spec/edgedriver_downloader_specs/edgedriver_downloader_overridden_methods.rb +58 -0
  29. data/spec/edgedriver_downloader_specs/edgedriver_downloader_simple_spec.rb +22 -0
  30. data/spec/firefoxdriver_downloader_specs/firefoxdriver_downloader_overridden_methods_spec.rb +86 -0
  31. data/spec/firefoxdriver_downloader_specs/firefoxdriver_downloader_simple_spec.rb +22 -0
  32. data/spec/format_for_platform_spec.rb +59 -0
  33. data/spec/helpers/spec_helper.rb +4 -0
  34. data/spec/iedriver_downloader_spec.rb +17 -0
  35. data/spec/iedriver_downloader_specs/iedriver_downloader_overridden_methods_spec.rb +65 -0
  36. data/spec/iedriver_downloader_specs/iedriver_downloader_simple_spec.rb +22 -0
  37. data/spec/path_expansion_spec.rb +43 -0
  38. data/spec/setup_spec.rb +48 -0
  39. metadata +165 -0
@@ -0,0 +1,60 @@
1
+ Chauffeur is there to help you manage your browser drivers for web automation.
2
+
3
+ Usage:
4
+ chauffeur <command> <arg1> <arg2>
5
+
6
+ commands:
7
+ driver_versions: takes no arguments and prints the installed versions for each browser.
8
+
9
+ cmd > chauffeur driver_versions
10
+ {"chromedriver"=>
11
+ {"linux32"=>"nil", "linux64"=>"nil", "mac32"=>"nil", "win32"=>"nil"},
12
+ "geckodriver"=>
13
+ {"linux32"=>"nil",
14
+ "linux64"=>"nil",
15
+ "macos"=>"nil",
16
+ "win32"=>"nil",
17
+ "win64"=>"nil"},
18
+ "iedriver"=>{"Win32"=>"nil", "x64"=>"nil"},
19
+ "microsoft_webdriver"=>{}}
20
+
21
+ upgrade_driver: takes the browser name and system platform as arguments and installs the driver.
22
+ browser: chrome, firefox, ie, edge
23
+ platform: chrome: [linux32, linux64, mac32, win32]
24
+ firefox: [linux32, linux64, macos, win32, win64]
25
+ ie: [Win32, x64]
26
+ edge: build version number
27
+
28
+ cmd > chauffeur upgrade_driver ie Win32
29
+ installing 'http://selenium-release.storage.googleapis.com/3.8/IEDriverServer_Win32_3.8.0.zip' into 'C:/casnc/repos/chauffeur/drivers/iedriver/Win32/'
30
+
31
+ upgrade_driver_all_platforms: takes the browser name and installs most current driver for each platform
32
+ browser: chrome, firefox, ie, edge
33
+
34
+ cmd > chauffeur upgrade_driver_all_platforms chrome
35
+ installing 'http://chromedriver.storage.googleapis.com/2.33/chromedriver_linux32.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/linux32/'
36
+ installing 'http://chromedriver.storage.googleapis.com/2.34/chromedriver_linux64.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/linux64/'
37
+ installing 'http://chromedriver.storage.googleapis.com/2.22/chromedriver_mac32.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/mac32/'
38
+ installing 'http://chromedriver.storage.googleapis.com/2.34/chromedriver_win32.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/win32/'
39
+
40
+ install_driver: takes browser, platform, and version and installs that driver.
41
+ browser: chrome, firefox, ie, edge
42
+ platform: chrome: [linux32, linux64, mac32, win32]
43
+ firefox: [linux32, linux64, macos, win32, win64]
44
+ ie: [Win32, x64]
45
+ edge: build version number
46
+ version: must match exactly the download version
47
+
48
+ cmd > chauffeur install_driver firefox linux64 0.18.0
49
+ installing 'https://github.com/mozilla/geckodriver/releases//download/v0.18.0/geckodriver-v0.18.0-linux64.tar.gz' into 'C:/casnc/repos/chauffeur/drivers/geckodriver/linux64/'
50
+
51
+ install_driver_all_platforms: takes browser name and version number and installs that version for all platforms.
52
+ browser: chrome, firefox, ie, edge
53
+ version: must match exactly the download version
54
+
55
+ cmd > chauffeur install_driver_all_platforms chrome 2.22
56
+ installing 'http://chromedriver.storage.googleapis.com/2.22/chromedriver_linux32.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/linux32/'
57
+ installing 'http://chromedriver.storage.googleapis.com/2.22/chromedriver_linux64.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/linux64/'
58
+ installing 'http://chromedriver.storage.googleapis.com/2.22/chromedriver_mac32.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/mac32/'
59
+ installing 'http://chromedriver.storage.googleapis.com/2.22/chromedriver_win32.zip' into 'C:/casnc/repos/chauffeur/drivers/chromedriver/win32/'
60
+
@@ -0,0 +1,90 @@
1
+ class Chauffeur
2
+ # Adds locations of drivers for the current platform to the beginning of the path
3
+ module PathExpander
4
+ def self.paths_to_add
5
+ all_paths = [path_to_chromedriver, path_to_geckodriver, path_to_iedriver, path_to_edgedriver].compact
6
+ # paths = all_paths.compact.join(Gem.path_separator) + Gem.path_separator
7
+ all_paths.map { |p| format_for_platform(p) }
8
+ end
9
+
10
+ def self.path_to_chromedriver
11
+ driver_path = "#{Dir.pwd}/drivers/chromedriver/#{current_chromedriver_platform}"
12
+ make_driver_executable("#{driver_path}/chromedriver")
13
+ driver_path
14
+ end
15
+
16
+ def self.current_chromedriver_platform
17
+ case RbConfig::CONFIG['host_os']
18
+ when 'mingw32'
19
+ 'win32'
20
+ when 'mac'
21
+ 'mac32'
22
+ else
23
+ RbConfig::CONFIG['host_cpu'].eql?('x86_64') ? 'linux64' : 'linux32'
24
+ end
25
+ end
26
+
27
+ def self.path_to_geckodriver
28
+ driver_path = "#{Dir.pwd}/drivers/geckodriver/#{current_geckodriver_platform}"
29
+ make_driver_executable("#{driver_path}/geckodriver")
30
+ driver_path
31
+ end
32
+
33
+ def self.current_geckodriver_platform
34
+ case RbConfig::CONFIG['host_os']
35
+ when 'mingw32'
36
+ ENV['architecture'].eql?('64') ? 'win64' : 'win32'
37
+ when 'mac'
38
+ 'macos'
39
+ else
40
+ RbConfig::CONFIG['host_cpu'].eql?('x86_64') ? 'linux64' : 'linux32'
41
+ end
42
+ end
43
+
44
+ def self.path_to_iedriver
45
+ windows? ? "#{Dir.pwd}/drivers/iedriver/#{current_iedriver_platform}" : nil
46
+ end
47
+
48
+ def self.current_iedriver_platform
49
+ ENV['architecture'].eql?('64') ? 'x64' : 'Win32'
50
+ end
51
+
52
+ def self.path_to_edgedriver
53
+ windows_10? ? "#{Dir.pwd}/drivers/microsoft_webdriver/#{windows_build_number}" : nil
54
+ end
55
+
56
+ # Takes a file path and puts the appropriate slashes for the operating
57
+ # system.
58
+ def self.format_for_platform(path, platform = nil)
59
+ host_os = platform || RbConfig::CONFIG['host_os']
60
+ if host_os.eql?('mingw32')
61
+ path.tr('/', '\\')
62
+ elsif host_os.include?('linux') || host_os.include?('mac')
63
+ path.tr('\\', '/')
64
+ else
65
+ raise UnknownPlatformError, platform
66
+ end
67
+ end
68
+
69
+ def self.windows?
70
+ RbConfig::CONFIG['host_os'].eql?('mingw32')
71
+ end
72
+
73
+ def self.windows_10?
74
+ windows? && windows_version.eql?('Version 10')
75
+ end
76
+
77
+ def self.windows_version
78
+ `ver`.match(/(Version \d+)/)[1]
79
+ end
80
+
81
+ def self.windows_build_number
82
+ `ver`.match(/\.(\d+)\]/)[1]
83
+ end
84
+
85
+ def self.make_driver_executable(file_path)
86
+ return if windows?
87
+ File.chmod(0o0777, file_path) if File.exist?(file_path)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,15 @@
1
+ require 'archive/zip'
2
+ require 'httparty'
3
+ require 'nokogiri'
4
+ require 'pry'
5
+ require 'yaml'
6
+
7
+ require_relative './setup'
8
+ require_relative './path_expander'
9
+ require_relative './unknown_platform_error'
10
+ require_relative './unknown_version_error'
11
+ require_relative './driver_downloader'
12
+ require_relative './downloaders/chromedriver_downloader'
13
+ require_relative './downloaders/firefoxdriver_downloader'
14
+ require_relative './downloaders/iedriver_downloader'
15
+ require_relative './downloaders/edgedriver_downloader'
@@ -0,0 +1,36 @@
1
+ class Chauffeur
2
+ # Initializes the folders for storing the drivers and creates config.yml file
3
+ # that stores the versions of installed drivers.
4
+ module Setup
5
+ # Initializes the folders for storing the drivers and creates config.yml file
6
+ # that stores the versions of installed drivers.
7
+ def self.create_folders_and_config
8
+ config_file_path = "#{File.dirname(__FILE__)}/config.yml"
9
+ data = File.open(config_file_path) { |f| YAML.safe_load(f) }
10
+ create_folders(data['folders'])
11
+ create_config(data)
12
+ end
13
+
14
+ # Initializes the folders for storing the drivers
15
+ #
16
+ # folders: Array(strings) - each is a folder to be created relative
17
+ # to the current working directory
18
+ def self.create_folders(folders)
19
+ folders.each do |folder|
20
+ full_path = "#{Dir.pwd}/#{folder}"
21
+ FileUtils.mkdir_p(full_path) unless File.exist?(full_path)
22
+ end
23
+ end
24
+
25
+ # Initializes the config.yml file that is used for storing the installed
26
+ # versions of the specific drivers
27
+ #
28
+ # data: hash
29
+ def self.create_config(data)
30
+ return if File.exist?("#{Dir.pwd}/drivers/config.yml")
31
+ File.open("#{Dir.pwd}/drivers/config.yml", 'w') do |file|
32
+ file.puts(data.to_yaml)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ # This class gets thrown when the platform is something other than:
2
+ # mingw32
3
+ # mac
4
+ # linux
5
+ class UnknownPlatformError < StandardError
6
+ def initialize(platform, msg = nil)
7
+ msg ||= "Unknown OS: #{platform}"
8
+ super(msg)
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ # This class gets thrown when the platform is something other than valid driver versions.
2
+ class UnknownVersionError < StandardError
3
+ def initialize(version, msg = nil)
4
+ msg ||= "Unknown Version: #{version}"
5
+ super(msg)
6
+ end
7
+ end
data/lib/chauffeur.rb ADDED
@@ -0,0 +1,83 @@
1
+ # Chauffeur adds WebDriver executables to the path
2
+ # Drivers must be in path '{working_directory}/features/support/drivers/{os}/'
3
+ # otherwise, the path must be passed in.
4
+ class Chauffeur
5
+ require_relative './chauffeur/requires'
6
+
7
+ class << self
8
+ # Initialize method must be run before anything else will work.
9
+ def initialize_chauffeur
10
+ Setup.create_folders_and_config
11
+ end
12
+
13
+ # Upgrades path to include the folder containing web drivers.
14
+ def add_drivers_to_path
15
+ path = ENV['PATH']
16
+ new_paths = PathExpander.paths_to_add
17
+ new_paths.reject! { |p| path.include?(p) }
18
+ ENV['PATH'] = "#{new_paths.join(Gem.path_separator)}#{Gem.path_separator}#{path}"
19
+ end
20
+
21
+ # Returns a hash of the currently installed drivers.
22
+ def driver_versions
23
+ config_file_path = "#{Dir.pwd}/drivers/config.yml"
24
+ File.open(config_file_path) { |f| YAML.safe_load(f) }['installed_versions']
25
+ end
26
+
27
+ # Installs the latest version of chromedriver for the specified platform.
28
+ # browser - string, chrome, edge, firefox, ie
29
+ # platform - string, must match for browser
30
+ # chrome: linux32, linux64, mac32, win32
31
+ # edge: win
32
+ # firefox: linux32, linux64, macos, win32, win64
33
+ # ie: Win32, x64
34
+ def upgrade_driver(browser, platform)
35
+ raise "Unknown Browser '#{browser}'." unless valid_browser?(browser)
36
+ downloader = downloader_for(browser)
37
+ downloader.upgrade_driver(platform)
38
+ end
39
+
40
+ # Installs the latest version of specified driver for all platforms.
41
+ # browser - string, chrome, edge, firefox, ie
42
+ def upgrade_driver_all_platforms(browser)
43
+ raise "Unknown Browser '#{browser}'." unless valid_browser?(browser)
44
+ downloader = downloader_for(browser)
45
+ downloader.upgrade_driver_all_platforms
46
+ end
47
+
48
+ # Installs the specified version of specified driver for the specified platform.
49
+ # browser - string, chrome, edge, firefox, ie
50
+ # platform - string, linux32, linux 64, mac32, win32
51
+ # version: string - must match exactly the version in the download URL
52
+ def install_driver(browser, platform, version)
53
+ raise "Unknown Browser '#{browser}'." unless valid_browser?(browser)
54
+ downloader = downloader_for(browser)
55
+ downloader.install_driver(version, platform)
56
+ end
57
+
58
+ # Installs the specified version of specified driver for all platforms.
59
+ # browser - string, chrome, edge, firefox, ie
60
+ # platforms - linux32, linux 64, mac32, win32
61
+ def install_driver_all_platforms(browser, version)
62
+ raise "Unknown Browser '#{browser}'." unless valid_browser?(browser)
63
+ downloader = downloader_for(browser)
64
+ downloader.install_driver_all_platforms(version)
65
+ end
66
+
67
+ # Returns a new downloader for the specified browser.
68
+ # browser: string - chrome, edge, firefox, ie
69
+ def downloader_for(browser)
70
+ Object.const_get("#{browser.capitalize}driverDownloader").new
71
+ end
72
+
73
+ private
74
+
75
+ def valid_browsers
76
+ %w[chrome firefox edge ie]
77
+ end
78
+
79
+ def valid_browser?(browser)
80
+ valid_browsers.include?(browser)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,4 @@
1
+ require_relative './chauffeur'
2
+ require_relative './chauffeur/requires'
3
+
4
+ binding.pry
@@ -0,0 +1,82 @@
1
+ require_relative './helpers/spec_helper'
2
+
3
+ describe 'downloader_for chrome' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ end
7
+ after(:all) do
8
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
9
+ end
10
+
11
+ it 'returns a ChromedriverDownloader when chrome is passed in' do
12
+ downloader = Chauffeur.downloader_for('chrome')
13
+ expect(downloader.is_a?(ChromedriverDownloader)).to be_truthy
14
+ end
15
+ end
16
+
17
+ describe 'driver_download_url mac' do
18
+ before(:all) do
19
+ Chauffeur::Setup.create_folders_and_config
20
+ end
21
+ after(:all) do
22
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
23
+ end
24
+ it 'returns the url for the mac when mac32 is given' do
25
+ version = '2.11'
26
+ platform = 'mac32'
27
+ downloader = ChromedriverDownloader.new
28
+ url = downloader.driver_download_url(version, platform)
29
+ expect(url).to eq('http://chromedriver.storage.googleapis.com/2.11/chromedriver_mac32.zip')
30
+ end
31
+ end
32
+
33
+ describe 'driver_download_url linux' do
34
+ before(:all) do
35
+ Chauffeur::Setup.create_folders_and_config
36
+ @downloader = ChromedriverDownloader.new
37
+ end
38
+ after(:all) do
39
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
40
+ end
41
+ it 'returns the url for the linux32 when linux32 is given' do
42
+ version = '2.23'
43
+ platform = 'linux32'
44
+ url = @downloader.driver_download_url(version, platform)
45
+ expect(url).to eq('http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux32.zip')
46
+ end
47
+
48
+ it 'returns the url for the linux64 when linux64 is given' do
49
+ version = '2.23'
50
+ platform = 'linux64'
51
+ url = @downloader.driver_download_url(version, platform)
52
+ expect(url).to eq('http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux64.zip')
53
+ end
54
+ end
55
+
56
+ describe 'latest_driver_version' do
57
+ before(:all) do
58
+ Chauffeur::Setup.create_folders_and_config
59
+ @downloader = ChromedriverDownloader.new
60
+ end
61
+ after(:all) do
62
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
63
+ end
64
+ it 'gives the latest version for current platform when none is given' do
65
+ expected_version = Gem::Version.new('2.34')
66
+ found_version = @downloader.latest_driver_version('win32')
67
+ expect(found_version).to eq(expected_version)
68
+ end
69
+
70
+ it 'gives the latest version for windows when win32 is given' do
71
+ platform = 'win32'
72
+ expected_version = Gem::Version.new('2.34')
73
+ found_version = @downloader.latest_driver_version(platform)
74
+ expect(found_version).to eq(expected_version)
75
+ end
76
+
77
+ it 'gives the latest version for mac when mac32 is given' do
78
+ expected_version = Gem::Version.new('2.22')
79
+ found_version = @downloader.latest_driver_version('mac32')
80
+ expect(found_version).to eq(expected_version)
81
+ end
82
+ end
@@ -0,0 +1,79 @@
1
+ require_relative '../helpers/spec_helper'
2
+
3
+ describe 'chromedriver downloader overridden methods' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ @downloader = ChromedriverDownloader.new
7
+ end
8
+ after(:all) do
9
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
10
+ end
11
+ describe 'latest_driver_version' do
12
+ it 'returns a latest driver version for linux32' do
13
+ expect(@downloader.latest_driver_version('linux32')).to be_a(Gem::Version)
14
+ end
15
+ it 'returns a latest driver version for linux64' do
16
+ expect(@downloader.latest_driver_version('linux64')).to be_a(Gem::Version)
17
+ end
18
+ it 'returns a latest driver version for mac32' do
19
+ expect(@downloader.latest_driver_version('mac32')).to be_a(Gem::Version)
20
+ end
21
+ it 'returns a latest driver version for win32' do
22
+ expect(@downloader.latest_driver_version('win32')).to be_a(Gem::Version)
23
+ end
24
+ it 'throws an error for unknown platform' do
25
+ e = Object.const_get('UnknownPlatformError')
26
+ expect { @downloader.latest_driver_version('linux33') }.to raise_error(e)
27
+ end
28
+ end
29
+ end
30
+ describe 'all versions and errors for driver_download_url' do
31
+ before(:all) do
32
+ Chauffeur::Setup.create_folders_and_config
33
+ @downloader = ChromedriverDownloader.new
34
+ end
35
+ after(:all) do
36
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
37
+ end
38
+ describe 'all_driver_versions' do
39
+ it 'returns an array for all_driver_versions' do
40
+ found = @downloader.all_driver_versions
41
+ expect(found).to be_a(Array)
42
+ end
43
+ end
44
+ describe 'driver_download_url' do
45
+ it 'raises an Unknown platform error for unknown platform' do
46
+ e = Object.const_get('UnknownPlatformError')
47
+ expect { @downloader.driver_download_url('2.3', 'linux33') }.to raise_error(e)
48
+ end
49
+ it 'raises an Unknown Version Error When version is invalid' do
50
+ e = Object.const_get('UnknownVersionError')
51
+ expect { @downloader.driver_download_url('1.132', 'linux32') }.to raise_error(e)
52
+ end
53
+ end
54
+ end
55
+ describe 'driver_download_url' do
56
+ before(:all) do
57
+ Chauffeur::Setup.create_folders_and_config
58
+ @downloader = ChromedriverDownloader.new
59
+ end
60
+ after(:all) do
61
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
62
+ end
63
+ it 'returns a string for valid version and linux32' do
64
+ found = @downloader.driver_download_url('2.2', 'linux32')
65
+ expect(found).to be_a(String)
66
+ end
67
+ it 'returns a string for valid version and linux64' do
68
+ found = @downloader.driver_download_url('2.2', 'linux64')
69
+ expect(found).to be_a(String)
70
+ end
71
+ it 'returns a string for valid version and mac32' do
72
+ found = @downloader.driver_download_url('2.2', 'mac32')
73
+ expect(found).to be_a(String)
74
+ end
75
+ it 'returns a string for valid version and win32' do
76
+ found = @downloader.driver_download_url('2.2', 'win32')
77
+ expect(found).to be_a(String)
78
+ end
79
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../helpers/spec_helper'
2
+
3
+ describe 'chromedriver downloader single line methods' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ @downloader = ChromedriverDownloader.new
7
+ end
8
+ after(:all) do
9
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
10
+ end
11
+ it 'has a browser name' do
12
+ expect(@downloader.browser_name).to eq('chromedriver')
13
+ end
14
+ it 'has a browser url' do
15
+ expected = 'http://chromedriver.storage.googleapis.com/'
16
+ expect(@downloader.driver_url).to eq(expected)
17
+ end
18
+ it 'has a browser url' do
19
+ expected = %w[linux32 linux64 mac32 win32]
20
+ expect(@downloader.all_platforms).to eq(expected)
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../helpers/spec_helper'
2
+
3
+ describe 'driver downloader error throwing methods' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ @downloader = DriverDownloader.new
7
+ end
8
+ after(:all) do
9
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
10
+ end
11
+ it 'throws an error for browser_name' do
12
+ expect { @downloader.browser_name }.to raise_error(RuntimeError)
13
+ end
14
+ it 'throws an error for driver_url' do
15
+ expect { @downloader.driver_url }.to raise_error(RuntimeError)
16
+ end
17
+ it 'throws an error for all_platforms' do
18
+ expect { @downloader.all_platforms }.to raise_error(RuntimeError)
19
+ end
20
+ it 'throws an error for latest_driver_version' do
21
+ expect { @downloader.latest_driver_version('something') }.to raise_error(RuntimeError)
22
+ end
23
+ it 'throws an error for all_driver_versions' do
24
+ expect { @downloader.all_driver_versions }.to raise_error(RuntimeError)
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ require_relative './helpers/spec_helper'
2
+
3
+ describe 'driver versions' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ end
7
+ after(:all) do
8
+ FileUtils.rm_r("#{Dir.pwd}/drivers")
9
+ end
10
+ it 'returns a hash of all installed versions' do
11
+ expected = { 'chromedriver' =>
12
+ { 'linux32' => 'nil',
13
+ 'linux64' => 'nil',
14
+ 'mac32' => 'nil',
15
+ 'win32' => 'nil' },
16
+ 'geckodriver' =>
17
+ { 'linux32' => 'nil',
18
+ 'linux64' => 'nil',
19
+ 'macos' => 'nil',
20
+ 'win32' => 'nil',
21
+ 'win64' => 'nil' },
22
+ 'iedriver' =>
23
+ { 'Win32' => 'nil',
24
+ 'x64' => 'nil' },
25
+ 'microsoft_webdriver' => {} }
26
+ found = Chauffeur.driver_versions
27
+ expect(found).to eq(expected)
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../helpers/spec_helper'
2
+
3
+ describe 'chromedriver downloader overridden methods' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ @downloader = EdgedriverDownloader.new
7
+ end
8
+ after(:all) do
9
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
10
+ end
11
+ describe 'latest_driver_version' do
12
+ it 'returns a latest driver version for win' do
13
+ expect(@downloader.latest_driver_version('win')).to be_a(String)
14
+ end
15
+ it 'throws an error for unknown platform' do
16
+ e = Object.const_get('UnknownPlatformError')
17
+ expect { @downloader.latest_driver_version('linux33') }.to raise_error(e)
18
+ end
19
+ end
20
+ end
21
+ describe 'all versions and errors for driver_download_url' do
22
+ before(:all) do
23
+ Chauffeur::Setup.create_folders_and_config
24
+ @downloader = EdgedriverDownloader.new
25
+ end
26
+ after(:all) do
27
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
28
+ end
29
+ describe 'all_driver_versions' do
30
+ it 'returns an array for all_driver_versions' do
31
+ found = @downloader.all_driver_versions
32
+ expect(found).to be_a(Hash)
33
+ end
34
+ end
35
+ describe 'driver_download_url' do
36
+ it 'raises an Unknown platform error for unknown platform' do
37
+ e = Object.const_get('UnknownPlatformError')
38
+ expect { @downloader.driver_download_url('2.3', 'linux33') }.to raise_error(e)
39
+ end
40
+ it 'raises an Unknown Version Error When version is invalid' do
41
+ e = Object.const_get('UnknownVersionError')
42
+ expect { @downloader.driver_download_url('1.132', 'win') }.to raise_error(e)
43
+ end
44
+ end
45
+ end
46
+ describe 'driver_download_url' do
47
+ before(:all) do
48
+ Chauffeur::Setup.create_folders_and_config
49
+ @downloader = EdgedriverDownloader.new
50
+ end
51
+ after(:all) do
52
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
53
+ end
54
+ it 'returns a string for valid version and win' do
55
+ found = @downloader.driver_download_url('15063', 'win')
56
+ expect(found).to be_a(String)
57
+ end
58
+ end
@@ -0,0 +1,22 @@
1
+ require_relative '../helpers/spec_helper'
2
+
3
+ describe 'chromedriver downloader single line methods' do
4
+ before(:all) do
5
+ Chauffeur::Setup.create_folders_and_config
6
+ @downloader = EdgedriverDownloader.new
7
+ end
8
+ after(:all) do
9
+ FileUtils.rm_r("#{Dir.pwd}/drivers") if File.exist?("#{Dir.pwd}/drivers")
10
+ end
11
+ it 'has a browser name' do
12
+ expect(@downloader.browser_name).to eq('microsoft_webdriver')
13
+ end
14
+ it 'has a browser url' do
15
+ expected = 'https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/'
16
+ expect(@downloader.driver_url).to eq(expected)
17
+ end
18
+ it 'has a browser url' do
19
+ expected = %w[win]
20
+ expect(@downloader.all_platforms).to eq(expected)
21
+ end
22
+ end