I want launch browsers(FF, CHROME) for test with disabled cookies, I tried this:
service =
new ChromeDriverService.Builder()
.usingDriverExecutable(new File("src/test/resources/chromedriver"))
.usingAnyFreePort().build();
try {
service.start();
} catch (IOException e1) {
e1.printStackTrace();
}
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("disable-restore-session-state", true);
driver = new ChromeDriver(service, capabilities);
but it's not work...
I've just get solution for Firefox:
FirefoxProfile profile = new ProfilesIni().getProfile("default");
profile.setPreference("network.cookie.cookieBehavior", 2);
driver = new FirefoxDriver(profile);
for Chrome (block all cookies)
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.cookies", 2);
for Chrome (block only third party cookies)
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.cookies", 1);
options.AddUserProfilePreference("profile.cookie_controls_mode", 1);
You can disable Chrome cookies as below:
Map prefs = new HashMap();
prefs.put("profile.default_content_settings.cookies", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOptions("prefs", prefs);
driver = new ChromeDriver(options);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With