How can I see what capybara found in a failing cucumber step?
Asked Answered
A

7

46

I started migrating from cucumber + webrat to cucumber + capybara. Now the behavior of "I should see " seems to be somewhat different. Most of these fail now, although I didn't change anything on the page. I replaced the snippet that should be found with some stuff that is on every page and for some text it works and for other text it doesn't. I can't find any pattern in what is found in the page's content and what is not. Webrat used to print what the page content is that it found, in case it did not contain the required phrase. Is there anyway to have capybara show what text it got from the page in which it tried to find the text?

Alvar answered 10/3, 2010 at 1:46 Comment(3)
As someone completely unfamiliar with the technologies named, this is my favourite stack overflow question title, ever!Electret
Yeah, it sounds like something zoo related.Alvar
@Electret ignorance is blissClea
L
32

Try adding this step:

Then show me the page
Longe answered 10/3, 2010 at 9:18 Comment(1)
I know this is super old, but after adding that directive I had to install the gem 'launchy' and it launched the page with the contents, truly great.Jenjena
T
41

Then show me the page calls webrat/capybara's underlying save_and_open_page method. Found that useful when working with steak.

Tolley answered 13/2, 2011 at 8:16 Comment(0)
L
32

Try adding this step:

Then show me the page
Longe answered 10/3, 2010 at 9:18 Comment(1)
I know this is super old, but after adding that directive I had to install the gem 'launchy' and it launched the page with the contents, truly great.Jenjena
L
24

If you want to have the browser open the page when the page fails you use the 'launchy' gem. Add it to your gem file, and then in /features/support create a file called debugging.rb with contents:

After do |scenario|
   save_and_open_page if scenario.failed?
end
Laundryman answered 20/12, 2011 at 3:2 Comment(1)
This is spectacularly useful, thanks. It seems like it should be installed by default with Cucumber.Wealthy
I
9

If you're using Javascript or Ajax in your pages and want to see what's going on, I've found that the Poltergeist driver is very good at letting you get into the DOM and find out what's going wrong.

If you setup your Capybara driver with the remote debugging option:

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, inspector: true)
end

You can then put the following line in your steps:

page.driver.debug 

Which fires up a new Chromium browser with the current DOM state set, letting you get at the console. (On my version of Linux, I had to symlink chromium to chromium-browser but it otherwise worked fine).

Source Info: http://jonathanleighton.com/articles/2012/poltergeist-0-6-0/

Ichthyo answered 14/9, 2012 at 11:4 Comment(0)
C
8

Then show me the response didn't work for me with cucumber 1.1. I found useful to write a step using capybara's command:

print page.html

This outputs the current state of the DOM

Consubstantiation answered 6/6, 2013 at 10:11 Comment(0)
M
7

You could also use "Then show me the response" which outputs the HTML to the console if you don't want to use a browser.

Monstrance answered 14/5, 2010 at 22:50 Comment(0)
I
0

You could always have it take a screen shot when something failed. I debug a LOT of failing features that way.

Intendance answered 6/6, 2013 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.