Skip to content

Commit

Permalink
Fix #11 chromedriver version does not update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Hoer committed May 26, 2015
1 parent 01470b4 commit b300c50
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.2.6 - 5/26/2015

- Fix #11 chromedriver version does not update
- Update ChromeDriver from 2.14 to 2.15

## 2.2.5 - 5/1/2015

- Fix #10 'failed to allocate memory' exception on Windows 2008
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'MIT'
description 'Installs/Configures Selenium'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.2.5'
version '2.2.6'

supports 'centos'
supports 'redhat'
Expand Down
67 changes: 31 additions & 36 deletions recipes/chromedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,47 @@

bit = node['kernel']['machine'] == 'x86_64' && !platform?('windows') ? '64' : '32'
os = platform?('windows') ? 'win' : 'linux'
dir = "#{selenium_home}/drivers/chromedriver_#{os}#{bit}-#{node['selenium']['chromedriver_version']}"
version = node['selenium']['chromedriver_version']

directory dir do
action :create
end
name = "chromedriver_#{os}#{bit}-#{version}"
driver_path = "#{selenium_home}/drivers/#{name}"
cache_path = "#{Chef::Config[:file_cache_path]}/#{name}.zip"

src = "#{node['selenium']['chromedriver_url']}/#{node['selenium']['chromedriver_version']}/chromedriver_#{os}#{bit}.zip"
src = "#{node['selenium']['chromedriver_url']}/#{version}/chromedriver_#{os}#{bit}.zip"
link = "#{selenium_home}/drivers/chromedriver"

if platform_family?('windows')
zip = "#{Chef::Config[:file_cache_path]}/chromedriver_#{os}#{bit}.zip"
directory driver_path do
action :create
end

remote_file zip do
source src
not_if { ::File.exist?("#{link}/chromedriver.exe") }
# Fixes #10: windows_zipfile rubyzip failure to allocate memory (requires PowerShell 3 or greater & .NET Framework 4)
begin
batch 'unzip chromedriver' do
code "powershell.exe -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem';"\
" [IO.Compression.ZipFile]::ExtractToDirectory('#{cache_path}', '#{driver_path}'); }\""
action :nothing
end

# Fixes #10: windows_zipfile rubyzip failure to allocate memory (requires PowerShell 3 or greater & .NET Framework 4)
begin
batch 'unzip chrome driver' do
code "powershell.exe -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem';"\
" [IO.Compression.ZipFile]::ExtractToDirectory('#{zip}', '#{dir}'); }\""
not_if { ::File.exist?("#{link}/chromedriver.exe") }
end
rescue # cheesy attempt at backward compatibility
windows_zipfile dir do
source zip
action :unzip
not_if { ::File.exist?("#{link}/chromedriver.exe") }
end
rescue # cheesy attempt at backward compatibility
windows_zipfile driver_path do
source cache_path
action :unzip
end
else # linux
cache = "#{Chef::Config[:file_cache_path]}/chromedriver_linux#{bit}-#{node['selenium']['chromedriver_version']}.zip"
end

execute 'unpack chromedriver' do
command "unzip -o #{cache} -d #{dir}"
action :nothing
end
execute 'unzip chromedriver' do
command "unzip -o #{cache_path} -d #{driver_path}"
action :nothing
end

remote_file cache do
source src
action :create
notifies :run, 'execute[unpack chromedriver]', :immediately
end
remote_file 'download chromedriver' do
path cache_path
source src
use_etag true
use_conditional_get true
notifies :run, 'batch[unzip chromedriver]', :immediately if platform?('windows')
notifies :run, 'execute[unzip chromedriver]', :immediately unless platform?('windows')
end

link link do
to dir
to driver_path
end
28 changes: 15 additions & 13 deletions spec/unit/chromedriver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@
end

it 'create directory' do
expect(chef_run).to create_directory('C:/selenium/drivers/chromedriver_win32-2.14')
expect(chef_run).to create_directory('C:/selenium/drivers/chromedriver_win32-2.15')
end

it 'downloads driver' do
expect(chef_run).to create_remote_file('C:/chef/cache/chromedriver_win32.zip').with(
source: 'https://chromedriver.storage.googleapis.com/2.14/chromedriver_win32.zip'
expect(chef_run).to create_remote_file('download chromedriver').with(
path: "#{Chef::Config[:file_cache_path]}/chromedriver_win32-2.15.zip",
source: 'https://chromedriver.storage.googleapis.com/2.15/chromedriver_win32.zip'
)
end

it 'unzips driver' do
expect(chef_run).to run_batch('unzip chrome driver')
expect(chef_run).to_not run_batch('unzip chromedriver')
.with(code: "powershell.exe -nologo -noprofile -command \"& { Add-Type -A "\
"'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory("\
"'C:/chef/cache/chromedriver_win32.zip', "\
"'C:/selenium/drivers/chromedriver_win32-2.14'); }\"")
"'C:/selenium/drivers/chromedriver_win32-2.15'); }\"")
end

it 'link driver' do
expect(chef_run).to create_link('C:/selenium/drivers/chromedriver').with(
to: 'C:/selenium/drivers/chromedriver_win32-2.14'
to: 'C:/selenium/drivers/chromedriver_win32-2.15'
)
end
end
Expand All @@ -39,22 +40,23 @@
end

it 'create directory' do
expect(chef_run).to create_directory('/usr/local/selenium/drivers/chromedriver_linux64-2.14')
expect(chef_run).to create_directory('/usr/local/selenium/drivers/chromedriver_linux64-2.15')
end

it 'downloads chromedriver' do
expect(chef_run).to create_remote_file("#{Chef::Config[:file_cache_path]}/chromedriver_linux64-2.14.zip").with(
source: 'https://chromedriver.storage.googleapis.com/2.14/chromedriver_linux64.zip'
it 'downloads driver' do
expect(chef_run).to create_remote_file('download chromedriver').with(
path: "#{Chef::Config[:file_cache_path]}/chromedriver_linux64-2.15.zip",
source: 'https://chromedriver.storage.googleapis.com/2.15/chromedriver_linux64.zip'
)
end

it 'unpack chromedriver' do
expect(chef_run).to_not run_execute('unpack chromedriver')
it 'unpack driver' do
expect(chef_run).to_not run_execute('unzip chromedriver')
end

it 'link driver' do
expect(chef_run).to create_link('/usr/local/selenium/drivers/chromedriver').with(
to: '/usr/local/selenium/drivers/chromedriver_linux64-2.14'
to: '/usr/local/selenium/drivers/chromedriver_linux64-2.15'
)
end
end
Expand Down

0 comments on commit b300c50

Please sign in to comment.