Cucumber / Capybara — how to get the host and port

2019-01-14 19:56发布

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

3条回答
何必那么认真
2楼-- · 2019-01-14 20:29

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).

查看更多
唯我独甜
3楼-- · 2019-01-14 20:30

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-14 20:40

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

Capybara.server_port = 31337
查看更多
登录 后发表回答