titusfortner / webdrivers

Keep your Selenium WebDrivers updated automatically
MIT License
596 stars 111 forks source link

Can't find Chrome Binary in WSL2 with version 4.4.2 #192

Closed fabioxgn closed 3 years ago

fabioxgn commented 3 years ago

After updating to v4.4.2 my tests are failing with:

Webdrivers::BrowserNotFound:  Failed to find Chrome binary.

I've tried to set the WD_CHROME_PATH to the chrome binary path of my WSL2 Ubuntu installation but it doesn't work either:

 Webdrivers::VersionError: Failed to find Chrome version
 RuntimeError:
            Failed to make system call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]

What's the proper way to use chrome on WSL2?

kapoorlakshya commented 3 years ago

Was this working in v4.4.1? And please share the debug logs (instructions). I'll try to setup WSL2 tomorrow and reproduce this.

@G-Rath Would it be possible for you to troubleshoot this as well?

G-Rath commented 3 years ago

@kapoorlakshya I don't have WSLv2 setup, but happy to help where I can - I'll see if I can find some time to try get it setup somewhere so I can test things locally.

kapoorlakshya commented 3 years ago

@G-Rath Thanks! Here's what I've found:

v4.4.1 and v4.4.2 are able to find the Chrome binary installed on my local system when using WSL2:

C:\Users\Lakshya>wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         1

C:\Users\Lakshya>wsl
kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ irb
irb(main):001:0> require 'webdrivers'
=> true

irb(main):003:0> Webdrivers::ChromeFinder.location
=> "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"

irb(main):004:0> Webdrivers::Chromedriver.browser_version
sh: 1: pwsh.exe: not found
=> #<Gem::Version "87.0.4280.88">

irb(main):005:0> Webdrivers::Chromedriver.current_version
=> nil

irb(main):006:0> Webdrivers::Chromedriver.update
sh: 1: pwsh.exe: not found
sh: 1: pwsh.exe: not found
sh: 1: pwsh.exe: not found
sh: 1: pwsh.exe: not found
sh: 1: pwsh.exe: not found
sh: 1: pwsh.exe: not found
=> "/home/kapoorlakshya/.webdrivers/chromedriver.exe"

irb(main):007:0> Webdrivers::Chromedriver.current_version
=> #<Gem::Version "87.0.4280.88">

Side note: Need to look into the pwsh.exe not found errors. Doesn't appear to be a blocker though.

But I do get the Webdrivers::VersionError in both v4.4.1 and v4.4.2 when using the Chrome binary installed inside WSL2 (in /usr/bin/):

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ which google-chrome
/usr/bin/google-chrome

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ google-chrome --version
Google Chrome 87.0.4280.88

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ export WD_CHROME_PATH=$(which google-chrome)

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ echo $WD_CHROME_PATH
/usr/bin/google-chrome

kapoorlakshya@Windows10:/mnt/c/Users/Lakshya$ irb
irb(main):001:0> require 'webdrivers'
=> true

irb(main):002:0> Webdrivers::ChromeFinder.location
=> "/usr/bin/google-chrome"

irb(main):003:0> Webdrivers::Chromedriver.browser_version
sh: 1: pwsh.exe: not found
Get-ItemProperty : Cannot find path 'C:\wsl$\Ubuntu-20.04\opt\google\chrome\google-chrome' because it does not exist.
At line:1 char:2
+ (Get-ItemProperty '\wsl$\Ubuntu-20.04\opt\google\chrome\google-chrome ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\wsl$\Ubuntu-...e\google-chrome:String) [Get-ItemProperty], ItemNotFo
   undException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

Traceback (most recent call last):
        6: from /home/kapoorlakshya/.rbenv/versions/2.6.6/bin/irb:23:in `<main>'
        5: from /home/kapoorlakshya/.rbenv/versions/2.6.6/bin/irb:23:in `load'
        4: from /home/kapoorlakshya/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        3: from (irb):3
        2: from /home/kapoorlakshya/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webdrivers-4.4.2/lib/webdrivers/chromedriver.rb:51:in `browser_version'
        1: from /home/kapoorlakshya/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webdrivers-4.4.2/lib/webdrivers/chrome_finder.rb:11:in `version'
Webdrivers::VersionError (Failed to find Chrome version.)

@fabioxgn Can you please follow the steps from the first code block and share what you're seeing? Chrome installed on my local machine is being found within WSL2, and chromedriver is successfully downloaded, but not if I set WD_CHROME_PATH to the binary in /usr/bin/.

Also do note that this gem currently only supports WSL1. This ticket might become the motivator to add WSL2 support soon, if there is a breaking change between the two at all. Need to look into that.

G-Rath commented 3 years ago

Need to look into the pwsh.exe not found errors

That'll be because you've not got the new powershell installed, which we attempt to use if possible to avoid messing up the terminal due to an unfixable "bug" in conhost/powershell.


I feel like this is what'll happen in WSL1 too.

C:\wsl$\Ubuntu-20.04\opt\google\chrome\google-chrome

That path doesn't look right to me? This is all just based on your comment (i.e. I've not done anything in WSL2) so it might be fine, but I'd try navigating to that path in Windows Explorer to see if you can actually get there.

kapoorlakshya commented 3 years ago

That'll be because you've not got the new powershell installed

Right. Sorry, I should have been more clear - I meant that we should not be printing that harmless error in the console. It may confuse users using PS < 6.0 into thinking that something went wrong even though that error is successfully rescued.

I was able to fix that when using PS 5.1 by redirecting STDERR to STDOUT and letting IO.popen intercept it just for the pwsh.exe call (see change), but then realized that it would cause true errors when using pwsh.exe to not be sent to STDERR. I'm now going to install PS 7 and test my fix/debug this further to make sure both PS old and new versions work the same.

That path doesn't look right to me?

I looked into this and the apparently wslpath is converting /usr/bin/google-chrome to \\\\wsl$\\Ubuntu-20.04\\opt\\google\\chrome\\google-chrome:

From: /mnt/d/git_local/webdrivers/lib/webdrivers/system.rb:162 Webdrivers::System.to_win32_path:

[1] pry(Webdrivers::System)> path
=> "/usr/bin/google-chrome"

[2] pry(Webdrivers::System)> call("wslpath -w '#{path}'").chomp
=> "\\\\wsl$\\Ubuntu-20.04\\opt\\google\\chrome\\google-chrome"

but I'd try navigating to that path in Windows Explorer to see if you can actually get there.

So... I think my WSL setup is broken because I am unable to access the base path \\wsl$ from explorer. Will try to spend more time on this soon.

kapoorlakshya commented 3 years ago

I was able to quickly fix my WSL setup and I am now able to access \\wsl$\Ubuntu-20.04\opt\google\chrome. After further debugging, the root cause is that powershell.exe is unable to resolve the \\wsl$ UNC path in "\\\\wsl$\\Ubuntu-20.04\\opt\\google\\chrome\\google-chrome". It needs the fully resolved path for wsl$ to work, but I am not yet to sure how to do that.

kapoorlakshya commented 3 years ago

Just realized we actually don't need Powershell for this. ChromeFinder#linux_version is what we need to use here. Will look more into this soon.

fabioxgn commented 3 years ago

@fabioxgn Can you please follow the steps from the first code block and share what you're seeing? Chrome installed on my local machine is being found within WSL2, and chromedriver is successfully downloaded, but not if I set WD_CHROME_PATH to the binary in /usr/bin/.

>  wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
fabio@XPS:~/ $ irb
ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
fabio@XPS:~/ $ irb
irb(main):001:0> require "webdrivers"
=> true
irb(main):002:0> Webdrivers::ChromeFinder.location
=> "/usr/bin/google-chrome"
irb(main):003:0> Webdrivers::Chromedriver.browser_version
/home/fabio/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webdrivers-4.4.1/lib/webdrivers/system.rb:177: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
=> #<Gem::Version "87.0.4280.88">
irb(main):004:0> Webdrivers::Chromedriver.current_version
=> #<Gem::Version "87.0.4280.88">
irb(main):005:0> Webdrivers::Chromedriver.update
=> "/home/fabio/.webdrivers/chromedriver"
irb(main):006:0> Webdrivers::Chromedriver.current_version
=> #<Gem::Version "87.0.4280.88">

@kapoorlakshya here's the output of the commands you asked, looks like to be ok, maybe this is some problem with my project's config that can't find chrome?

fabioxgn commented 3 years ago

Was this working in v4.4.1? And please share the debug logs (instructions). I'll try to setup WSL2 tomorrow and reproduce this.

@G-Rath Would it be possible for you to troubleshoot this as well?

Here's the debug output:

2021-01-04 09:01:26 DEBUG Webdrivers Checking current version
2021-01-04 09:01:26 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-04 09:01:26 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-04 09:01:26 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-04 09:01:26 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-04 09:01:26 DEBUG Webdrivers making System call: wslpath -u 'c:\Users\fabio\AppData\Local\Google\Chrome\Application\chrome.exe'
2021-01-04 09:01:27 DEBUG Webdrivers System call returned: /mnt/c/Users/fabio/AppData/Local/Google/Chrome/Application/chrome.exe

2021-01-04 09:01:27 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
2021-01-04 09:01:27 DEBUG Webdrivers System call returned: /mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe

2021-01-04 09:01:27 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files\Google\Chrome\Application\chrome.exe'
2021-01-04 09:01:27 DEBUG Webdrivers System call returned: /mnt/c/Program Files/Google/Chrome/Application/chrome.exe

2021-01-04 09:01:27 DEBUG Webdrivers making System call: wslpath -u 'c:\Users\fabio\AppData\Local\Chromium\Application\chrome.exe'
2021-01-04 09:01:27 DEBUG Webdrivers System call returned: /mnt/c/Users/fabio/AppData/Local/Chromium/Application/chrome.exe

2021-01-04 09:01:27 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files (x86)\Chromium\Application\chrome.exe'
2021-01-04 09:01:27 DEBUG Webdrivers System call returned: /mnt/c/Program Files (x86)/Chromium/Application/chrome.exe

2021-01-04 09:01:27 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files\Chromium\Application\chrome.exe'
2021-01-04 09:01:27 DEBUG Webdrivers System call returned: /mnt/c/Program Files/Chromium/Application/chrome.exe
kapoorlakshya commented 3 years ago

@fabioxgn Thanks for the logs. I am little confused why the Chrome path in the first comment is /usr/bin/google-chrome, but the debug logs show the Windows filesystem path for Chrome. Did you set WD_CHROME_PATH in the first one, but not for the second run? Anyway, if it's working then nothing to worry about. I am not seeing any issues on my end unless I set WD_CHROME_PATH to the Chrome binary on the Linux filesystem.

I'll try to fix it this week.

fabioxgn commented 3 years ago

@fabioxgn Thanks for the logs. I am little confused why the Chrome path in the first comment is /usr/bin/google-chrome, but the debug logs show the Windows filesystem path for Chrome. Did you set WD_CHROME_PATH in the first one, but not for the second run? Anyway, if it's working then nothing to worry about. I am not seeing any issues on my end unless I set WD_CHROME_PATH to the Chrome binary on the Linux filesystem.

I'll try to fix it this week.

@kapoorlakshya these logs are from the same run. I did not customize the WD_CHROME_PATH, only thing that is changed on our project is this: Webdrivers.install_dir = File.expand_path("~/.webdrivers/#{ENV['TEST_ENV_NUMBER']}") but removing it doesn't make any difference.

Setting the WD_CHROME_PATH I get this:

WD_CHROME_PATH=/usr/bin/google-chrome rspec spec/system/ --fail-fast
Running via Spring preloader in process 6451
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 2665
....2021-01-05 10:50:31 DEBUG Webdrivers Checking current version
2021-01-05 10:50:31 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-05 10:50:31 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-05 10:50:32 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:32 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:32 DEBUG Webdrivers WD_CHROME_PATH: /usr/bin/google-chrome
2021-01-05 10:50:32 DEBUG Webdrivers making System call: wslpath -w '/usr/bin/google-chrome'
2021-01-05 10:50:32 DEBUG Webdrivers System call returned: \\wsl$\Ubuntu\opt\google\chrome\google-chrome

2021-01-05 10:50:32 DEBUG Webdrivers making System call: pwsh.exe -command "(Get-ItemProperty '\\wsl$\Ubuntu\opt\google\chrome\google-chrome').VersionInfo.ProductVersion"
sh: 1: pwsh.exe: not found
2021-01-05 10:50:32 DEBUG Webdrivers making System call: powershell.exe "(Get-ItemProperty '\\wsl$\Ubuntu\opt\google\chrome\google-chrome').VersionInfo.ProductVersion"
Get-ItemProperty : Não é possível localizar o caminho 
'Microsoft.PowerShell.Core\FileSystem::wsl$\Ubuntu\opt\google\chrome\google-chrome' porque ele não existe.
No linha:1 caractere:2
+ (Get-ItemProperty '\wsl$\Ubuntu\opt\google\chrome\google-chrome').Ver ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...e\google-chrome:String) [Get-ItemProperty], ItemNotFo 
   undException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

2021-01-05 10:50:33 DEBUG Webdrivers System call returned: 
2021-01-05 10:50:33 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-05 10:50:33 DEBUG Webdrivers Checking current version
2021-01-05 10:50:33 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-05 10:50:33 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-05 10:50:33 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:33 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:33 DEBUG Webdrivers Checking current version
2021-01-05 10:50:33 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-05 10:50:33 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-05 10:50:34 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:34 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:34 DEBUG Webdrivers Checking current version
2021-01-05 10:50:34 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-05 10:50:34 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-05 10:50:34 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:34 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:34 DEBUG Webdrivers Checking current version
2021-01-05 10:50:34 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-05 10:50:34 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-05 10:50:35 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:35 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-05 10:50:35 DEBUG Webdrivers WD_CHROME_PATH: /usr/bin/google-chrome
2021-01-05 10:50:35 DEBUG Webdrivers making System call: wslpath -w '/usr/bin/google-chrome'
2021-01-05 10:50:35 DEBUG Webdrivers System call returned: \\wsl$\Ubuntu\opt\google\chrome\google-chrome

2021-01-05 10:50:35 DEBUG Webdrivers making System call: pwsh.exe -command "(Get-ItemProperty '\\wsl$\Ubuntu\opt\google\chrome\google-chrome').VersionInfo.ProductVersion"
sh: 1: pwsh.exe: not found
2021-01-05 10:50:35 DEBUG Webdrivers making System call: powershell.exe "(Get-ItemProperty '\\wsl$\Ubuntu\opt\google\chrome\google-chrome').VersionInfo.ProductVersion"
Get-ItemProperty : Não é possível localizar o caminho 
'Microsoft.PowerShell.Core\FileSystem::wsl$\Ubuntu\opt\google\chrome\google-chrome' porque ele não existe.
No linha:1 caractere:2
+ (Get-ItemProperty '\wsl$\Ubuntu\opt\google\chrome\google-chrome').Ver ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...e\google-chrome:String) [Get-ItemProperty], ItemNotFo 
   undException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

2021-01-05 10:50:36 DEBUG Webdrivers System call returned: 
F

Failures:

  1) Person billing items #create adds a billing item for the agency user
     Failure/Error: driven_by :selenium_chrome_headless

     Webdrivers::VersionError:
       Failed to find Chrome version.

Guessing by the: making System call: wslpath -w '/usr/bin/google-chrome' I think it is detecting that I'm running on WSL and instead of just calling the google-chrome binary it's trying to convert the path to the full wsl path and the call it via powershell, which will not work because the chrome I want to use is installed on the Linux OS, not on Windows.

fabioxgn commented 3 years ago

@kapoorlakshya I did some more tests, and the powershell errors were because I didn't have powershell 7.1, I installed that and installed chrome on Windows but this still doesn't work:

2021-01-08 15:01:03 DEBUG Webdrivers Checking current version
2021-01-08 15:01:03 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:03 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-08 15:01:03 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:03 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:03 DEBUG Webdrivers making System call: wslpath -u 'c:\Users\fabio\AppData\Local\Google\Chrome\Application\chrome.exe'
2021-01-08 15:01:03 DEBUG Webdrivers System call returned: /mnt/c/Users/fabio/AppData/Local/Google/Chrome/Application/chrome.exe

2021-01-08 15:01:03 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
2021-01-08 15:01:03 DEBUG Webdrivers System call returned: /mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe

2021-01-08 15:01:03 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files\Google\Chrome\Application\chrome.exe'
2021-01-08 15:01:03 DEBUG Webdrivers System call returned: /mnt/c/Program Files/Google/Chrome/Application/chrome.exe

2021-01-08 15:01:03 DEBUG Webdrivers making System call: wslpath -w '/mnt/c/Program Files/Google/Chrome/Application/chrome.exe'
2021-01-08 15:01:03 DEBUG Webdrivers System call returned: C:\Program Files\Google\Chrome\Application\chrome.exe

2021-01-08 15:01:03 DEBUG Webdrivers making System call: pwsh.exe -command "(Get-ItemProperty 'C:\Program Files\Google\Chrome\Application\chrome.exe').VersionInfo.ProductVersion"
2021-01-08 15:01:04 DEBUG Webdrivers System call returned: 87.0.4280.141

2021-01-08 15:01:04 DEBUG Webdrivers Browser version: 87.0.4280.141
2021-01-08 15:01:04 DEBUG Webdrivers Checking current version
2021-01-08 15:01:04 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:04 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-08 15:01:04 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:04 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:04 DEBUG Webdrivers Checking current version
2021-01-08 15:01:04 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:04 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-08 15:01:05 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:05 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:05 DEBUG Webdrivers making System call: wslpath -u 'c:\Users\fabio\AppData\Local\Google\Chrome\Application\chrome.exe'
2021-01-08 15:01:05 DEBUG Webdrivers System call returned: /mnt/c/Users/fabio/AppData/Local/Google/Chrome/Application/chrome.exe

2021-01-08 15:01:05 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
2021-01-08 15:01:05 DEBUG Webdrivers System call returned: /mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe

2021-01-08 15:01:05 DEBUG Webdrivers making System call: wslpath -u 'c:\Program Files\Google\Chrome\Application\chrome.exe'
2021-01-08 15:01:05 DEBUG Webdrivers System call returned: /mnt/c/Program Files/Google/Chrome/Application/chrome.exe

2021-01-08 15:01:05 DEBUG Webdrivers making System call: wslpath -w '/mnt/c/Program Files/Google/Chrome/Application/chrome.exe'
2021-01-08 15:01:05 DEBUG Webdrivers System call returned: C:\Program Files\Google\Chrome\Application\chrome.exe

2021-01-08 15:01:05 DEBUG Webdrivers making System call: pwsh.exe -command "(Get-ItemProperty 'C:\Program Files\Google\Chrome\Application\chrome.exe').VersionInfo.ProductVersion"
2021-01-08 15:01:05 DEBUG Webdrivers System call returned: 87.0.4280.141

2021-01-08 15:01:05 DEBUG Webdrivers Browser version: 87.0.4280.141
2021-01-08 15:01:05 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:05 DEBUG Webdrivers using cached version as latest: 87.0.4280.88
2021-01-08 15:01:05 DEBUG Webdrivers Latest version available: 87.0.4280.88
2021-01-08 15:01:05 DEBUG Webdrivers A working webdriver version is already on the system
2021-01-08 15:01:05 DEBUG Webdrivers Checking current version
2021-01-08 15:01:05 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:05 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-08 15:01:06 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:06 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:06 DEBUG Webdrivers A working webdriver version is already on the system
2021-01-08 15:01:26 DEBUG Webdrivers Checking current version
2021-01-08 15:01:26 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:26 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-08 15:01:26 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:26 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:26 DEBUG Webdrivers A working webdriver version is already on the system
2021-01-08 15:01:46 DEBUG Webdrivers Checking current version
2021-01-08 15:01:46 DEBUG Webdrivers /home/fabio/.webdrivers/chromedriver.exe is already downloaded
2021-01-08 15:01:46 DEBUG Webdrivers making System call: ["/home/fabio/.webdrivers/chromedriver.exe", "--version"]
2021-01-08 15:01:46 DEBUG Webdrivers System call returned: ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:46 DEBUG Webdrivers Current version of /home/fabio/.webdrivers/chromedriver.exe is ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})

2021-01-08 15:01:46 DEBUG Webdrivers A working webdriver version is already on the system
      copies the link to the clipboard (FAILED - 1)

Failures:

  1) Quotes #index when click on copy link button copies the link to the clipboard
     Got 0 failures and 3 other errors:

     1.1) Failure/Error: visit new_user_session_path

          Selenium::WebDriver::Error::WebDriverError:
            unable to connect to chromedriver 127.0.0.1:9515
fabioxgn commented 3 years ago

But in any case, even fixing the powershell it is now impossible to use chrome on linux when using WSL, because it now correctly detects that it is running on WSL, it defaults to the windows version of chrome and tries to run chrome using powershell, even if you set the WD_CHROME_PATH:

2021-01-08 15:13:57 DEBUG Webdrivers making System call: pwsh.exe -command "(Get-ItemProperty '\\wsl$\Ubuntu\opt\google\chrome\google-chrome').VersionInfo.ProductVersion"
Get-ItemProperty: Cannot find path 'Microsoft.PowerShell.Core\FileSystem::wsl$\Ubuntu\opt\google\chrome\google-chrome' because it does not exist.

My suggestion is to provide a flag to disable this wsl detection, so it can run the linux version of chrome.

changing the wsl? method on system.rb to return false solves my issue as it goes back to using chrome on linux.

kapoorlakshya commented 3 years ago

@fabioxgn Thanks again for all the details and the PR! You are right that Powershell is incorrectly being used to retrieve the version from the Chrome binary on the Linux filesystem, which not only leads to Webdrivers::VersionError, but also sh: 1: pwsh.exe: not found. The sh error does not happen outside of WSL so that's good.

Another approach besides adding the WD_USE_WINDOWS ENV flag (from your PR) is to see if we can use wslpath to check if the path is from the Windows filesystem vs the Linux one. I'll try to take a look at your PR soon and see if there are other options.

fabioxgn commented 3 years ago

@fabioxgn Thanks again for all the details and the PR! You are right that Powershell is incorrectly being used to retrieve the version from the Chrome binary on the Linux filesystem, which not only leads to Webdrivers::VersionError, but also sh: 1: pwsh.exe: not found. The sh error does not happen outside of WSL so that's good.

Another approach besides adding the WD_USE_WINDOWS ENV flag (from your PR) is to see if we can use wslpath to check if the path is from the Windows filesystem vs the Linux one. I'll try to take a look at your PR soon and see if there are other options.

I don't know if what I did in my PR is the best solution, I think it would be best not to add a new config. I'll try some ideas to see if there's a better solution.

fabioxgn commented 3 years ago

@kapoorlakshya I did some more testing and I think we should revert this change: https://github.com/titusfortner/webdrivers/pull/187/files

It doesn't work on WSLv2 and I don't think it was tested on it. WSL2 networking is different from WSL1 and you can't connect from the WSL2 Linux on chromedriver running on Windows using 127.0.0.1:9515, see: https://github.com/microsoft/WSL/issues/4619

So with this changed now it detects that is running on WSL but Selenium can't connect to the chromedriver, so this just doesn't work on WSL2.

Maybe we can revert this and make it more explicity changing the wsl? method to wslv1? and adding to the README that on WSL2 you have to install chrome o Linux. I don't know if anyone goes through all the trouble to configure this port forwarding just to run Chrome on Windows.