Search code examples
javaseleniumselenium-chromedriverremotewebdriverbrowserstack

ChromeDriver Remote - disable notifications using browserstack


I use selenium on BrowserStack service and I need to disable chrome notifications [ex. on screenshot]. Locally I do it with the following code, but all manuals in Internet didn't help me to get it working on remote ChromeDriver on BrowserStack.

ChromeDriver notification.jpg

>@Before
    public void SetUP() throws Exception {
        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.default_content_setting_values.notifications", 2);
        options.setExperimentalOption("prefs", prefs);
        options.addArguments("--start-maximized");
        options.addArguments("disable-popup-blocking");
        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(ChromeOptions.CAPABILITY, options);
        caps.setCapability("browserstack.debug", "true");
        driver = new RemoteWebDriver(new URL(URL), caps);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }


Solution

  • 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);