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

Gre*_*ber 10 ruby testing rspec capybara

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

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

Capybara::Driver::Webkit::WebkitInvalidResponseError 
Run Code Online (Sandbox Code Playgroud)

执行此代码时:

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)
Run Code Online (Sandbox Code Playgroud)

Mat*_*dan 16

我已经专门写了一个宝石Capybara-Screenshot,请查看https://github.com/mattheworiordan/capybara-screenshot

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


Mar*_*sic 2

找到了一个可能对您有帮助的要点https://gist.github.com/1156691