Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/common/driverFinder.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* This implementation is still in beta, and may change.
20
*
21
* Utility to find if a given file is present and executable.
22
*/
23
24
const path = require('node:path')
25
const { binaryPaths } = require('./seleniumManager')
26
27
/**
28
* Determines the path of the correct Selenium Manager binary
29
* @param {Capabilities} capabilities browser options to fetch the driver
30
* @returns {{browserPath: string, driverPath: string}} path of the driver
31
* and browser location
32
*/
33
function getBinaryPaths(capabilities) {
34
try {
35
const args = getArgs(capabilities)
36
return binaryPaths(args)
37
} catch (e) {
38
throw Error(
39
`Unable to obtain browser driver.
40
For more information on how to install drivers see
41
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. ${e}`,
42
)
43
}
44
}
45
46
function getArgs(options) {
47
let args = ['--browser', options.getBrowserName(), '--language-binding', 'javascript', '--output', 'json']
48
49
if (options.getBrowserVersion() && options.getBrowserVersion() !== '') {
50
args.push('--browser-version', options.getBrowserVersion())
51
}
52
53
const vendorOptions =
54
options.get('goog:chromeOptions') || options.get('ms:edgeOptions') || options.get('moz:firefoxOptions')
55
if (vendorOptions && vendorOptions.binary && vendorOptions.binary !== '') {
56
args.push('--browser-path', path.resolve(vendorOptions.binary))
57
}
58
59
const proxyOptions = options.getProxy()
60
61
// Check if proxyOptions exists and has properties
62
if (proxyOptions && Object.keys(proxyOptions).length > 0) {
63
const httpProxy = proxyOptions['httpProxy']
64
const sslProxy = proxyOptions['sslProxy']
65
66
if (httpProxy !== undefined) {
67
args.push('--proxy', httpProxy)
68
} else if (sslProxy !== undefined) {
69
args.push('--proxy', sslProxy)
70
}
71
}
72
return args
73
}
74
75
// PUBLIC API
76
module.exports = { getBinaryPaths }
77
78