Capybara-webkit tries to open example.com
Asked Answered
I

3

14

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
Interpolation answered 23/12, 2011 at 20:19 Comment(0)
S
13

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

Solidstate answered 24/12, 2011 at 10:23 Comment(2)
Using products_path ends with an error in the first place: Unable to load URL: file:///products (Capybara::Driver::Webkit::WebkitInvalidResponseError) But once I also configure the app_host it starts working. So that's my current configuration: Capybara.run_server = true Capybara.server_port = 7787 Before '@javascript' do Capybara.app_host = "127.0.0.1:#{Capybara.server_port}" end In addition this: emmanueloga.com/2011/07/26/taming-a-capybara.html seesm to resolve some other pitfalls with capybara and rails 3.1Interpolation
Seems the gotchas does not apply to Webkit when talking about absolute URLsPeptone
E
1

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!!

Engud answered 28/2, 2012 at 22:33 Comment(0)
K
1

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.

Kare answered 17/9, 2012 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.