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

Selenium::WebDriver::Error::WebDriverError #658

Closed
sebyx07 opened this issue Oct 10, 2018 · 8 comments
Closed

Selenium::WebDriver::Error::WebDriverError #658

sebyx07 opened this issue Oct 10, 2018 · 8 comments

Comments

@sebyx07
Copy link

sebyx07 commented Oct 10, 2018

I've also added this

  Capybara.register_driver :chrome do |app|
    capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
        chromeOptions: {
            args: %w[ no-sandbox headless disable-popup-blocking disable-gpu window-size=1920,1080]
        }
    )

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

error trace

   Selenium::WebDriver::Error::NoSuchDriverError:
            invalid session id
              (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.15.0-36-generic x86_64)
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/http/common.rb:84:in `new'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/http/common.rb:84:in `create_response'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/http/default.rb:104:in `request'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/http/common.rb:62:in `call'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/bridge.rb:164:in `execute'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/oss/bridge.rb:584:in `execute'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/remote/oss/bridge.rb:152:in `window_handles'
          # /usr/local/bundle/gems/selenium-webdriver-3.14.1/lib/selenium/webdriver/common/driver.rb:185:in `window_handles'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara/selenium/driver.rb:193:in `window_handles'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara/selenium/driver_specializations/chrome_driver.rb:33:in `reset!'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara/session.rb:126:in `reset!'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara.rb:312:in `block in reset_sessions!'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara.rb:312:in `reverse_each'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara.rb:312:in `reset_sessions!'
          # /usr/local/bundle/gems/capybara-3.8.2/lib/capybara/rspec.rb:18:in `block (2 levels) in <main>'

Is there a way to run the tests parallel?

@grosser
Copy link
Owner

grosser commented Oct 10, 2018

@sebyx07
Copy link
Author

sebyx07 commented Oct 11, 2018

have both of them added, same result

Capybara.default_driver = :chrome
Capybara.ignore_hidden_elements = false

port = 9887 + ENV['TEST_ENV_NUMBER'].to_i
Capybara.server_port = port
Capybara.session_name = port.to_s


if ENV['TEST_ENV_NUMBER']
  class Capybara::Server
    def find_available_port
      @port = 9887 + ENV['TEST_ENV_NUMBER'].to_i
    end
  end
end

Only the first driver, browser starts. the seconds throws the invalid session id

@grosser
Copy link
Owner

grosser commented Oct 11, 2018 via email

@sebyx07
Copy link
Author

sebyx07 commented Oct 12, 2018

Hey, got something that works. had to also configure the driver port.
here is the full config
Selenium::WebDriver::Error::NoSuchDriverError was raise because of insufficient resources, disabled with disable-dev-shm-usage

Capybara.default_driver = :chrome

port = 9887 + ENV["TEST_ENV_NUMBER"].to_i
Capybara.server_port = port

Capybara.register_driver :chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: {
        args: %W(disable-dev-shm-usage disable-infobars disable-extensions no-sandbox headless disable-popup-blocking disable-gpu window-size=1280,1024)
    }
  )

  Capybara::Selenium::Driver.new(app,
                                 {
                                     browser: :chrome,
                                     desired_capabilities: capabilities,
                                     driver_opts: {
                                         port_server: 9515 + ENV["TEST_ENV_NUMBER"].to_i
                                     }
                                 }
  )
end

@sebyx07 sebyx07 closed this as completed Oct 12, 2018
@maniax89
Copy link

maniax89 commented Dec 21, 2018

@sebyx07 i am currently attempting to do something very similar with my setup (using https://github.com/flavorjones/chromedriver-helper)

require 'capybara/rails'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'

Chromedriver::Helper.new.update
Capybara.server_host = "localhost"
test_run_int = (ENV["TEST_ENV_NUMBER"].try(:to_i) || 0)
port = 4000 + test_run_int
Capybara.server_port = port

Capybara.register_driver :headless_chrome do |app|
  browser_options = ::Selenium::WebDriver::Chrome::Options.new()
  browser_options.args << '--no-sandbox'
  browser_options.args << '--window-size=1280,1024'
  browser_options.args << '--disable-dev-shm-usage'
  browser_options.headless!

  Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, driver_opts: {
    port_server: 9515 + test_run_int
  })
end

Capybara::Screenshot.register_driver :headless_chrome do |driver, path|
  driver.browser.save_screenshot(path)
end

Capybara.javascript_driver = :headless_chrome

i just wanted to say that by adding disable-dev-shm-usage I was able to finally get this to work (after many hours of saying "it works locally on macosx, but not on a linux-based docker container")

leaving this here in case anyone else comes across this

@grosser
Copy link
Owner

grosser commented Dec 21, 2018

awesome, thx! :)

@maniax89
Copy link

Yes, I think in my original issue it was all using docker containers (running on some flavor of Linux)

@lmansur
Copy link

lmansur commented Sep 6, 2019

I'm moving an application to a Docker environment, so one of the first steps is running CI in a docker container.

I was running into chrome not reachable error. After following https://github.com/grosser/parallel_tests/wiki#with-capybara040selenium----by-rgo, I started receiving another error (I think it was port related).

Adding disable-dev-shm-usage, as suggested by @maniax89, fixed the remaining errors. Now I can run my entire suite with parallel_test in a Docker container.

Thanks a lot fellas!

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

4 participants