From 4b80eb486b79039957b85e5f2b0bdfc853be1e7a Mon Sep 17 00:00:00 2001 From: Stephann Vasconcelos <3025661+stephannv@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:27:55 -0300 Subject: [PATCH] Download correct geckdriver file on Apple Silicon Geckodriver splits its Mac OS files into 2 versions (macos.tar.gz and macos-aarch64.tar.gz), and webdriver doesn't work properly if `macos.tar.gz` is used on Apple Sillicon platform. Geckodriver releases: https://github.com/mozilla/geckodriver/releases --- lib/webdrivers/geckodriver.rb | 2 +- spec/webdrivers/geckodriver_spec.rb | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/webdrivers/geckodriver.rb b/lib/webdrivers/geckodriver.rb index de3fb51e..a17cd9b5 100644 --- a/lib/webdrivers/geckodriver.rb +++ b/lib/webdrivers/geckodriver.rb @@ -51,7 +51,7 @@ def platform_ext when 'linux' "linux#{System.bitsize}.tar.gz" when 'mac' - 'macos.tar.gz' + System.apple_m1_architecture? ? 'macos-aarch64.tar.gz' : 'macos.tar.gz' when 'win' "win#{System.bitsize}.zip" end diff --git a/spec/webdrivers/geckodriver_spec.rb b/spec/webdrivers/geckodriver_spec.rb index d6b49ede..0ee809bc 100644 --- a/spec/webdrivers/geckodriver_spec.rb +++ b/spec/webdrivers/geckodriver_spec.rb @@ -92,6 +92,40 @@ msg = /Net::HTTPServerException: 404 "Not Found"/ expect { geckodriver.update }.to raise_error(StandardError, msg) end + + context 'when platform is Apple Sillicon' do + it 'downloads aarch64 binary' do + allow(Webdrivers::System).to receive(:platform).and_return('mac') + allow(Webdrivers::System).to receive(:apple_m1_architecture?).and_return(true) + base = 'https://github.com/mozilla/geckodriver/releases/download' + binary = 'geckodriver-v0.31.0-macos-aarch64.tar.gz' + url = "#{base}/v0.31.0/#{binary}" + + allow(Webdrivers::System).to receive(:download).with(url, geckodriver.driver_path) + + geckodriver.required_version = '0.31.0' + geckodriver.update + + expect(Webdrivers::System).to have_received(:download).with(url, geckodriver.driver_path) + end + end + + context 'when platform isn\'t Apple Sillicon' do + it 'downloads default binary' do + allow(Webdrivers::System).to receive(:platform).and_return('mac') + allow(Webdrivers::System).to receive(:apple_m1_architecture?).and_return(false) + base = 'https://github.com/mozilla/geckodriver/releases/download' + binary = 'geckodriver-v0.31.0-macos.tar.gz' + url = "#{base}/v0.31.0/#{binary}" + + allow(Webdrivers::System).to receive(:download).with(url, geckodriver.driver_path) + + geckodriver.required_version = '0.31.0' + geckodriver.update + + expect(Webdrivers::System).to have_received(:download).with(url, geckodriver.driver_path) + end + end end describe '#current_version' do