54

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

3 Answers 3

96

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Setting Capybara.server_port worked when the selenium integration test ran independent of other integration tests, but failed to change the port when run with other tests, at least in my env. Asking for the port number capybara wanted to use, seemed to work better with running multiple tests. Maybe it would have worked if I changed the port for all tests, instead of letting some choose on their own.
I used to use this solution but it doesn't work anymore with the latest Capybara version. I'm getting this error: NoMethodError: undefined method `rack_server' for #<Capybara::Selenium::Driver:0x007fa371676d00>
Updated for 2.0 (it's even simpler, yay!)
Hi guys I have stupid question: is there way to tell Capybara to lunch a server when running without Selenium => therefore can access host & port in tests where I don't need Selenium ? Thank you.
.@Woahdae does this still work (sorry been away for awhile -- happy to make this the correct answer) but Capybara.current_session.server returns nil for me
|
48

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

Capybara.server_port = 31337

2 Comments

@iafonov, +1 for 31337
I wanted capybara to listen all interfaces so I set the server host ruby Capybara.server_host = '0.0.0.0'
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.