Port of the Rails app when running Cucumber tests

妖精的绣舞 提交于 2019-12-10 18:35:44

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/7840428/port-of-the-rails-app-when-running-cucumber-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!