在 Rails 系统测试中关闭屏幕截图

dfa*_*ken 2 ruby-on-rails capybara

我在 Rails 5.1 中使用系统测试,我想关闭失败案例的自动屏幕截图。通常,失败消息足以让我弄清楚发生了什么 - 值得注意的是,webdriver 浏览器窗口总是聚焦以截取屏幕截图,这在我处理代码(或尝试做任何其他事情)时很烦人)。

Capybara 配置中是否有内置方法来关闭屏幕截图?我查看了文档并没有找到任何明确说明的内容,但由于这是主流 Rails 的新增功能,我认为这并不一定意味着它不存在。

Tho*_*ole 5

在 Rails 5.1 ActionDispatch::SystemTestCase(从中派生 ApplicationSystemTestCase)有一个默认after_teardown方法

def after_teardown
  take_failed_screenshot
  Capybara.reset_sessions!
  super
end
Run Code Online (Sandbox Code Playgroud)

要阻止截屏,最简单的方法是take_failed_screenshot在您的 ApplicationSystemTestCase 类中进行覆盖

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by ...

  # Add this method
  def take_failed_screenshot
    false
  end
end
Run Code Online (Sandbox Code Playgroud)