Skip to content

Commit

Permalink
opt.drivers.chome.arch fix (#827)
Browse files Browse the repository at this point in the history
* opt.drivers.chome.arch fix

* mac test fix
  • Loading branch information
udarrr authored Aug 20, 2023
1 parent 0c8756d commit f38e78b
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 126 deletions.
133 changes: 22 additions & 111 deletions lib/compute-download-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ module.exports = { computeDownloadUrls, resolveDownloadPath, getLastChromedriver
const got = require('got');
const util = require('util');
const { isSelenium4 } = require('./isSelenium4');
const { detectBrowserPlatform, resolveBuildId } = require('@puppeteer/browsers');
const { resolveBuildId } = require('@puppeteer/browsers');
const { validateMajorVersionPrefix, getVersionWithZeroedPatchPart } = require('./validation');
const {
detectBrowserPlatformCustom,
getArhType,
getChromiumEdgeDriverArchitectureOld,
getChromeDriverArchitectureOld,
getIeDriverArchitectureOld,
getFirefoxDriverArchitectureOld,
} = require('./platformDetection');
const axios = require('axios');

const urls = {
Expand Down Expand Up @@ -59,11 +67,11 @@ async function computeDownloadUrls(options) {
if (opts.drivers.chrome.version === 'latest' && !opts.drivers.chrome.fullURL) {
opts.drivers.chrome.version = await resolveBuildId(
'chromedriver',
detectBrowserPlatform(),
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
opts.drivers.chrome.channel ? opts.drivers.chrome.channel : 'stable'
);
downloadUrls.chrome = resolveDownloadUrl(
detectBrowserPlatform(),
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
opts.drivers.chrome.version,
opts.drivers.chrome.baseURL
);
Expand All @@ -83,7 +91,7 @@ async function computeDownloadUrls(options) {
) {
const url = lastVersionFromMajor.downloads.chromedriver
.map((m) => {
if (m.platform === detectBrowserPlatform()) {
if (m.platform === detectBrowserPlatformCustom(opts.drivers.chrome.arch)) {
return m.url;
}
})
Expand All @@ -97,11 +105,11 @@ async function computeDownloadUrls(options) {

opts.drivers.chrome.version = await resolveBuildId(
'chromedriver',
detectBrowserPlatform(),
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
opts.drivers.chrome.channel ? opts.drivers.chrome.channel : 'stable'
);
downloadUrls.chrome = resolveDownloadUrl(
detectBrowserPlatform(),
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
opts.drivers.chrome.version,
opts.drivers.chrome.baseURL
);
Expand All @@ -111,11 +119,11 @@ async function computeDownloadUrls(options) {

opts.drivers.chrome.version = await resolveBuildId(
'chromedriver',
detectBrowserPlatform(),
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
opts.drivers.chrome.channel ? opts.drivers.chrome.channel : 'stable'
);
downloadUrls.chrome = resolveDownloadUrl(
detectBrowserPlatform(),
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
opts.drivers.chrome.version,
opts.drivers.chrome.baseURL
);
Expand Down Expand Up @@ -143,7 +151,7 @@ async function computeDownloadUrls(options) {
urls.chrome,
opts.drivers.chrome.baseURL,
opts.drivers.chrome.version,
getChromeDriverArchitecture(opts.drivers.chrome.arch, opts.drivers.chrome.version)
getChromeDriverArchitectureOld(opts.drivers.chrome.arch, opts.drivers.chrome.version)
);
}
}
Expand All @@ -154,7 +162,7 @@ async function computeDownloadUrls(options) {
urls.ie,
opts.drivers.ie.baseURL,
opts.drivers.ie.version.slice(0, opts.drivers.ie.version.lastIndexOf('.')),
getIeDriverArchitecture(opts.drivers.ie.arch),
getIeDriverArchitectureOld(opts.drivers.ie.arch),
opts.drivers.ie.version
);
}
Expand All @@ -168,7 +176,7 @@ async function computeDownloadUrls(options) {
`v${opts.drivers.firefox.version}`,
'geckodriver',
`v${opts.drivers.firefox.version}`,
getFirefoxDriverArchitecture(opts.drivers.firefox.arch)
getFirefoxDriverArchitectureOld(opts.drivers.firefox.arch)
);
}
if (opts.drivers.edge) {
Expand All @@ -186,73 +194,12 @@ async function computeDownloadUrls(options) {
urls.chromiumedge,
opts.drivers.chromiumedge.baseURL,
opts.drivers.chromiumedge.version,
getChromiumEdgeDriverArchitecture(opts.drivers.chromiumedge.arch, opts.drivers.chromiumedge.version)
getChromiumEdgeDriverArchitectureOld(opts.drivers.chromiumedge.arch, opts.drivers.chromiumedge.version)
);
}
return downloadUrls;
}

function getChromeDriverArchitecture(wantedArchitecture, version) {
let platform;

if (process.platform === 'linux') {
platform = 'linux64';
} else if (process.platform === 'darwin') {
if (process.arch === 'arm64') {
const [major] = version.split('.');
platform = parseInt(major, 10) > 105 ? 'mac_arm64' : 'mac64_m1';
} else {
platform = 'mac64';
}
} else {
platform = 'win32';
}

return platform;
}

function getIeDriverArchitecture(wanted) {
let platform;

if (wanted === 'ia32') {
platform = 'Win32';
} else {
platform = 'x64';
}

return platform;
}

function getFirefoxDriverArchitecture(wantedArchitecture) {
const extension = '.tar.gz';

switch (process.platform) {
case 'linux':
return getLinuxFirefoxDriverArchitecture(extension, wantedArchitecture);
case 'darwin':
return getMacFirefoxDriverArchitecture(extension);
case 'win32':
return getWindowsFirefoxDriverArchitecture(wantedArchitecture);
default:
throw new Error('No Firefox driver is available for platform "' + process.platform + '"');
}
}

function getLinuxFirefoxDriverArchitecture(extension, wantedArchitecture = 'x64') {
const arch = wantedArchitecture === 'x64' ? '64' : '32';
return 'linux' + arch + extension;
}

function getMacFirefoxDriverArchitecture(extension) {
return 'macos' + (process.arch === 'arm64' ? '-aarch64' : '') + extension;
}

function getWindowsFirefoxDriverArchitecture(wantedArchitecture = '64') {
const arch = wantedArchitecture.substr(-2) === '64' ? '64' : '32';

return `win${arch}.zip`;
}

const microsoftEdgeReleases = require('./microsoft-edge-releases');

function getEdgeDriverUrl(version) {
Expand All @@ -266,33 +213,12 @@ function getEdgeDriverUrl(version) {
return release.url;
}

function getChromiumEdgeDriverArchitecture(wantedArchitecture, version) {
let platform;

if (process.platform === 'linux') {
platform = 'linux64';
} else if (process.platform === 'darwin') {
if (process.arch === 'arm64') {
const [major] = version.split('.');
platform = parseInt(major, 10) > 104 ? 'mac64_m1' : 'mac64';
} else {
platform = 'mac64';
}
} else if (wantedArchitecture === 'x32') {
platform = 'win32';
} else {
platform = 'win64';
}

return platform;
}

async function chromiumEdgeBundleAvailable(opts) {
const url = util.format(
urls.chromiumedge,
opts.drivers.chromiumedge.baseURL,
opts.drivers.chromiumedge.version,
getChromiumEdgeDriverArchitecture(opts.drivers.chromiumedge.platform)
getChromiumEdgeDriverArchitectureOld(opts.drivers.chromiumedge.platform)
);
try {
await got.head(url, { timeout: 10000 });
Expand Down Expand Up @@ -362,23 +288,8 @@ function resolveDownloadUrl(
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
}

function folder(platform) {
switch (platform) {
case 'linux':
return 'linux64';
case 'mac_arm':
return 'mac-arm64';
case 'mac':
return 'mac-x64';
case 'win32':
return 'win32';
case 'win64':
return 'win64';
}
}

function resolveDownloadPath(platform, buildId) {
return [buildId, folder(platform), `chromedriver-${folder(platform)}.zip`];
return [buildId, getArhType(platform), `chromedriver-${getArhType(platform)}.zip`];
}

async function getLastChromedriverVersionFromMajor(version) {
Expand Down
10 changes: 5 additions & 5 deletions lib/compute-fs-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = computeFsPaths;
const path = require('path');
const { getLastChromedriverVersionFromMajor, getLatestChromium } = require('./compute-download-urls');
const { validateMajorVersionPrefix } = require('./validation');
const { detectBrowserPlatformCustom } = require('./platformDetection');

const basePath = path.join(__dirname, '..', '.selenium');

Expand Down Expand Up @@ -36,7 +37,7 @@ async function computeFsPaths(options) {
installPath: path.join(
opts.basePath,
'chromedriver',
opts.drivers.chrome.version + '-' + opts.drivers.chrome.arch,
`${opts.drivers.chrome.version}-${detectBrowserPlatformCustom(opts.drivers.chrome.arch)}`,
'chromedriver'
),
requireChmod: true,
Expand All @@ -48,7 +49,7 @@ async function computeFsPaths(options) {
installPath: path.join(
opts.basePath,
'iedriver',
opts.drivers.ie.version + '-' + opts.drivers.ie.arch,
`${opts.drivers.ie.version}-${detectBrowserPlatformCustom(opts.drivers.ie.arch)}`,
'IEDriverServer.exe'
),
};
Expand All @@ -65,7 +66,7 @@ async function computeFsPaths(options) {
installPath: path.join(
opts.basePath,
'geckodriver',
opts.drivers.firefox.version + '-' + opts.drivers.firefox.arch,
`${opts.drivers.firefox.version}-${detectBrowserPlatformCustom(opts.drivers.firefox.arch)}`,
'geckodriver'
),
requireChmod: true,
Expand All @@ -77,7 +78,7 @@ async function computeFsPaths(options) {
installPath: path.join(
opts.basePath,
'chromiumedgedriver',
opts.drivers.chromiumedge.version + '-' + opts.drivers.chromiumedge.arch,
`${opts.drivers.chromiumedge.version}-${detectBrowserPlatformCustom(opts.drivers.chromiumedge.arch)}`,
'msedgedriver'
),
requireChmod: true,
Expand All @@ -98,7 +99,6 @@ async function computeFsPaths(options) {
} else {
downloadPath = acc[name].installPath + '.zip';
}

acc[name].downloadPath = downloadPath;
return acc;
}, fsPaths);
Expand Down
2 changes: 1 addition & 1 deletion lib/default-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = () => {
const config = {
baseURL: 'https://github.com/SeleniumHQ/selenium/releases/download',
version: process.env.SELENIUM_VERSION || '4.4.0',
version: process.env.SELENIUM_VERSION || '4.9.0',
drivers: {
chrome: {
version: 'latest',
Expand Down
Loading

0 comments on commit f38e78b

Please sign in to comment.