Skip to content
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

Gitlab CI fails when running Capybara tests #126

Closed
8vius opened this issue Jun 5, 2019 · 11 comments
Closed

Gitlab CI fails when running Capybara tests #126

8vius opened this issue Jun 5, 2019 · 11 comments

Comments

@8vius
Copy link

8vius commented Jun 5, 2019

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
Copy link
Owner

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
Copy link
Author

8vius commented Jun 5, 2019

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

@8vius
Copy link
Author

8vius commented Jun 5, 2019

Just checked it's still on version 74.

@AxelTheGerman
Copy link

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:

  • why does the chromedriver version has to be the exact version string without the last digit - doesn't make any sense to me (but prob a chromedriver issue)
  • I assumed webdrivers:chromedriver:update would install the latest version - doesn't seem to be the case?
$ 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 14:41:06 INFO Webdrivers Updated to chromedriver 75.0.3770.8

$ 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
Copy link
Owner

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
Copy link

rylanb commented Jun 6, 2019

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
Copy link
Owner

@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
Copy link

rylanb commented Jun 6, 2019

@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
Copy link

sharkeyryan commented Jun 7, 2019

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
Copy link

victorhazbun commented Jun 10, 2019

@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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants