-
Notifications
You must be signed in to change notification settings - Fork 111
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
Migrating from chromedriver-helper (Heroku production) #72
Comments
Hi @hwhelchel, your issue reminds me of this related thread where setting Give it a try and if it doesn't work, we can troubleshoot this further. Edit: This will make sure that the downloaded chromedriver is compatible with the Chrome version on Heroku. |
@kapoorlakshya thanks I'm going to try this |
@kapoorlakshya hmm still not able to get it to work on Heroku. Still hanging with message:
I added this line: in the conditional block: if chrome_bin = ENV["GOOGLE_CHROME_SHIM"]
options.add_argument "--no-sandbox"
options.binary = chrome_bin
Selenium::WebDriver::Chrome.path = chrome_bin
end Context: class Browser::Builder
attr_reader :downloads
def self.call(downloads: false)
new(downloads: downloads).call
end
def initialize(downloads: false)
@downloads = downloads
end
def key
@key ||= object_id
end
def number
@number ||= rand(1..20_000)
end
def call
options = Selenium::WebDriver::Chrome::Options.new
# make a directory for chrome if it doesn't already exist
chrome_dir = File.join Dir.pwd, ["tmp", "chrome#{key}"]
FileUtils.mkdir_p chrome_dir
user_data_dir = "--user-data-dir=#{chrome_dir}"
# add the option for user-data-dir
options.add_argument user_data_dir
# let Selenium know where to look for chrome if we have a hint from
# heroku. chromedriver-helper & chrome seem to work out of the box on osx,
# but not on heroku.
if chrome_bin = ENV["GOOGLE_CHROME_SHIM"]
options.add_argument "--no-sandbox"
options.binary = chrome_bin
Selenium::WebDriver::Chrome.path = chrome_bin
end
# headless!
options.add_argument "--window-size=2048x1080"
options.add_argument "--headless"
options.add_argument "--disable-gpu"
options.add_argument "--disable-dev-shm-usage"
options.add_argument "--port=#{9514 + number}"
# make the browser
browser = Watir::Browser.new :chrome, options: options
# setup downloading options
if downloads
# make download storage directory
downloads_dir = File.join Dir.pwd, ["tmp", "downloads#{key}"]
FileUtils.mkdir_p downloads_dir
# tell the bridge to use downloads
bridge = browser.driver.send :bridge
path = "/session/#{bridge.session_id}/chromium/send_command"
params = { behavior: "allow", downloadPath: downloads_dir }
bridge.http.call(:post, path, cmd: "Page.setDownloadBehavior",
params: params)
end
browser
end
end |
@hwhelchel Which version of Chrome are you using on Heroku? Since this works with Webdrivers::Chromedriver.version = '2.46' |
@kapoorlakshya thanks for the suggestion. I'm trying out browserless.io right now. If I revert to running on Heroku will try this! Hopefully if others have this same problem they can come to this issue and get some help. Again thank you for your help. |
Sounds good! Closing this issue for now. Feel free to revive it if/when needed. |
Hi @kapoorlakshya, I just upgraded and am having the same issue. Setting |
Hi @rgalanakis, which version of Chrome are you using on Heroku, and what does |
I assume that, after the pin, I am using 2.46 on Heroku. Before that, I believe 73- the Heroku buildpack downloads their latest stable release: https://github.com/heroku/heroku-buildpack-chromedriver which: /app/.apt/usr/bin/google-chrome |
The stable is 74 now, so that's probably being used for Try setting |
No dice- adding that and removing the |
@rgalanakis Hmm... okay. I just read the README for
The location above and what Webdrivers.logger.level = :DEBUG
Selenium::WebDriver::Chrome.path = '/app/.apt/usr/bin/google-chrome' And if you're using Capybara or Watir, set the binary path in options to |
Also running into the same issue - if the version is not explictly set, the test suite hangs with the |
Hi @rubendinho, did you already attempt what I shared above? |
@rgalanakis Let's also set the Selenium logging level to |
@kapoorlakshya I tried setting the path inside the Heroku CI debug console and that did not fix anything. The only way I've been able to stop it from hanging and execute my tests is by explicitly setting the version to the latest stable version - "74.0.3729.6" as of this writing. Possibly related: heroku/heroku-buildpack-google-chrome#70 |
I'm running into the same problem. I tried setting up the path, changing the version, and explicitly setting the version to the latest stable. Nothing has worked for me so far. I have more information and logs about it in heroku/heroku-buildpack-google-chrome#70 |
@rubendinho Can you check what I don't have access to Heroku CI (using free account), so I'll have to completely rely on you all for the information we need to troubleshoot this. @neosepulveda I looked at the log in heroku/heroku-buildpack-google-chrome#70 (comment) and you have both the chromedriver buildpack and webdrivers gem included. Let's only use Also, your logs don't have this portion (example from my machine) which tells us that the driver is actually not being downloaded for some reason:
Let's set |
The same problem happens on normal Heroku dynos, outside of CI. You can test it on 1 - Create a new project, put I did that test and got this:
As you can see, it hangs on Devtool instead of returning so my code can continue. So I aborted and tried again:
Hope this helps. My app relies on Selenium in production to generate website screenshots so I'm definitely interested in seeing this problem fixed. |
I'm taking a wild guess here, since I don't know how webdrivers actually works, but Heroku only allows writing to a few directories (such as $HOME and /tmp), so webdrivers might be silently failing the download because it doesn't have permission to write in the directory it expect to be able to. Also, strangely, when I try to get the product version from chrome I instead get a prompt about DevTools:
|
@brenogazzola Can you hop on Slack? I would also like to see this issue resolved as well. It's a strange one. |
@kapoorlakshya Tried to, but it expects me to have @seleniumhq.org, @slack-corp.com, or @saucelabs.com emails to allow me to create an account, which I don't have. |
@brenogazzola Try the Slack link from here instead - https://seleniumhq.herokuapp.com. Once you are in, join the |
Thanks to @brenogazzola and his Heroku setup, we've figured out the problem. The problem is that the shim responds to I looked at the code for We were able to successfully download the correct Selenium::WebDriver::Chrome.path = ENV.fetch('GOOGLE_CHROME_BIN', nil)
options = Selenium::WebDriver::Chrome::Options.new
options.binary = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
driver = Selenium::WebDriver.for :chrome, options: options I have documented this in the wiki - https://github.com/titusfortner/webdrivers/wiki/heroku-buildpack-google-chrome |
Thanks @kapoorlakshya for resolving this issue so quickly. One quick question, in terms of best practises, where would be the best place to add the configuration code above? Thank you |
@neosepulveda I am not sure if there is an official best practice for this, but I would do it right before browser initialization to keep the driver and browser related code close together. |
On a rails app, I'm still having issues with this setup on Heroku Before RSpec.configure I did add the following Webdrivers.cache_time = 86_400
require 'webdrivers'
# From : https://github.com/titusfortner/webdrivers/issues/72
if ENV.fetch('GOOGLE_CHROME_BIN', nil)
Selenium::WebDriver::Chrome.path = ENV.fetch('GOOGLE_CHROME_BIN', nil)
options = Selenium::WebDriver::Chrome::Options.new
options.binary = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
driver = Selenium::WebDriver.for :chrome, options: options
end
Capybara.register_driver(:chrome) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu] }
)
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: capabilities
)
end During Rspec configure : config.before(:each, type: :system, js: true) do
# Chrome driver, visible , good for debugging
# driven_by :selenium_chrome
# Default driver: headless.
driven_by :chrome
end And it still fails listening forever to ws://127.0.0.1:9222/devtools/browser/bc537da7-79e6-4443-9f89-fc297c94a113 Tried a lot of different setups with no avail.. Any tip would be appreciated ! |
Hi @thomasdarde, please set |
@thomasdarde Maybe Rspec is overwriting your configuration when starting? Is there a good point, just before the test suit opens the browser, where you can have the test suit print |
Thanks a lot for the replies ! Here is the updated code : Webdrivers.cache_time = 86_400
puts "setting debug level for webdrivers logger"
puts "GOOGLE_CHROME_BIN is: #{ENV.fetch('GOOGLE_CHROME_BIN', nil)} "
puts "GOOGLE_CHROME_SHIM is: #{ENV.fetch('GOOGLE_CHROME_SHIM', nil)} "
puts "--product-version : #{`/app/.apt/opt/google/chrome/chrome --product-version`} "
Webdrivers.logger.level = :DEBUG
require 'webdrivers'
# From : https://github.com/titusfortner/webdrivers/issues/72
if ENV.fetch('GOOGLE_CHROME_BIN', nil)
Selenium::WebDriver::Chrome.path = ENV.fetch('GOOGLE_CHROME_BIN', nil)
options = Selenium::WebDriver::Chrome::Options.new
options.binary = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
driver = Selenium::WebDriver.for :chrome, options: options
end and the output
|
So the issue was found : GOOGLE_CHROME_BIN was set as an env var to another value (/app/.apt/usr/bin/google-chrome) in the CI due to an old configuration... In the end, this is my (working) config (Rspec/capybara/webdrivers) : At the beginning of the rails_helper: Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } The file spec/support/capybara_webdrivers.rb Webdrivers.cache_time = 86_400
# Some help to debug on CI
# puts "--product-version : #{`/app/.apt/opt/google/chrome/chrome --product-version`} "
# Webdrivers.logger.level = :DEBUG
require "webdrivers"
chrome_shim = ENV.fetch("GOOGLE_CHROME_SHIM", nil)
chrome_bin = ENV.fetch("GOOGLE_CHROME_BIN", nil)
# From : https://github.com/titusfortner/webdrivers/issues/72
Selenium::WebDriver::Chrome.path = chrome_bin if chrome_bin
chrome_args = {args: %w[headless disable-gpu window-size=1280,1024]}
selenium_options = Selenium::WebDriver::Chrome::Options.new(chrome_args)
selenium_options.binary = chrome_shim if chrome_shim
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome, options: selenium_options
)
end
# Silent puma in logs
Capybara.server = :puma, { Silent: true } |
@thomasdarde Glad you figured it out. It got stuck on the DevTools listening line because it was attempting to extract the |
) This change adds out-of-the-box compatibility with the webdrivers gem, which apparently quite a few Heroku users are using. Currently, the users have to use a workaround in their project to get the Chrome version from $GOOGLE_CHROME_BIN, so that webdrivers can download the appropriate version of chromedriver, and then switch back to $GOOGLE_CHROME_SHIM to launch Chrome. See titusfortner/webdrivers#40, titusfortner/webdrivers#72, and titusfortner/webdrivers#134. This simple change will provide the convenience of not needing any hacks to make the two work :).
The latest version of the google-chrome buildpack no longer needs the workaround described here. We've updated the SHIM to support |
I use Watir and chromedriver-helper for parallel chrome headless execution on Heroku.
This configuration has worked well for
chromedriver-helper
. Just tried migrating towebdrivers
and now when I callbrowser = Watir::Browser.new :chrome, options: options
The app hangs with this message
DevTools listening on ws://127.0.0.1:9222/devtools/browser/ec46578f-304d-4a11-8441-fee4092aebac
Does anyone have a similar setup or advice on how I can get
webdrivers
andwatir
to work together on Heroku?The text was updated successfully, but these errors were encountered: