Ruby-on-rails 我怎样才能看到水豚在失败的黄瓜步骤中发现了什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2413992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:23:19  来源:igfitidea点击:

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

ruby-on-railscucumberwebratcapybara

提问by ajmurmann

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?

我开始从黄瓜 + webrat 迁移到黄瓜 + 水豚。现在“我应该看到”的行为似乎有些不同。尽管我没有更改页面上的任何内容,但大多数现在都失败了。我用每个页面上的一些东西替换了应该找到的片段,并且对于某些文本它有效,而对于其他文本则无效。我在页面内容中找到的内容和没有的内容中找不到任何模式。Webrat 用于打印它找到的页面内容,以防它不包含所需的短语。无论如何让水豚显示它从它试图找到文本的页面中获得的文本?

采纳答案by marcgg

Try adding this step:

尝试添加此步骤:

Then show me the page

回答by sent-hil

Then show me the pagecalls webrat/capybara's underlying save_and_open_pagemethod. Found that useful when working with steak.

Then show me the page调用 webrat/capybara 的底层save_and_open_page方法。发现在处理牛排时很有用。

回答by Hymanlin

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:

如果您想让浏览器在页面失败时打开页面,请使用“launchy” gem。将其添加到您的 gem 文件中,然后在 /features/support 中创建一个名为 debugging.rb 的文件,其中包含以下内容:

After do |scenario|
   save_and_open_page if scenario.failed?
end

回答by Dan Garland

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. (On my version of Linux, I had to symlink chromium to chromium-browser but it otherwise worked fine).

这会使用当前的 DOM 状态集启动一个新的 Chromium 浏览器,让您进入控制台。(在我的 Linux 版本上,我必须将铬符号链接到铬浏览器,但它可以正常工作)。

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

来源信息:http: //jonathanleighton.com/articles/2012/poltergeist-0-6-0/

回答by joscas

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

Then show me the response黄瓜 1.1对我不起作用我发现使用 capybara 的命令编写一个步骤很有用:

print page.html

print page.html

This outputs the current state of the DOM

这将输出 DOM 的当前状态

回答by kinet

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.

如果您不想使用浏览器,您还可以使用“然后向我显示响应”将 HTML 输出到控制台。

回答by Whitney Imura

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

当出现故障时,您总是可以让它截屏。我以这种方式调试了很多失败的功能。