From c801b14d77c6877b6a7fd9758c5d3aef8d214331 Mon Sep 17 00:00:00 2001 From: Rodrigo Urubatan Date: Wed, 13 Jan 2021 17:38:57 -0300 Subject: [PATCH 1/2] Fix for titusfortner/webdrivers#192 and titusfortner/webdrivers#197 uses information from (https://askubuntu.com/questions/1177729/wsl-am-i-running-version-1-or-version-2) checking if the WSL kernel version is < 4.19 then it is WSL 1 --- lib/webdrivers/.system.rb.swp | Bin 0 -> 16384 bytes lib/webdrivers/chrome_finder.rb | 4 ++-- lib/webdrivers/chromedriver.rb | 4 ++-- lib/webdrivers/system.rb | 14 ++++++++++++-- spec/webdrivers/.system_spec.rb.swp | Bin 0 -> 12288 bytes spec/webdrivers/chrome_finder_spec.rb | 2 +- spec/webdrivers/system_spec.rb | 24 +++++++++++++++++++++--- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 lib/webdrivers/.system.rb.swp create mode 100644 spec/webdrivers/.system_spec.rb.swp diff --git a/lib/webdrivers/.system.rb.swp b/lib/webdrivers/.system.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..b91fdd9a81737a8a33a8f4331d1f0e4b59215581 GIT binary patch literal 16384 zcmeI3Uu+yl9mh9mX$erEL4rz1@QWQ~&#}E{Cv8=ZxK8E7#WYD#?4)XJbL{QT-EF+L zyWKxN+p!b%p+ZICp+F1bg$F1o1>RDcz9A}6wX_dNh$2)8sCYpjB*a4jRg~|{?Ci}s zw$lb7p=ww9_-=P*e)F5({Qdp*+!#AMbCT|{#tmE_HH_as{C0ieEBWWHO`kXA_b2nu)lKR7ZTV4JptL|~fzkq{1xgE)7AP%HTA;K* zX@SxLr3Fe0{2yAtb`1ls`i%+?0O0+<^8erXh++Hz{2W{b-v>{FF1Q!`5S z!M$KF_{9ee<7E(m(_k7L0iOk*06+bJVf+L<3%(9cf=`1_fj9OT#&5uD;5iV15S#!H zfC2E!_Z!B~z*X=Z_!?LOGvKXT4dYkf1@J7m0vyl)d%^ACx3@qCa0NUAE`ujP2<`xT z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gf_MDoO|x{54q-Yu<-ZET}H!ct0@iy`6 zoEOzjk#GRPjv|;=QK{0KA literal 0 HcmV?d00001 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..33850d78 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 0000000000000000000000000000000000000000..83e07709f9b705514f12b503551de615b5542d1a GIT binary patch literal 12288 zcmeI2&2QX97{;emKocn62aq_tO$6RWjrSuTN>@Tu1W^Sw0x3;%sDtr(Ct0^%&vrb! zn*ag93GoMj1SdFfs6Zej4xHc!^hPgKLPBui+`@?qJma;UZL&!lsYq=#mVO!A^YzX% z@4Vwxrd~chzd*Bgh2eULu_sUe>pt~ilWiVltRp*hPkE8f+Ur`<Dxlg2*xMM{UFqn~r0IceY5HgqqkvJs zC}0#Y3K#{90!9I&fKk9GU=%P47zJ)a1-u4hmk%=L-3{aM|Nrdw{~r%B_B*%;ega>E z_do#V!8CXbjDSPn>I01Z2rhv4K^H86m%u!D20RQd9cJuZ@D6wt{Cz)Te}V77H{c8K zIami4cp4l8AK%B=M_>)CfF*DWjDbs|jQtEg0}*I}V_+6s8DZ>C@Ef=cegWSC2b=-V zgHbR7E*xU)Q}78`2S>mY;BoNly^MViHo=?VIG6!8C;$tLg0Jpj>`U+gSOE_B2ijf* zSHKS-2Il|=TKCt0xr_ovfjdwE9yJ(I|L<0cyLFsrQiTSOeHqkw!}UWij%_8}UL3k@ zPc;ix$uH@fk`kp=5jMEAibXpT%2h(Q==K6#%89HZx*!S^S(3Lzm&c@aYUBbln)a=Y^4`NBKIx;GZ z?GV+8#)`CwJ~Knf8XuU3tlvztEFGN8-E~Z7YnYaqKD$*;d?AP?tEo4<0G+i1=*d4% zR`Qri+@EZt!;Qpf!sUxd@pVYqYw{@Zie%z~7~)CpH8v=SXgP=)q8AfnZFwpi z@ZbRV@YVqfcSw87`D+jUy2HxrIcq*b+FAGi_0^$EYZrITt<2^xbJQ#yoX_0nUJOE> z$CPbeD%w2CR=hs4>6i5R%s}XPlR94BPPTTkIHrSGxAI)(t*c%b^Q}t#h1>5N?wqgI zevf*!>S*H%8LS177Y=xNLm(nxQBhqW#7Xj-+&`ydoVG6;xpw^h1c`R&Dee13dn-_o z)$-7wjtj$9k>8P$M~bqlgcX%k7!qQW9Y8m8qiQMHxnZ&T0eRc>42+|&s3i26f7!+^ zP)PO`DCH(`AyRR%zjgFCk3`Ivu5B#eG;W5b*oHdm`%^Woax-+@mly6^*e(L~Z740( zJBpSUPj;*6rjadWY=h}4PBQY>%lT35T5T~oo1M7GihWjKFR@66L~B7rwBT(}d73IS zwenQ0T&7nRPf@j8Ehh!WXD4SS76M<2Sgb1RsIF94^Ld z$MZYe7p*k=q;{^n{*!-1n619uijhF{K~Q2?BDKb{Siohz7ycP$kHd} i-6jv)_+Z3IUs{#obso8K5(wNdP+WRp4WEaIGXDX6ro)f` literal 0 HcmV?d00001 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 From ec266828442d1a148f5740fd893ec5230b8390ca Mon Sep 17 00:00:00 2001 From: Rodrigo Urubatan Date: Wed, 13 Jan 2021 17:41:09 -0300 Subject: [PATCH 2/2] rake rubocop:auto_correct --- lib/webdrivers/system.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webdrivers/system.rb b/lib/webdrivers/system.rb index 33850d78..9fa3e3e6 100644 --- a/lib/webdrivers/system.rb +++ b/lib/webdrivers/system.rb @@ -151,8 +151,8 @@ def platform # @return [TrueClass, FalseClass] def wsl_v1? if platform == 'linux' - version=File.open('/proc/version')&.read - if version.downcase.include?('microsoft') + 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