selenium-lib.js 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. // https://code.google.com/p/selenium/wiki/WebDriverJs
  2. var webdriver = require('selenium-webdriver');
  3. var chrome = require('selenium-webdriver/chrome');
  4. var firefox = require('selenium-webdriver/firefox');
  5. function buildDriver(browser) {
  6. // Firefox options.
  7. // http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_firefox.html
  8. var profile = new firefox.Profile();
  9. profile.setPreference('media.navigator.streams.fake', true);
  10. var firefoxOptions = new firefox.Options()
  11. .setBinary('browsers/bin/firefox-stable')
  12. .setProfile(profile);
  13. // Chrome options.
  14. // http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_chrome_class_Options.html#addArguments
  15. var chromeOptions = new chrome.Options()
  16. .setChromeBinaryPath('browsers/bin/chrome-stable')
  17. .addArguments('allow-file-access-from-files')
  18. .addArguments('use-fake-device-for-media-stream')
  19. .addArguments('use-fake-ui-for-media-stream');
  20. // use-file-for-fake-audio-capture -- see https://code.google.com/p/chromium/issues/detail?id=421054
  21. return new webdriver.Builder()
  22. .forBrowser(browser || process.env.BROWSER || 'firefox')
  23. .setFirefoxOptions(firefoxOptions)
  24. .setChromeOptions(chromeOptions)
  25. .build();
  26. }
  27. module.exports = {
  28. buildDriver: buildDriver
  29. };