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 

3 Answers 3

13

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.1
Seems the gotchas does not apply to Webkit when talking about absolute URLs
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!!

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.