Pablo Fernandez
Pablo Fernandez

Reputation: 287400

Port of the Rails app when running Cucumber tests

Is there a way to get, in the test, the port in which the rails app is running during cucumber test? I tried Capybara.server_port but that's nil.

Thanks.

Upvotes: 3

Views: 3367

Answers (2)

Pablo Fernandez
Pablo Fernandez

Reputation: 287400

When using the selenium driver, the port can be found on:

Capybara.current_session.driver.rack_server.port

and when using the webkit driver, it can be found on:

Capybara.current_session.driver.server_port

Alternative, you can set

Capybara.server_port

to a known value and use that.

Upvotes: 5

Andy Waite
Andy Waite

Reputation: 11076

My understanding is that if you're using rack-test, the default Capybara driver, then there's isn't actually any real web server running to make requests to.

If you want to view your app as Cucumber/Capybara would, then you'd need to start it up manually on a chosen port:

$ RAILS_ENV=test rails s -p 4000

And then have something like this in env.rb:

Capybara.configure do |config|
  config.run_server = false
  config.app_host = "http://localhost:4000"
end

Upvotes: 3

Related Questions