I just had my capybara updated to 2.0, and all of my save_and_open_page calls return an html page without styling. It has the style sheets links properly at the top of the page. When I revert back to capybara 1.3, the styles work again. Anyone know how to fix this, and/or what the problem is?
thanks,
Dave
Update 1.
hack:
I have found a reasonable way to get around the problem following the links recommended by simonmorley:
Capybara Webkit problem
which points to: capybara-screenshot
It involves using the capybara-screenshot gem to get a screenshot of what the page looks like. When you combine it with the save_and_open_page, which generates the html, you can see what it looks like, and see the HTML.
save_and_open_page
Capybara::Screenshot.screenshot_and_open_image
If I could get Capybara::Screenshot.screenshot_and_save_page
to work, then I think that I might have a solution (if the name implies the action I think it does). However, when I try it, I get cannot load such file -- capybara/util/save_and_open_page
Update 2.
!! wait, the screenshot_and_open_image is not working now (no png image created or displayed). !!
Update 3.
Test App:
I created a test app, and posted it at test_capybara_screenshot on Github.
When I run this test app in development, the page come up with the blaring red background style displayed. When I run the tests, the only thing that works for me is the save_and_open_page, except there is no styling.
Note, when I run any tests, I get the following warning:
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
Details of the rspec test:
- The save_and_open_page comes up with a boring white background (no
styling). - the screenshot_and_open_image returns with the error:
Rack::Test capybara driver has no ability to output screen shots. Skipping.
Failure in opening /~/Documents/experiments/test_capybara_screenshot/tmp/capybara/screenshot-2012-11-26-07-48-29.png with options {}: No application found to handle '/~/Documents/experiments/test_capybara_screenshot/tmp/capybara/screenshot-2012-11-26-07-48-29.png'
- The screenshot_and_save_page returns:
An error occurred in an after hook
LoadError: cannot load such file — capybara/util/save_and_open_page
occurred at ~/.rvm/gems/ruby-1.9.3-p125@global/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
Best Answer
Try adding the following to your gem file
save_and_open_page won't work without this I don't believe.
-- Updated --
I've tested this for you and when I used the save and open method, I get the same error. In my set up, this is because my page is referencing:
This happens in Firefox, Chrome and Safari. According to the inspector, none of the files are found.
I haven't looked into this in too much detail and don't have an answer why it's not working. However there are a number of people struggling with this also:
https://github.com/jnicklas/capybara/issues/485
And, a bit more information about capybara and asset precompilation:
https://github.com/jnicklas/capybara/pull/609
And what might be a fix here:
https://groups.google.com/forum/#!msg/ruby-capybara/SBCor8UUj7w/hv97EgUQ1P4J
However, if you just want to see your page you could try this: delete scrap save_and_open_page and change your tests to use javascript. This way, my pages open fine.
Try that and let me know if that helps.
response (From Taylored Web Sites):
I see the page for a few seconds, then it goes away. Is there a way for the browser window to not close?