[英]How can I see what capybara found in a failing cucumber step?
I started migrating from cucumber + webrat to cucumber + capybara. 我开始从黄瓜+ webrat迁移到黄瓜+水豚。 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. Webrat用于打印它找到的页面内容,以防它不包含所需的短语。 Is there anyway to have capybara show what text it got from the page in which it tried to find the text? 反正有没有capybara显示它从试图找到文本的页面中得到了什么文本?
Then show me the page
calls webrat/capybara's underlying save_and_open_page
method. Then show me the page
调用webrat / save_and_open_page
的底层save_and_open_page
方法。 Found that useful when working with steak. 发现在使用牛排时很有用。
尝试添加此步骤:
Then show me the page
If you want to have the browser open the page when the page fails you use the 'launchy' gem. 如果您希望浏览器在页面失败时打开页面,请使用'launchy'gem。 Add it to your gem file, and then in /features/support create a file called debugging.rb with contents: 将它添加到您的gem文件中,然后在/ features / support中创建一个名为debugging.rb的文件,其中包含以下内容:
After do |scenario|
save_and_open_page if scenario.failed?
end
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. 如果你在你的页面中使用Javascript或Ajax并想看看发生了什么,我发现Poltergeist驱动程序非常善于让你进入DOM并找出问题所在。
If you setup your Capybara driver with the remote debugging option: 如果使用远程调试选项设置Capybara驱动程序:
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. 这将启动一个具有当前DOM状态集的新Chromium浏览器,让您进入控制台。 (On my version of Linux, I had to symlink chromium to chromium-browser but it otherwise worked fine). (在我的Linux版本中,我不得不将铬符号链接到铬浏览器,但它运行正常)。
Source Info: http://jonathanleighton.com/articles/2012/poltergeist-0-6-0/ 来源信息: http : //jonathanleighton.com/articles/2012/poltergeist-0-6-0/
Then show me the response
didn't work for me with cucumber 1.1. Then show me the response
黄瓜1.1对Then show me the response
不起作用。 I found useful to write a step using capybara's command: 我发现使用capybara的命令编写一个步骤很有用:
print page.html
This outputs the current state of the DOM 这将输出DOM的当前状态
您还可以使用“然后显示响应”,如果您不想使用浏览器,则会将HTML输出到控制台。
You could always have it take a screen shot when something failed. 当事情失败时,你总是可以拍摄一个屏幕截图。 I debug a LOT of failing features that way. 我通过这种方式调试了很多失败的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.