How can a fake media stream and media device be passed to firefox via command line/selenium

1,762 views
Skip to first unread message

John Sylvester

unread,
Aug 10, 2015, 1:04:14 AM8/10/15
to Selenium Users

Hi,


I am developing a java/selenium based application and need to fake microphone/cam and pass media i.e. audio and/or video files to the browser.

I have been able to successfully do this in Chrome using the below code snippet:

                

             DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
             ChromeOptions options = new ChromeOptions();
             options.addArguments("--allow-file-access-from-files",
                                 "--use-fake-ui-for-media-stream",
                                 "--allow-file-access",
                                 "--use-file-for-fake-audio-capture=D:\\PATH\\TO\\WAV\\xxx.wav",
                                 "--use-fake-device-for-media-stream");
             capabilities.setCapability(ChromeOptions.CAPABILITY, options);
             ChromeDriver driver = new ChromeDriver(capabilities);

Are there similar options available in Firefox to achieve the same capability?


If not, how can this be done using java? Any help will be helpful.


I tried this and preferences do get set, but I still get an error saying "Media device unavailable"


                  DesiredCapabilities capabilities = DesiredCapabilities.firefox();
                  ProfilesIni profilesIni = new ProfilesIni();
                  FirefoxProfile profile = profilesIni.getProfile("John");
                  profile.setPreference("browser.privatebrowsing.autostart", true);
                  profile.setPreference("media.navigator.enabled", true);
                  profile.setPreference("media.navigator.permission.disabled", true);
                  profile.setPreference("media.navigator.streams.fake", true);
                  capabilities.setCapability(FirefoxDriver.PROFILE, profile);
                  FirefoxDriver driver = new FirefoxDriver(capabilities);


P.S. Development is done on a windows system but will later be moved to Linux.


Thanks,

John


David

unread,
Aug 10, 2015, 11:36:43 PM8/10/15
to Selenium Users
+1

I'd be interested to know the scope of support for faking media devices & streams across browsers (and OSes) with Selenium. Taken further one might inquire this for Appium and mobile browser equivalents.
Reply all
Reply to author
Forward
0 new messages