I want launch browsers(FF, CHROME) for test with disabled cookies, I tried this:
service =
new ChromeDriverService.Builder()
You can use the below code snippets to disable the cookies in the Chrome and Firefox browsers. If you wish to enable cookies, just remove the capability.
Safari doesn't support any capability to achieve this.
For Chrome:
DesiredCapabilities caps = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();
Map prefs = new HashMap();
Map profile = new HashMap();
Map contentSettings = new HashMap();
contentSettings.put("cookies",2);
profile.put("managed_default_content_settings",contentSettings);
prefs.put("profile",profile);
options.setExperimentalOption("prefs",prefs);
caps.setCapability(ChromeOptions.CAPABILITY,options);
WebDriver driver = new ChromeDriver(caps);
For Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.cookie.cookieBehavior",2);
caps.setCapability(FirefoxDriver.PROFILE,profile);