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
Try using visit products_path
instead. They do not recommend using absolute URLs in "Gotchas" section of README.
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!!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With