titusfortner / webdrivers

Keep your Selenium WebDrivers updated automatically
MIT License
592 stars 113 forks source link

Support for chromium-chromedriver on ARM64? #244

Closed davetron5000 closed 1 year ago

davetron5000 commented 1 year ago

Summary

On Linux ARM64, webdrivers installs the X64 chromedriver which doesn't work. As there is no official ARM64 chromedriver (because there is no ARM64 chrome for linux), this leaves me in a pickle as to how to make this work.

One can get chromium-chromedriver for arm64, but this gem doesn't not provide a way to control what chromedriver executable is being used.

I'm posting this to 1) see if there is a way to fix this and 2) document how I was able to get it working via monkeypatching for others.

Debug Info

Please provide the following information for bug reports:

Expected Behavior

Either the gem uses the arm64 chromium and chromium-chromedriver or allows me to override its settings for chromedriver to use what i have installed.

Actual Behavior

With DEBUG logging:

2023-01-26 22:40:39 DEBUG Webdrivers Checking current version
2023-01-26 22:40:39 DEBUG Webdrivers /root/.webdrivers/chromedriver is already downloaded
2023-01-26 22:40:39 DEBUG Webdrivers making System call: ["/root/.webdrivers/chromedriver", "--version"]
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
2023-01-26 22:40:39 DEBUG Webdrivers Checking current version
2023-01-26 22:40:39 DEBUG Webdrivers /root/.webdrivers/chromedriver is already downloaded
2023-01-26 22:40:39 DEBUG Webdrivers making System call: ["/root/.webdrivers/chromedriver", "--version"]
qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

Workaround

For me, chromium-chromedriver installs in /usr/bin/chromedriver, so this is what I did:

# In my case, a rails app, this is at the top of `test/application_system_test_case.rb`
Webdrivers.logger.level = :DEBUG
module Webdrivers
  class Common
    class << self
      def driver_path
        "/usr/bin/chromedriver"
      end

      def correct_binary? # prevent it ever trying to download into /usr/bin
        true
      end
    end
  end
end

It also works to set WD_INSTALL_DIR to /usr/bin (in my case), but you still need to keep it from trying to update there

I'm glad I can make it work, but I don't actually want webdrivers to install anything. I just need it to bridge the rails system tests and chromium installation by using what I have already set up, so something like:

Webdrivers.chromedriver = "/usr/bin/chromedriver"

would be great.

Edit to clarify correct_binary? and preventing downloading new versions

titusfortner commented 1 year ago

Downloading new versions is the primary purpose of this gem. Your monkey patch is pretty much just turning off the gem. I'd recommend not using this gem and setting the location of the driver in Selenium directly:

Selenium::WebDriver::Chrome::Service.driver_path = "/usr/bin/chromedriver"

As for linux arm64 support, electron provides a driver, and support for it was requested in #242. As I mentioned there, though, we're working to get things implemented in Selenium itself so all Selenium languages can benefit. (https://github.com/SeleniumHQ/selenium/issues/11357).

davetron5000 commented 1 year ago

OK, that makes sense. Can confirm your solution works i.e. removing this gem and using that line of configuration. How did you know to do that? I have been over the Web driver docs and cannot where this is documented. I can find it in the source code, but would not have known what it was. If there aren't docs I'm happy to provide, but I'm not sure where they should go ( here? https://www.selenium.dev/documentation/webdriver/drivers/service/ )

titusfortner commented 1 year ago

I know to do that because I implemented the code in Selenium to better support this gem. 😄

The line of code is there at the bottom of the file so that it always executes just by requiring the gem. It's implemented with a proc so that the code only executes when Selenium goes to start that specific driver. It's a step up from the previous driver helper gems that used shims for storing drivers.

Building the driver support into selenium itself is going to be another big step up. It will manage both browser and driver version downloads and settings for everything will be parsed from the browser options class.