Skip to content

Commit

Permalink
find chrome version and automatically dl the right driver (#3726)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom authored Aug 23, 2024
1 parent e02caed commit 531807e
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions lib/tasks/test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require 'net/http'
require 'json'

desc 'Test OnDemand'
task :test => 'test:all'

Expand Down Expand Up @@ -60,31 +63,62 @@
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:e2e) do |task|
ENV['BEAKER_setdir'] = PROJ_DIR.join('spec', 'e2e', 'nodesets').to_s
ENV['PATH'] = PROJ_DIR.join('tests').to_s + ":#{ENV['PATH']}"
ENV['PATH'] = PROJ_DIR.join("tests/chromedriver-#{platform}").to_s + ":#{ENV['PATH']}"
task.pattern = "#{PROJ_DIR.join('spec', 'e2e')}/*_spec.rb"
task.rspec_opts = ['--format documentation']
end
rescue LoadError
end

def chrome_version
`google-chrome --version`.split.last
end

def chrome_dl_data(version)
json_uri = URI('https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json')
data = Net::HTTP.get(json_uri)
json = JSON.parse(data)
maj_version = version.split('.').first

json['versions'].select do |driver_data|
driver_major_version = driver_data['version'].split('.').first
driver_major_version == maj_version
end.last
end

def chrome_dl_url(dl_data)
drivers = dl_data['downloads']['chromedriver']
driver = drivers.select { |d| d['platform'] == platform }.first
driver['url']
end

def platform
@platform ||= begin
uname = `uname -s`
case uname.chomp
when 'Darwin'
if `uname -m`.chomp == 'arm64'
'mac-arm64'
else
'mac-x64'
end
when 'Linux'
'linux64'
end
end
end

desc 'Get chromedriver'
task :chromedriver, [:version] do |_t, args|
version = args[:version] || '87.0.4280.88'
uname = `uname -s`
case uname.chomp
when 'Darwin'
file = if `uname -m`.chomp == 'arm64'
'chromedriver_mac_arm64.zip'
else
'chromedriver_mac64.zip'
end
when 'Linux'
file = 'chromedriver_linux64.zip'
end
url = "https://chromedriver.storage.googleapis.com/#{version}/#{file}"
sh "curl -o tests/#{file} #{url}"
version = args[:version] || chrome_version
puts "Fetching chromedriver #{version}"

data = chrome_dl_data(version)
url = chrome_dl_url(data)

sh "curl -o tests/chromedriver.zip #{url}"
chdir PROJ_DIR.join('tests') do
sh "unzip -o #{file}"
sh 'unzip -o chromedriver.zip'
end
end

Expand Down

0 comments on commit 531807e

Please sign in to comment.