Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way the library uses to detect WSL to detect only WSL v1 #199

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lib/webdrivers/.system.rb.swp
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/webdrivers/chrome_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/webdrivers/chromedriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions lib/webdrivers/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added spec/webdrivers/.system_spec.rb.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/webdrivers/chrome_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 21 additions & 3 deletions spec/webdrivers/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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

Expand All @@ -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
Expand Down