简体   繁体   English

我如何才能看到黄瓜失败的黄瓜步骤中发现了什么?

[英]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.1Then 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.

相关问题 如果我的“然后我应该看到”黄瓜功能失败,我怎么能看到黄瓜看到了什么? - If my “Then I should see” Cucumber feature is failing, how can I see what Cucumber is seeing? 黄瓜设计失败的迹象(rails 3.2,黄瓜,水豚,rspec) - Cucumber devise sign in step failing (rails 3.2, cucumber, capybara, rspec) 如何查看黄瓜中每个方案步骤所使用的步骤定义 - How can I see which step definitions are used for each scenario step in cucumber 使用Cucumber和Selenium进行测试:我如何才能看到它在浏览器中看到的内容? - Testing with Cucumber and Selenium: how can I see what it sees in the browser? 黄瓜水豚的阶梯功能 - step function in cucumber capybara 如何打开黄瓜,水豚和硒的多个并发会话? - How can I open multiple concurrent sessions with cucumber, capybara, and selenium? 如何从使用 Capybara 的 Cucumber Step 获取整个页面的响应 HTML? - How do i get the response HTML of an entire Page from a Cucumber Step that uses Capybara? 如何在我的Cucumber / Capybara步骤定义(Rails 3)中进行xpath正则表达式搜索? - How do I do an xpath regex search in my Cucumber / Capybara step definition (Rails 3)? 水豚测试失败,因为找不到元素 - Capybara test failing because element can not be found 如何在黄瓜+水豚步骤定义中设置HTTP_REFERER? - How to set HTTP_REFERER in cucumber+capybara step definitions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM