|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. |
| 3 | + * |
| 4 | + * Use of this source code is governed by a BSD-style license |
| 5 | + * that can be found in the LICENSE file in the root of the source |
| 6 | + * tree. |
| 7 | + */ |
1 | 8 | const os = require('os'); |
2 | | -const fs = require('fs'); |
3 | 9 |
|
4 | 10 | const webdriver = require('selenium-webdriver'); |
5 | 11 | const chrome = require('selenium-webdriver/chrome'); |
6 | 12 | const firefox = require('selenium-webdriver/firefox'); |
7 | 13 | const safari = require('selenium-webdriver/safari'); |
8 | 14 |
|
9 | | -// setup path for webdriver binaries |
10 | 15 | if (os.platform() === 'win32') { |
11 | | - process.env.PATH += ';C:\\Program Files (x86)\\Microsoft Web Driver\\'; |
12 | | - // FIXME: not sure why node_modules\.bin\ is not enough |
13 | | - process.env.PATH += ';' + process.cwd() + |
14 | | - '\\node_modules\\chromedriver\\lib\\chromedriver\\'; |
15 | | - process.env.PATH += ';' + process.cwd() + |
16 | | - '\\node_modules\\geckodriver'; |
| 16 | + process.env.PATH += ';' + process.cwd() + '\\node_modules\\chromedriver\\lib\\chromedriver\\'; |
| 17 | + process.env.PATH += ';' + process.cwd() + '\\node_modules\\geckodriver'; |
17 | 18 | } else { |
18 | 19 | process.env.PATH += ':node_modules/.bin'; |
19 | 20 | } |
20 | 21 |
|
21 | 22 | function buildDriver(browser = process.env.BROWSER || 'chrome', options = {bver: process.env.BVER}) { |
22 | | - // Firefox options. |
23 | | - let firefoxPath; |
24 | | - if (options.firefoxpath) { |
25 | | - firefoxPath = options.firefoxpath; |
26 | | - } else if (os.platform() == 'linux' && options.bver) { |
27 | | - firefoxPath = 'browsers/bin/firefox-' + options.bver; |
28 | | - } else { |
29 | | - firefoxPath = firefox.Channel.RELEASE; |
30 | | - } |
31 | | - |
32 | | - const firefoxOptions = new firefox.Options() |
33 | | - .setPreference('media.navigator.streams.fake', true) |
34 | | - .setPreference('media.navigator.permission.disabled', true) |
35 | | - .setPreference('xpinstall.signatures.required', false) |
36 | | - .setPreference('media.peerconnection.dtls.version.min', 771) |
37 | | - .setBinary(firefoxPath); |
38 | | - |
39 | 23 | // Chrome options. |
40 | | - let chromeOptions = new chrome.Options() |
41 | | - .addArguments('allow-file-access-from-files') |
| 24 | + const chromeOptions = new chrome.Options() |
| 25 | + .addArguments('allow-insecure-localhost') |
42 | 26 | .addArguments('use-fake-device-for-media-stream') |
43 | | - .addArguments('use-fake-ui-for-media-stream') |
44 | | - .addArguments('disable-translate') |
45 | | - .addArguments('no-process-singleton-dialog') |
46 | | - .addArguments('mute-audio'); |
47 | | - // ensure chrome.runtime is visible. |
48 | | - chromeOptions.excludeSwitches('test-type'); |
| 27 | + .addArguments('allow-file-access-from-files'); |
| 28 | + if (options.chromeFlags) { |
| 29 | + options.chromeFlags.forEach((flag) => chromeOptions.addArguments(flag)); |
| 30 | + } |
49 | 31 |
|
50 | 32 | if (options.chromepath) { |
51 | 33 | chromeOptions.setChromeBinaryPath(options.chromepath); |
52 | | - } else if (os.platform() === 'linux' && options.bver) { |
53 | | - chromeOptions.setChromeBinaryPath('browsers/bin/chrome-' + options.bver); |
| 34 | + } else if (os.platform() === 'linux' && options.version) { |
| 35 | + chromeOptions.setChromeBinaryPath('browsers/bin/chrome-' + options.version); |
| 36 | + } |
| 37 | + |
| 38 | + if (!options.devices || options.headless) { |
| 39 | + // GUM doesn't work in headless mode so we need this. See |
| 40 | + // https://bugs.chromium.org/p/chromium/issues/detail?id=776649 |
| 41 | + chromeOptions.addArguments('use-fake-ui-for-media-stream'); |
| 42 | + } else { |
| 43 | + // see https://bugs.chromium.org/p/chromium/issues/detail?id=459532#c22 |
| 44 | + const domain = 'https://' + (options.devices.domain || 'localhost') + ':' + (options.devices.port || 443) + ',*'; |
| 45 | + const exceptions = { |
| 46 | + media_stream_mic: {}, |
| 47 | + media_stream_camera: {}, |
| 48 | + }; |
| 49 | + |
| 50 | + exceptions.media_stream_mic[domain] = { |
| 51 | + last_used: Date.now(), |
| 52 | + setting: options.devices.audio ? 1 : 2 // 0: ask, 1: allow, 2: denied |
| 53 | + }; |
| 54 | + exceptions.media_stream_camera[domain] = { |
| 55 | + last_used: Date.now(), |
| 56 | + setting: options.devices.video ? 1 : 2 |
| 57 | + }; |
| 58 | + |
| 59 | + chromeOptions.setUserPreferences({ |
| 60 | + profile: { |
| 61 | + content_settings: { |
| 62 | + exceptions: exceptions |
| 63 | + } |
| 64 | + } |
| 65 | + }); |
54 | 66 | } |
55 | 67 |
|
56 | 68 | const safariOptions = new safari.Options(); |
57 | 69 | safariOptions.setTechnologyPreview(options.bver === 'unstable'); |
58 | 70 |
|
| 71 | + // Firefox options. |
| 72 | + const firefoxOptions = new firefox.Options(); |
| 73 | + let firefoxPath = firefox.Channel.RELEASE; |
| 74 | + if (options.firefoxpath) { |
| 75 | + firefoxPath = options.firefoxpath; |
| 76 | + } else if (os.platform() == 'linux' && options.version) { |
| 77 | + firefoxPath = 'browsers/bin/firefox-' + options.version; |
| 78 | + } |
| 79 | + if (options.headless) { |
| 80 | + firefoxOptions.addArguments('-headless'); |
| 81 | + } |
| 82 | + firefoxOptions.setBinary(firefoxPath); |
| 83 | + firefoxOptions.setPreference('media.navigator.streams.fake', true); |
| 84 | + firefoxOptions.setPreference('media.navigator.permission.disabled', true); |
| 85 | + |
59 | 86 | const driver = new webdriver.Builder() |
60 | | - .setFirefoxOptions(firefoxOptions) |
61 | 87 | .setChromeOptions(chromeOptions) |
62 | 88 | .setSafariOptions(safariOptions) |
63 | | - .forBrowser(browser); |
64 | | - driver.getCapabilities().set('acceptInsecureCerts', true); |
| 89 | + .setFirefoxOptions(firefoxOptions) |
| 90 | + .forBrowser(browser) |
| 91 | + .setChromeService( |
| 92 | + new chrome.ServiceBuilder().addArguments('--disable-build-check') |
| 93 | + ); |
65 | 94 |
|
| 95 | + if (browser === 'firefox') { |
| 96 | + driver.getCapabilities().set('marionette', true); |
| 97 | + driver.getCapabilities().set('acceptInsecureCerts', true); |
| 98 | + } |
66 | 99 | return driver.build(); |
67 | 100 | } |
68 | 101 |
|
|
0 commit comments