ChromeDriver Remote - disable notifications using browserstack ChromeDriver Remote - disable notifications using browserstack selenium selenium

ChromeDriver Remote - disable notifications using browserstack


Good guys from BrowserStack support found the solution! Very thanks to them.

This code works in ChromeDriver remotely:

        ChromeOptions options = new ChromeOptions();        Map<String, Object> prefs = new HashMap<String, Object>();        Map<String, Object> profile = new HashMap<String, Object>();        Map<String, Object> contentSettings = new HashMap<String, Object>();        contentSettings.put("notifications", 2);        profile.put("managed_default_content_settings", contentSettings);        prefs.put("profile", profile);        options.setExperimentalOption("prefs", prefs);        options.addArguments("--disable-plugins");        options.addArguments("--start-maximized");        DesiredCapabilities caps = DesiredCapabilities.chrome();        caps.setCapability("browser", "Chrome");        caps.setCapability("browser_version", "49.0");        caps.setCapability("os", "Windows");        caps.setCapability("os_version", "10");        caps.setCapability("resolution", "1280x1024");        caps.setCapability("browserstack.debug", "true");        caps.setCapability(ChromeOptions.CAPABILITY, options);        driver = new RemoteWebDriver(new URL(URL), caps);


Some time ago I have this same problem with WebPageTest (perf measurement tool) when execute tests remotely on Chrome. One hint I can give you here is to restore browser profile from a state in which all notifications are turned off. I "lied" the tool by doing this manually by:

  1. Switch off notifications on the browser instance. You can do this manually, see screenshot
  2. Took the profile created with this change (search in internet which was the default location)
  3. Place the profile in the default folder from where the profile is restored before every run or just place it here:

prefs.put("profile.default_content_setting_values.notifications", 2);

Hope this helps,Lora