titusfortner / webdrivers

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

Google Chrome on Apple M1 architecture #191

Closed MichaelHoste closed 3 years ago

MichaelHoste commented 3 years ago

Maybe I'm not at the right place to submit this issue. Feel free to close and redirect me.

I have a new Macbook M1, and I installed the M1-specific Google Chrome on my system to avoid using the Rosetta emulation. It works well!

However, when I'm running my test suite, I can see in the Activity Monitor that the headless Chrome is not started with the correct architecture. We can see "Intel" instead of "Apple":

Screenshot 2020-12-30 at 16 32 37

I checked and Google Chrome seems to use Universal Binary, so either Intel or Apple, but the wrong one is started.

Would it be because chromedriver doesn't officially support M1 architecture? [1] And Google Chrome is forced to follow the same architecture?

Is there any way to fix this situation in webdrivers, and force Google Chrome with M1 architecture? It will certainly speed up significantly my test suite.

Or maybe I need to wait when (if?) a M1-specific chromedriver is released?

Any thoughts on this would be welcome πŸ˜„

[1] https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.88/

kapoorlakshya commented 3 years ago

Hmm... I don't have a M1 mac to reproduce this and I am not seeing any new, specific ChromeOptions or CLI switches to pick a specific one in https://peter.sh/experiments/chromium-command-line-switches/

Might be better to create this issue in the chromium issue tracker.

MichaelHoste commented 3 years ago

Thank you for looking at this!

I found a M1 version of chromedriver here (darwin-arm64.zip): https://github.com/electron/electron/releases

I was able to test it, it started the correct Chrome and... holy cow, that was fast! My (parallel) test suite went from 2min20 to 1min30. And only 140 of my 900 specs use the browser. I knew they were the slowest specs but still, that was unexpected.

For reference, my high-end 2018 i7 MacBook ran the specs in 2min30. Apple is not kidding with this new CPU.

I have a naΓ―ve question: would it be possible to compile chromedriver directly with this gem?

Either way, I will open an issue on Chromium to ask for an ARM64 version.

Have a great New Year!

kapoorlakshya commented 3 years ago

I found a M1 version of chromedriver here (darwin-arm64.zip): https://github.com/electron/electron/releases

Nice! I am not seeing the darwin-arm64 version officially listed for v88 or v89 (beta), so let us know what you find out from the Chromium team. If they're not responsive then we could consider fetching it from that electron release page you shared until an official release is available.

My (parallel) test suite went from 2min20 to 1min30.

Wow that's really good.

would it be possible to compile chromedriver directly with this gem?

Nope. The gem simply reaches out to the download servers and fetches the binary matching your browser version.

I'll keep this issue open until we have implemented support for the M1 specific chromedriver.

rubiety commented 3 years ago

I also had success getting Chrome invoked natively (arm64) when using Electron v11.1.1's chromedriver build for darwin-arm64 and putting it in ~/.webdrivers/chromedriver.

However, unlike the original x86 one installed, for some reason this build was not able to find my Google Chrome application binary:

Selenium::WebDriver::Error::UnknownError:
  unknown error: cannot find Chrome binary
    (Driver info: chromedriver=87.0.4280.88 (b66d19be4d887361d1cfaa4bf22fe2cdc2361496-refs/heads/master@{#829380}),platform=Mac OS X 11.0.0 arm64)

I was able to fix this by manually specifying the binary path on my machine with something like this, in the context of capybara / selenium webdriver (where SELENIUM_CHROME_BINARY_PATH is set in my .env):

Capybara.register_driver :headless_chrome do |app|
  client = Selenium::WebDriver::Remote::Http::Default.new
  client.read_timeout = 240

  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: {
      args: %w(headless disable-gpu window-size=1440,900),
      prefs: chrome_preferences,
      w3c: false,
      binary: ENV["SELENIUM_CHROME_BINARY_PATH"]
    }
  )

  Capybara::Selenium::Driver.new(app,
    browser: :chrome,
    desired_capabilities: capabilities,
    http_client: client
  )
end

For me, capybara feature specs are running about 20% faster under native arm64 Chrome / chromedriver.

MichaelHoste commented 3 years ago

I opened an issue on the Chromium bugtracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1162906

Feel free to upvote it to increase the chances someone sees it (62361 opened issues πŸ˜„ ).

@rubiety: for some reason this build was not able to find my Google Chrome application binary

I had the same issue with the path to Chrome, maybe Electron built the binary with another default path? I fixed it by using this line:

Selenium::WebDriver::Chrome.path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

@rubiety: For me, capybara feature specs are running about 20% faster under native arm64 Chrome / chromedriver.

I have noticed that in my case, the improvements were way better using multi-core than single-core. Are you already using something like https://github.com/grosser/parallel_tests ?

@kapoorlakshya: If they're not responsive then we could consider fetching it from that electron release page you shared until an official release is available. I'll keep this issue open until we have implemented support for the M1 specific chromedriver.

Thank you! It's really appreciated! πŸ‘

MichaelHoste commented 3 years ago

I just found out that ChromeDriver uses a separate bugtracker, and a similar ticket is already open: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3688

Thanks for reporting the issue. We have plan to release the ChromeDriver binary that would supports Apple m1 early next year. It would be a separate binary.

πŸŽ‰

kapoorlakshya commented 3 years ago

@MichaelHoste That's good to know. I have left a comment in that ticket. Thanks!

MichaelHoste commented 3 years ago

I just opened a pull request to be able to download the correct chromedriver for your Mac from the official storage (like this one: https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.88/).

Apparently, with the official M1 chromedriver version, it's not anymore needed to define the Google Chrome path manually like described by @rubiety or myself. It just works! 🍾

pawelnguyen commented 3 years ago

Thanks a lot Michael for fixing that! πŸŽ‰

In case someone ends up here trying to switch their Intel chromedriver to M1 chromedriver to speed up tests like I did - you need to delete the existing driver and the new one will be downloaded. In my case it shaved off 40% of test run time. https://github.com/titusfortner/webdrivers#chrome-and-edge-on-apple-m1-arm64

danilokleber commented 2 years ago

Hi. I don't know if I'm doing anything wrong but chromedriver appears in Activity Monitor as Intel and not Apple (also the logs are saying so). I removed everything in ~/.webdrivers before running tests for the matter.

Debug Info

Webdrivers version: 4.6.1 Ruby version: 2.4.10 Operating system / CI Environment: macOS 12.5 Browser and version: Chromium version 104.0.5112.81 (Official Build, ungoogled-chromium) (arm64)

Debug Output

2022-08-16 16:19:37 DEBUG Webdrivers Checking current version
2022-08-16 16:19:37 DEBUG Webdrivers /Users/bytes/.webdrivers/chromedriver is not already downloaded
2022-08-16 16:19:37 DEBUG Webdrivers Selenium::WebDriver::Chrome.path: /Applications/Chromium.app/Contents/MacOS/Chromium
2022-08-16 16:19:37 DEBUG Webdrivers making System call: ["/Applications/Chromium.app/Contents/MacOS/Chromium", "--version"]
2022-08-16 16:19:37 DEBUG Webdrivers System call returned: Chromium 104.0.5112.81

2022-08-16 16:19:37 DEBUG Webdrivers Browser version: Chromium 104.0.5112.81
2022-08-16 16:19:37 DEBUG Webdrivers Selenium::WebDriver::Chrome.path: /Applications/Chromium.app/Contents/MacOS/Chromium
2022-08-16 16:19:37 DEBUG Webdrivers making System call: ["/Applications/Chromium.app/Contents/MacOS/Chromium", "--version"]
2022-08-16 16:19:37 DEBUG Webdrivers System call returned: Chromium 104.0.5112.81

2022-08-16 16:19:37 DEBUG Webdrivers Browser version: Chromium 104.0.5112.81
2022-08-16 16:19:37 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_104.0.5112
2022-08-16 16:19:37 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2022-08-16 16:19:37 DEBUG Webdrivers Latest version available: 104.0.5112.79
2022-08-16 16:19:37 DEBUG Webdrivers Apple architecture: Intel (mac64)
2022-08-16 16:19:37 DEBUG Webdrivers chromedriver version is NOT Apple M1 compatible. Required >= 87.0.4280.88
2022-08-16 16:19:37 DEBUG Webdrivers chromedriver URL: https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_mac64.zip
2022-08-16 16:19:37 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_mac64.zip
2022-08-16 16:19:38 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2022-08-16 16:19:38 DEBUG Webdrivers Successfully downloaded /var/folders/dz/3r5lkh5d1y39h26ht91x36lr0000gn/T/20220816-91087-1rke9avchromedriver_mac64.zip
2022-08-16 16:19:38 DEBUG Webdrivers Decompressing /var/folders/dz/3r5lkh5d1y39h26ht91x36lr0000gn/T/20220816-91087-1rke9avchromedriver_mac64.zip
2022-08-16 16:19:38 DEBUG Webdrivers Completed download and processing of /Users/bytes/.webdrivers/chromedriver

Thanks for any help.