Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara-webkit tries to open example.com

I'm using capybara, capybara-webkit, capybara-screenshot together with cucumber. (Ruby 1.9.3, Rails 3.1.3) and Capybara.javascript_driver = :webkit is also set env.rb

Unfortunately running a cucumber spec with @javascript will never succeed for some reason and the error screenshots just capture example.com.

The URL which I actually try to open is generated with a rails router result for one of my models e.g. with visit products_url

So how can I avoid that it ends up querying example.com?

Any input is very welcome.


Just because the comment is messed up - here's what I found was the solution:

Capybara.run_server = true
Capybara.server_port = 7787
Before '@javascript' do
  Capybara.app_host = "http://127.0.0.1:#{Capybara.server_port}"
end
like image 925
pagid Avatar asked Dec 23 '11 20:12

pagid


3 Answers

Try using visit products_path instead. They do not recommend using absolute URLs in "Gotchas" section of README.

like image 123
KL-7 Avatar answered Oct 21 '22 23:10

KL-7


For me, there was a much sneaker "gotcha" (and I was using Capybara with Rspec). Originally in a spec I had:

visit "foos/5"

This worked fine with Rack::Test but when I wanted to switch to the webkit driver to test js interactions, I got that exception (Unable to load URL: file:///products (Capybara::Driver::Webkit::WebkitInvalidResponseError)).

What I had to do was change the path I passed to visit, like so:

visit "/foos/5"

Succes!!

like image 38
steve Avatar answered Oct 21 '22 21:10

steve


Here's another potential gotcha, posted for others that might have this issue. I was testing action caching, and the key Rails generates looks like "views/www.example.com/products". This happens even if you use products_path as the url. This can lead to the need to set your server name so you can know in advance what cache key to expect.

like image 1
Dave Gantenbein Avatar answered Oct 21 '22 22:10

Dave Gantenbein