Cucumber / Capybara — how to get the host and port of the current execution

不想你离开。 提交于 2019-12-17 16:24:19

问题


I need to download a csv file from my app using Open::URI and to do that I need to give it a fully qualified URI. So whats the best way to get the HOST and more importantly PORT in my cucumber script?

Note I am using Capybara and Selenium


回答1:


You can set port that will be used to spawn an application server

Capybara.server_port = 31337



回答2:


For capybara < 2.0:

Capybara.current_session.driver.rack_server.host
Capybara.current_session.driver.rack_server.port

Capybara 2.0:

Capybara.current_session.server.host
Capybara.current_session.server.port

FYI, my use case is having clickable links in the mail generated by the integration tests.




回答3:


You can use current_host but I don't know if it contains the port. Alternatively you can use current_url and strip the path (and possibly the query string).



来源:https://stackoverflow.com/questions/6791601/cucumber-capybara-how-to-get-the-host-and-port-of-the-current-execution

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