diff --git a/lib/webdrivers/.system.rb.swp b/lib/webdrivers/.system.rb.swp new file mode 100644 index 00000000..b91fdd9a Binary files /dev/null and b/lib/webdrivers/.system.rb.swp differ diff --git a/lib/webdrivers/chrome_finder.rb b/lib/webdrivers/chrome_finder.rb index 20f28e94..8d72c49a 100644 --- a/lib/webdrivers/chrome_finder.rb +++ b/lib/webdrivers/chrome_finder.rb @@ -88,7 +88,7 @@ def mac_location end def linux_location - return wsl_location if System.wsl? + return wsl_location if System.wsl_v1? directories = %w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /snap/bin /opt/google/chrome] files = %w[google-chrome chrome chromium chromium-browser] @@ -114,7 +114,7 @@ def wsl_version(location) end def linux_version(location) - return wsl_version(location) if System.wsl? + return wsl_version(location) if System.wsl_v1? System.call(location, '--product-version')&.strip end diff --git a/lib/webdrivers/chromedriver.rb b/lib/webdrivers/chromedriver.rb index 26954a0b..62f892d1 100644 --- a/lib/webdrivers/chromedriver.rb +++ b/lib/webdrivers/chromedriver.rb @@ -84,7 +84,7 @@ def latest_point_release(version) end def file_name - System.platform == 'win' || System.wsl? ? 'chromedriver.exe' : 'chromedriver' + System.platform == 'win' || System.wsl_v1? ? 'chromedriver.exe' : 'chromedriver' end def apple_m1_compatible?(version) @@ -102,7 +102,7 @@ def download_url apple_arch = apple_m1_compatible?(version) ? '_m1' : '' - file_name = System.platform == 'win' || System.wsl? ? 'win32' : "#{System.platform}64#{apple_arch}" + file_name = System.platform == 'win' || System.wsl_v1? ? 'win32' : "#{System.platform}64#{apple_arch}" url = "#{base_url}/#{version}/chromedriver_#{file_name}.zip" Webdrivers.logger.debug "chromedriver URL: #{url}" @download_url = url diff --git a/lib/webdrivers/system.rb b/lib/webdrivers/system.rb index 9648efcf..9fa3e3e6 100644 --- a/lib/webdrivers/system.rb +++ b/lib/webdrivers/system.rb @@ -149,8 +149,18 @@ def platform end # @return [TrueClass, FalseClass] - def wsl? - platform == 'linux' && File.open('/proc/version').read.downcase.include?('microsoft') + def wsl_v1? + if platform == 'linux' + version = File.open('/proc/version')&.read + if version.downcase.include?('microsoft') + ver = Gem::Version.new(version.gsub(/.*Linux version ([^ ]*).*/, '\1')) + ver.canonical_segments[0] <= 4 && ver.canonical_segments[1] < 19 + else + false + end + else + false + end end # @param [String] path diff --git a/spec/webdrivers/.system_spec.rb.swp b/spec/webdrivers/.system_spec.rb.swp new file mode 100644 index 00000000..83e07709 Binary files /dev/null and b/spec/webdrivers/.system_spec.rb.swp differ diff --git a/spec/webdrivers/chrome_finder_spec.rb b/spec/webdrivers/chrome_finder_spec.rb index ad54abe3..b3aced4c 100644 --- a/spec/webdrivers/chrome_finder_spec.rb +++ b/spec/webdrivers/chrome_finder_spec.rb @@ -52,7 +52,7 @@ before do skip "The current platform cannot be WSL, as it's not Linux" unless Selenium::WebDriver::Platform.linux? - allow(Webdrivers::System).to receive(:wsl?).and_return(true) + allow(Webdrivers::System).to receive(:wsl_v1?).and_return(true) allow(Webdrivers::System).to receive(:to_wsl_path).and_return('') allow(Webdrivers::System).to receive(:to_win32_path).and_return('') end diff --git a/spec/webdrivers/system_spec.rb b/spec/webdrivers/system_spec.rb index c89f7796..2ac81afd 100644 --- a/spec/webdrivers/system_spec.rb +++ b/spec/webdrivers/system_spec.rb @@ -2,6 +2,14 @@ require 'spec_helper' +wslv2_proc_contents = [ + 'Linux version 4.19.0-18362-Microsoft', + '(Microsoft@Microsoft.com)', + '(gcc version 5.4.0 (GCC) )', + '#836-Microsoft', + 'Mon May 05 16:04:00 PST 2020' +].join ' ' + wsl_proc_contents = [ 'Linux version 4.4.0-18362-Microsoft', '(Microsoft@Microsoft.com)', @@ -11,14 +19,24 @@ ].join ' ' describe Webdrivers::System do - describe '#wsl?' do + describe '#wsl_v1?' do + context 'when the current platform is linux but WSLv2' do + before { allow(described_class).to receive(:platform).and_return 'linux' } + + it 'checks /proc/version' do + allow(File).to receive(:open).with('/proc/version').and_return(StringIO.new(wslv2_proc_contents)) + + expect(described_class.wsl_v1?).to eq false + end + end + context 'when the current platform is linux' do before { allow(described_class).to receive(:platform).and_return 'linux' } it 'checks /proc/version' do allow(File).to receive(:open).with('/proc/version').and_return(StringIO.new(wsl_proc_contents)) - expect(described_class.wsl?).to eq true + expect(described_class.wsl_v1?).to eq true end end @@ -28,7 +46,7 @@ it 'does not bother checking proc' do allow(File).to receive(:open).and_call_original - expect(described_class.wsl?).to eq false + expect(described_class.wsl_v1?).to eq false expect(File).not_to have_received(:open).with('/proc/version') end