Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 719
mmr Avatar asked Jul 04 '13 00:07

mmr


2 Answers

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

like image 137
luigi7up Avatar answered Oct 18 '22 22:10

luigi7up


Capybara.current_session.driver.server.port
like image 45
Dmitry Semenyuk Avatar answered Oct 18 '22 21:10

Dmitry Semenyuk