Background:
I'm currently writing tests for a Rails project using RSpec + Capybara. We're using Selenium + Headless Chrome to simulate browser interactions.
Problem:
I want to disable browser cookies for a test. We're currently instantiating the web driver this way in our spec/spec_helper.rb
chrome_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: {
w3c: false,
args: %w[headless no-sandbox window-size=1280,2000 no-proxy-server disable-gpu disable-dev-shm-usage],
},
loggingPrefs:{browser: 'ALL'},
)
Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: chrome_capabilities
)
end
I've seen many Java examples that disable cookies by passing this setting when instantiating Headless Chrome: "profile.default_content_setting_values.cookies" => 2
However, I haven't been able to get to this to work.
Does anyone know the correct way to instantiate the Headless Chrome instance so that cookies are disabled?