@wdio/utils
Advanced tools
Comparing version 8.20.0 to 8.20.3
@@ -11,3 +11,3 @@ import os from 'node:os'; | ||
import { download as downloadEdgedriver } from 'edgedriver'; | ||
import { locateChrome, locateFirefox } from 'locate-app'; | ||
import { locateChrome, locateFirefox, locateApp } from 'locate-app'; | ||
const log = logger('webdriver'); | ||
@@ -106,6 +106,14 @@ const EXCLUDED_PARAMS = ['version', 'help']; | ||
}; | ||
function locateChromeSafely() { | ||
return locateChrome().catch(() => undefined); | ||
} | ||
export async function setupPuppeteerBrowser(cacheDir, caps) { | ||
caps.browserName = caps.browserName?.toLowerCase(); | ||
const browserName = caps.browserName === Browser.FIREFOX ? Browser.FIREFOX : Browser.CHROME; | ||
const browserName = caps.browserName === Browser.FIREFOX | ||
? Browser.FIREFOX | ||
: caps.browserName === Browser.CHROMIUM | ||
? Browser.CHROMIUM | ||
: Browser.CHROME; | ||
const exist = await fsp.access(cacheDir).then(() => true, () => false); | ||
const isChromeOrChromium = browserName === Browser.CHROME || caps.browserName === Browser.CHROMIUM; | ||
if (!exist) { | ||
@@ -115,5 +123,12 @@ await fsp.mkdir(cacheDir, { recursive: true }); | ||
/** | ||
* in case we run Chromium tests we have to switch back to browserName: 'chrome' | ||
* as 'chromium' is not recognised as a valid browser name by Chromedriver | ||
*/ | ||
if (browserName === Browser.CHROMIUM) { | ||
caps.browserName = Browser.CHROME; | ||
} | ||
/** | ||
* don't set up Chrome/Firefox if a binary was defined in caps | ||
*/ | ||
const browserOptions = (browserName === Browser.CHROME | ||
const browserOptions = (isChromeOrChromium | ||
? caps['goog:chromeOptions'] | ||
@@ -125,3 +140,3 @@ : caps['moz:firefoxOptions']) || {}; | ||
browserVersion: (caps.browserVersion || | ||
(browserName === Browser.CHROME | ||
(isChromeOrChromium | ||
? getBuildIdByChromePath(browserOptions.binary) | ||
@@ -137,5 +152,11 @@ : await getBuildIdByFirefoxPath(browserOptions.binary))) | ||
const executablePath = browserName === Browser.CHROME | ||
? await locateChrome().catch(() => undefined) | ||
: await locateFirefox().catch(() => undefined); | ||
const tag = browserName === Browser.CHROME | ||
? await locateChromeSafely() | ||
: browserName === Browser.CHROMIUM | ||
? await locateApp({ | ||
appName: Browser.CHROMIUM, | ||
macOsName: Browser.CHROMIUM, | ||
linuxWhich: 'chromium-browser' | ||
}).catch(() => undefined) | ||
: await locateFirefox().catch(() => undefined); | ||
const tag = isChromeOrChromium | ||
? getBuildIdByChromePath(executablePath) | ||
@@ -175,3 +196,12 @@ : await getBuildIdByFirefoxPath(executablePath); | ||
const executablePath = computeExecutablePath(installOptions); | ||
return { executablePath, browserVersion: buildId }; | ||
/** | ||
* for Chromium browser `resolveBuildId` returns with a useless build id | ||
* which will not find a Chromedriver, therefor we need to resolve the | ||
* id using Chrome as browser name | ||
*/ | ||
let browserVersion = buildId; | ||
if (browserName === Browser.CHROMIUM) { | ||
browserVersion = await resolveBuildId(Browser.CHROME, platform, tag); | ||
} | ||
return { executablePath, browserVersion }; | ||
} | ||
@@ -202,3 +232,3 @@ export function getDriverOptions(caps) { | ||
} | ||
const version = driverVersion || getBuildIdByChromePath(await locateChrome()) || ChromeReleaseChannel.STABLE; | ||
const version = driverVersion || getBuildIdByChromePath(await locateChromeSafely()) || ChromeReleaseChannel.STABLE; | ||
const buildId = await resolveBuildId(Browser.CHROMEDRIVER, platform, version); | ||
@@ -205,0 +235,0 @@ let executablePath = computeExecutablePath({ |
{ | ||
"name": "@wdio/utils", | ||
"version": "8.20.0", | ||
"version": "8.20.3", | ||
"description": "A WDIO helper utility to provide several utility functions used across the project.", | ||
@@ -58,3 +58,3 @@ "author": "Christian Bromann <mail@bromann.dev>", | ||
}, | ||
"gitHead": "6aa9e33233a6abc832bb16d2e24aaaa382e206b6" | ||
"gitHead": "963b578edcfd5636994662122ebac35b0bd641f1" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156333
3234