Capybara, Rails, Selenium, Chromedriver + ERR:CONNECTION_REFUSED

Viewed 2413

I'm setting up Capybara with Selenium Webdriver in my Rails application, and I keep running into the following error:

Helpdesk Ticketing System assigning a ticket should mark ticket as assigned
     Failure/Error: visit tickets_path
     
     Selenium::WebDriver::Error::UnknownError:
       unknown error: net::ERR_CONNECTION_REFUSED
         (Session info: chrome=85.0.4183.102)

My settings are as follows:

Capybara.server = :puma
Capybara.app_host = 'http://intranet.lvh.me'
Capybara.default_driver = :selenium_chrome_headless

In the logs it shows this before the failure, choosing a different port each time it runs:

Capybara starting Puma...
* Version 4.3.6 , codename: Mysterious Traveller
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:56277

Anyone help?

2 Answers

I solved my problem. I was missing:

Capybara.always_include_port = true

I had set route-level URL defaults inside of environments/test.rb and that option pulls through to all parts of the application.

When I removed the line shown below, all my tests passed again.

# environments/test.rb
Rails.application.routes.default_url_options = { 
  host: "server.localhost", 
  port: 3000 
}
Related