Showing posts with label Feature Specs. Show all posts
Showing posts with label Feature Specs. Show all posts

Thursday, April 2, 2015

Capybara::Poltergeist::TimeoutError

Timed out waiting for response to {"name":"visit","args":["http://127.0.0.1:54242/"]}. 
It's possible that this happened because something
took a very long time (for example a page load was slow). 
If so, setting the Poltergeist :timeout
 option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Poltergeist - please report it to the issue tracker. (Capybara::Poltergeist::TimeoutError)
While working with Capybara feature specs and Poltergeist, you may have encountered this error before. You also probably tried bumping up the timeout value to no avail. I found a surprisingly easy fix for this issue - update your Poltergeist gem and update PhantomJS to version 2.0! After I did these two things, most of these errors went away.

If you are still having issues after that, read through this issue and see if a solution there helps.

Thursday, March 26, 2015

Using local assets with save_and_open_page

Previously I talked about how to use save_and_open_page with Cucumber. Unfortunately, when you do this it renders an unstyled page. If you add

Capybara.asset_host = 'http://localhost:3000'

to your spec_helper.rb or Capybara config file, save_and_open_page will use your local server's assets - making it much easier to diagnose issues.

Thursday, March 19, 2015

Using save_and_open_page with Cucumber

Capybara has a nice utility method called save_and_open_page that will save the current page's HTML as a temp file and open it in your browser. This method is available by default in Ruby code (for example in an RSpec feature spec). As Cucumber is not direct Ruby, you can't directly say that. Fortunately, you can say

 Then show me the page  

and you'll get the same effect.

Sunday, February 15, 2015

Testing Multiple Attributes of an Input Field

Sometimes in a view or feature spec, you want to test multiple attributes of an input field (or some other field). For example, you might want to test that the input field is a checkbox and is checked, as well as testing that the field has the id #rawr. This is how you would do that in a view spec (feature spec is similar):

 expect(content).to have_css("input[type='checkbox'][checked='checked']#rawr")