Path: blob/trunk/javascript/selenium-webdriver/common/driverFinder.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* This implementation is still in beta, and may change.19*20* Utility to find if a given file is present and executable.21*/2223const path = require('node:path')24const { binaryPaths } = require('./seleniumManager')2526/**27* Determines the path of the correct Selenium Manager binary28* @param {Capabilities} capabilities browser options to fetch the driver29* @returns {{browserPath: string, driverPath: string}} path of the driver30* and browser location31*/32function getBinaryPaths(capabilities) {33try {34const args = getArgs(capabilities)35return binaryPaths(args)36} catch (e) {37throw Error(38`Unable to obtain browser driver.39For more information on how to install drivers see40https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/. ${e}`,41)42}43}4445function getArgs(options) {46let args = ['--browser', options.getBrowserName(), '--language-binding', 'javascript', '--output', 'json']4748if (options.getBrowserVersion() && options.getBrowserVersion() !== '') {49args.push('--browser-version', options.getBrowserVersion())50}5152const vendorOptions =53options.get('goog:chromeOptions') || options.get('ms:edgeOptions') || options.get('moz:firefoxOptions')54if (vendorOptions && vendorOptions.binary && vendorOptions.binary !== '') {55args.push('--browser-path', path.resolve(vendorOptions.binary))56}5758const proxyOptions = options.getProxy()5960// Check if proxyOptions exists and has properties61if (proxyOptions && Object.keys(proxyOptions).length > 0) {62const httpProxy = proxyOptions['httpProxy']63const sslProxy = proxyOptions['sslProxy']6465if (httpProxy !== undefined) {66args.push('--proxy', httpProxy)67} else if (sslProxy !== undefined) {68args.push('--proxy', sslProxy)69}70}71return args72}7374// PUBLIC API75module.exports = { getBinaryPaths }767778