How can I get the current hostname and port when running Capybara with Poltergeist? [duplicate]
Asked Answered
D

2

13

I have a test program that mimics a user's iOS device by sending chunks of data to a rails server. This program works fine outside of testing. Inside of testing, the program immediately times out since it cannot find the server.

My configuration, in env.rb:

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.server_port = 3123
Capybara.app_host = "http://0.0.0.0:3123"

Inside the test, I've tried things like

puts Capybara.current_session.current_host
puts Capybara.current_session.current_url

and so forth, but those are all blank. Doing:

puts Capybara.current_session

produces a memory address, so I know that the current session is working.

This is with Capybara set up like so in the gemfile:

gem 'capybara', '~> 2.0.2

I've seen several questions based on this, but their answers just don't work for me. Specifically, Capybara does not appear to be setting the current host or url as I've specified, nor is it actually allowing me to see the contents of the current session. So how can I fix this and specify a particular port and url?

Dodecanese answered 4/7, 2013 at 0:5 Comment(0)
E
20

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

I found the answer here: Cucumber / Capybara -- how to get the host and port of the current execution

Emperor answered 14/12, 2014 at 9:48 Comment(1)
I assume you're right, but I haven't tested the response. I'm no longer on this project :)Dodecanese
G
2
Capybara.current_session.driver.server.port
Greenling answered 12/3, 2014 at 9:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.