ReferenceError: Can’t find variable: jQuery with Poltergeist/Capybara

If jQuery is on the page you most likely have to use an evaluate function to enter the context of the page. CasperJS has this diagram http://docs.casperjs.org/en/latest/_images/evaluate-diagram.png http://phantomjs.org/api/webpage/method/evaluate.html The execution is sandboxed, the web page has no access to the phantom object and it can’t probe its own setting.

Chromedriver / Capybara Too many open files – socket(2) for “127.0.0.1” port 9518

If you’re using WebMock in your specs, then add the following to your rails_helper.rb: WebMock.allow_net_connect!(net_http_connect_on_start: true) or WebMock.disable_net_connect!(net_http_connect_on_start: true) source: https://github.com/bblimke/webmock/blob/master/README.md#connecting-on-nethttpstart

Is it possible to take a screenshot of the whole page with Selenium/Capybara?

In case anyone washed up this shore looking for how to do this with Poltergeist you just need to pass the full argument: page.save_screenshot(‘screen.png’, full: true) # If providing a custom file name. page.save_screenshot(full: true) # Capybara sets a name based on timestamp. page.save_and_open_screenshot(‘screen.png’, full: true) # Same as save_screenshot. page.save_and_open_screenshot(full: true) # Same as … Read more

How to verify number of records using capybara

This should do the trick for your Cucumber step definition: page.has_css?(“div.records li”, :count => 2) There’s also page.has_xpath? (but I don’t understand xpath) If you’re using Rspec you can phrase it the Rspec way with: page.should have_css(“div.records li”, :count => 2) I had to solve a very similar problem just yesterday; here’s the full step … Read more

How do I set up a session value in Capybara?

The accepted answer suggests rack_session_access. It works by inserting middleware controllers to edit and update the session state, then has capybara visit that page and submit a form with the session data. Very ingenious! But unnecessary if you are using Warden (directly or through Devise). Warden has a hook on_next_request that gives access to the … Read more

Rails: How to use Capybara to test a link’s href-value without caring about the text?

To find a link based on just its href using capybara you could do link = page.find(:css, ‘a[href=”actual link”]’) or if you’re looking to assert that the element exists page.assert_selector(:css, ‘a[href=”actual link”]’) or – if using RSpec expect(page).to have_selector(:css, ‘a[href=”actual link”]’) Since have link by default searches for substrings in the link text you can … Read more