Question

I have an app which uses domains stored in a table to determine certain aspects of the site. If the domain isn't found in the db, an error is generated.

When I test with cucumber normally, I use the domain localhost, and everything works as expected. When I try testing with capybara-webkit and headless (for testing the javascript portions of the site) I get a domain not found error for localhost.

Can anyone tell me how I can determine the domain and port that capybara-webkit and headless are using so that I can make sure that I can insert the info the the tables in advance. Or alternatively, set Capybara in advance instead.

I've tried the following without success (although it all works for my none js/headless tests).

Capybara.app_host = "http://localhost"
Capybara.javascript_driver = :webkit

if Capybara.current_driver == :webkit
  require 'headless'

  headless = Headless.new
  headless.start
end
Was it helpful?

Solution

With a bit of trial and error I found something that works. I stopped using localhost as the reference in the database and used 127.0.0.1 instead. I then amended the code in env.rb as follows.

Capybara.javascript_driver = :webkit

if Capybara.current_driver == :webkit
  require 'headless'

  @headless = Headless.new
  @headless.start
end

Before('@javascript') do
  @javascript = true
end

Capybara.app_host = @javascript.present? ? nil : "http://127.0.0.1"

I realise the @javascript variable is surplus to requirements here, but I use it elsewhere. I'm not sure why it works, but it does!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top