我正在 Rails 5.1 中使用系统测试,并且我想关闭失败案例的自动屏幕截图。通常,失败消息足以让我弄清楚发生了什么 - 值得注意的是,网络驱动程序浏览器窗口总是获得焦点以便截取屏幕截图,这在我处理代码(或尝试执行其他任何操作)时很烦人)。
capybara 配置中有内置方法可以关闭屏幕截图吗?我浏览了文档,找不到任何明确说明的内容,但由于这是对主流 Rails 的新补充,我认为这并不一定意味着它不存在。
最佳答案
在 Rails 5.1 ActionDispatch::SystemTestCase(从中派生出 ApplicationSystemTestCase)中,有一个默认的 after_teardown
方法
def after_teardown
take_failed_screenshot
Capybara.reset_sessions!
super
end
要阻止它截图,最简单的方法是重写 ApplicationSystemTestCase 类中的 take_failed_screenshot
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by ...
# Add this method
def take_failed_screenshot
false
end
end
关于ruby-on-rails - 关闭 Rails 系统测试中的屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44336581/