titusfortner / webdrivers

Keep your Selenium WebDrivers updated automatically
MIT License
595 stars 110 forks source link

Gitlab CI fails when running Capybara tests #126

Closed 8vius closed 5 years ago

8vius commented 5 years ago

I get several different errors when trying to use selenium with the Gitlab CI, I have to retry several times to get my tests to pass. These are the errors I get:

Selenium::WebDriver::Error::WebDriverError: invalid session id Errno::ECONNREFUSED: Failed to open TCP connection to 127.0.0.1:9515

This is the config I have for my tests:

Webdrivers.cache_time = 86_400

if ENV["CI"]
  Webdrivers::Chromedriver.required_version = "74.0.3729.6"
else
  Webdrivers::Chromedriver.update
end

Capybara.register_driver :headless_chrome do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new

  options.add_argument("--headless")
  options.add_argument("--no-sandbox")
  options.add_argument("--disable-gpu")
  options.add_argument("window-size=2560x2560")
  options.add_argument("disable-dev-shm-usage") if ENV['CI']

  Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.javascript_driver = :headless_chrome

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  include Devise::Test::IntegrationHelpers

  driven_by :headless_chrome, screen_size: [1280, 2400], options: {}
end
titusfortner commented 5 years ago

Please verify the version of Chrome being used. The most likely issue is that you are hard coding a chromedriver version for a system that has updated to Chrome v75.

8vius commented 5 years ago

@titusfortner thanks, I'll give it a check.

8vius commented 5 years ago

Just checked it's still on version 74.

AxelTheGerman commented 5 years ago

I'm having the same issue after chrome being upgraded to 75 - but I forced chromedrivers as well

$ google-chrome --version
Google Chrome 75.0.3770.80 
$ bundle exec rake webdrivers:chromedriver:update[75.0.3770.8]
The HashDiff constant used by this gem conflicts with another gem of a similar name.  As of version 1.0 the HashDiff constant will be completely removed and replaced by Hashdiff.  For more information see https://github.com/liufengyun/hashdiff/issues/45.
2019-06-05 22:00:03 INFO Webdrivers Updated to chromedriver 75.0.3770.8

Also:

$ rake webdrivers:chromedriver:update The HashDiff constant used by this gem conflicts with another gem of a similar name. As of version 1.0 the HashDiff constant will be completely removed and replaced by Hashdiff. For more information see https://github.com/liufengyun/hashdiff/issues/45. 2019-06-05 14:41:18 INFO Webdrivers Updated to chromedriver 2.41.578700

titusfortner commented 5 years ago

Validate with the log: Webdrivers::Logger.level = :debug to see what versions the gem is finding and comparing.

You can either specify the path of Chrome you want to use (Selenium::WebDriver::Chrome.path = '/path/to/chrome') or webdrivers gem will locate the Chrome browser that chromedriver will be using by default and reference that.

webdrivers:chromedriver:update will install the latest version that matches the version of Chrome you are using. It will use 2.41 if the version of Chrome it finds is less than v70 (https://github.com/titusfortner/webdrivers/blob/master/lib/webdrivers/chromedriver.rb#L32).

chromedriver version has to be the exact version string without the last digit

This is only if you are specifying it yourself. I think we could add some extra logic to find the latest driver for a specific major version, but this isn't something we are encouraging people to do, so if you want to go that route, you should be able to figure out exactly the one you want.

rylanb commented 5 years ago

I'm getting failures sort of without any correlation I can make to a gem update or our app starting yesterday around 1pm Mountain time. I don't know if they are related to Webdrivers but maybe a chrome/driver update instead?

Errors like:

Selenium::WebDriver::Error::ElementClickInterceptedError: element click intercepted: Element and

Capybara::Ambiguous: Ambiguous match

When we haven't updated anything around the test gems or those tests in a long time.

Just putting in my two cents to see if there is someone who knows more about it.

I tried updating the Selenium container version on Circle CI to 3.141.5, but no change there. I'm unsure that it is even being used, though.

Thanks for this gem, btw!

titusfortner commented 5 years ago

@rylanb this looks like a different issue. Chrome 75 was released yesterday and defaults to w3c: true, which is going to have some different behaviors to make it more cross-browser compatible. Those issues will not be webdrivers related.

rylanb commented 5 years ago

@titusfortner yup, very likely! I was more providing another data point in case that helped anyone with troubleshooting things and also to gather any salient data like the Chrome 75 with w3c: true! Thanks!

sharkeyryan commented 5 years ago

After the auto update of Chrome in my gitlab ci to version 75.0.3770.8 I was running into the following error:

Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

I Included the following in my rails_helper.rb to override the use of the new chromedriver 75 and instead use the old 74.0.3729.6 version. Tests are now passing with Chrome 75 installed:

require "webdrivers/chromedriver" Webdrivers.cache_time = 1 Webdrivers::Chromedriver.required_version = '74.0.3729.6'

Hope this helps someone.

victorhazbun commented 5 years ago

@sharkeyryan I was experimenting the same issue, now my TravisCI is passing. Thanks.

Important note: These options are mandatory no-sandbox headless disable-gpu.

My setup:

require "selenium/webdriver"
require "webdrivers/chromedriver"

Webdrivers::Chromedriver.required_version = "74.0.3729.6"

Capybara.server = :puma, { Silent: true }

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: {
      args: %w(no-sandbox headless disable-gpu window-size=1280,800),
    },
  )

  Capybara::Selenium::Driver.new app,
    browser: :chrome,
    desired_capabilities: capabilities
end

Capybara.javascript_driver = :headless_chrome
twalpole commented 5 years ago

Closing this since most peoples issues appear to have been fixed and other appear to be more about the chromedriver 75 update and not this gem. If anyone is still having an issue they believe is caused by this gem please open a new issue with enough data to replicate the issue.