capybara-webkit:自动保存RSpec测试失败的屏幕截图

如果使用带有Rspec的capybara-webkit测试失败,如何自动保存html和屏幕截图? 如何在RSpec测试失败时执行回调。

加分:如何避免出现以下错误:

Capybara::Driver::Webkit::WebkitInvalidResponseError 

执行此代码时:

 require 'capybara/util/save_and_open_page' path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}" png = Capybara.save_and_open_page_path + "#{path}.png" page.driver.render Rails.root.join(png) 

找到一个可以帮助你的要点https://gist.github.com/1156691

我已经专门为此编写了一个gemCapybara-Screenshot,请访问https://github.com/mattheworiordan/capybara-screenshot

它将自动创建失败的RSpec或Cucumber步骤的屏幕截图。

Capybara提供了在测试期间保存和打开屏幕截图的function。 您只需要在测试中的任何地方打电话:

save_and_open_screenshot

它将打开一张图片,测试在那一点上是什么样的。 不需要任何额外的gem。

水豚:: save_and_open_screenshot