配置 spec_helper 文件让默认驱动程序在 Chrome 中打开隐身 window

Configure the spec_helper file to have the default driver open an incognito window in Chrome

我一直在想办法让我的默认驱动程序以隐身方式 window 打开 Chrome。

Capybara.default_driver = :selenium_chrome 是我目前的默认驱动程序。

如何添加告诉驱动程序始终打开隐身模式的选项window?

您需要注册您自己的驱动程序,它可以按照您想要的方式配置Chrome

Capybara.register_driver :incognito_chrome do |app|
  browser_options = ::Selenium::WebDriver::Chrome::Options.new
  browser_options.args << '--incognito'
  Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

然后将其设置为默认驱动程序

Capybara.default_driver = :incognito_chrome