How to disable camera and microphone popup alert via Selenium WebDriver tests?

SamP :

Currently, I have tests which perform a specific test flow however this specific flow causes Chrome to present the user (Tests) with a microphone, camera alert popups:

enter image description here

I need a way to disable the alerts via Selenium Webdriver / Java, I have attempted to use Chrome options, with no luck; example code:

ChromeOptions op = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
prefs.put("profile.default_content_setting_values.geolocation", 1);
prefs.put("profile.default_content_setting_values.notifications", 1);
op.setExperimentalOption("prefs", prefs);
RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL(REMOTE_HUB_URL), op);

Even solely tried the following with no luck:

prefs.put("profile.default_content_settings.popups", 1);
Ratmir Asanov :

You need to use the "2" value for that. Code:

...
prefs.put("profile.default_content_setting_values.media_stream_mic", 2);
prefs.put("profile.default_content_setting_values.media_stream_camera", 2);
...

PS: The value "1" is used for allowing the option, "2" -- for blocking.

I hope it helps you!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=352896&siteId=1