Andy Harvey
Andy Harvey

Reputation: 12653

Why are parallel tests failing with “Selenium::WebDriver::Error::WebDriverError invalid session id”?

I am testing a Rails app on CircleCI. I'm running parallel tests in separate containers.

#.circleci/config.yml
...
jobs:
  build:
    parallelism: 2
    ...

One container always fails with:

Selenium::WebDriver::Error::WebDriverError:
              invalid session id

If I change configuration and only run 1 container, all my tests pass.

I guess I have configured something incorrectly for parallel testing. Can anyone help me to understand why Selenium might be expecting a session that does not exist, and where I should be looking to debug this?

Upvotes: 1

Views: 937

Answers (1)

Duke
Duke

Reputation: 3573

This is a common problem in selenium running in docker env. A way to fix it is use the disable-dev-shm-usage options and change the Capybara server port. Like it:

# ...

Capybara.server_port = 9887 + ENV["CIRCLE_NODE_INDEX"].to_i # In order to create a new server port to each runner

Capybara.register_driver :headless_chrome do |app|
  # ...
  browser_options.args << '--disable-dev-shm-usage'
  # ...
end

Source: https://github.com/grosser/parallel_tests/issues/658#issuecomment-429395002

Upvotes: 3

Related Questions