4

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

Shakle
  • 724
  • 9
  • 11

2 Answers2

3

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

Shakle
  • 724
  • 9
  • 11
0

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

  • I've read about this method, but haven't tried yet. I don't think that it is the best decision, but if it would work - thanks :) Will write if it works. – Shakle Mar 17 '16 at 14:49