Skip to content

Commit f38e78b

Browse files
authored
opt.drivers.chome.arch fix (#827)
* opt.drivers.chome.arch fix * mac test fix
1 parent 0c8756d commit f38e78b

File tree

8 files changed

+190
-126
lines changed

8 files changed

+190
-126
lines changed

lib/compute-download-urls.js

Lines changed: 22 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ module.exports = { computeDownloadUrls, resolveDownloadPath, getLastChromedriver
33
const got = require('got');
44
const util = require('util');
55
const { isSelenium4 } = require('./isSelenium4');
6-
const { detectBrowserPlatform, resolveBuildId } = require('@puppeteer/browsers');
6+
const { resolveBuildId } = require('@puppeteer/browsers');
77
const { validateMajorVersionPrefix, getVersionWithZeroedPatchPart } = require('./validation');
8+
const {
9+
detectBrowserPlatformCustom,
10+
getArhType,
11+
getChromiumEdgeDriverArchitectureOld,
12+
getChromeDriverArchitectureOld,
13+
getIeDriverArchitectureOld,
14+
getFirefoxDriverArchitectureOld,
15+
} = require('./platformDetection');
816
const axios = require('axios');
917

1018
const urls = {
@@ -59,11 +67,11 @@ async function computeDownloadUrls(options) {
5967
if (opts.drivers.chrome.version === 'latest' && !opts.drivers.chrome.fullURL) {
6068
opts.drivers.chrome.version = await resolveBuildId(
6169
'chromedriver',
62-
detectBrowserPlatform(),
70+
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
6371
opts.drivers.chrome.channel ? opts.drivers.chrome.channel : 'stable'
6472
);
6573
downloadUrls.chrome = resolveDownloadUrl(
66-
detectBrowserPlatform(),
74+
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
6775
opts.drivers.chrome.version,
6876
opts.drivers.chrome.baseURL
6977
);
@@ -83,7 +91,7 @@ async function computeDownloadUrls(options) {
8391
) {
8492
const url = lastVersionFromMajor.downloads.chromedriver
8593
.map((m) => {
86-
if (m.platform === detectBrowserPlatform()) {
94+
if (m.platform === detectBrowserPlatformCustom(opts.drivers.chrome.arch)) {
8795
return m.url;
8896
}
8997
})
@@ -97,11 +105,11 @@ async function computeDownloadUrls(options) {
97105

98106
opts.drivers.chrome.version = await resolveBuildId(
99107
'chromedriver',
100-
detectBrowserPlatform(),
108+
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
101109
opts.drivers.chrome.channel ? opts.drivers.chrome.channel : 'stable'
102110
);
103111
downloadUrls.chrome = resolveDownloadUrl(
104-
detectBrowserPlatform(),
112+
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
105113
opts.drivers.chrome.version,
106114
opts.drivers.chrome.baseURL
107115
);
@@ -111,11 +119,11 @@ async function computeDownloadUrls(options) {
111119

112120
opts.drivers.chrome.version = await resolveBuildId(
113121
'chromedriver',
114-
detectBrowserPlatform(),
122+
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
115123
opts.drivers.chrome.channel ? opts.drivers.chrome.channel : 'stable'
116124
);
117125
downloadUrls.chrome = resolveDownloadUrl(
118-
detectBrowserPlatform(),
126+
detectBrowserPlatformCustom(opts.drivers.chrome.arch),
119127
opts.drivers.chrome.version,
120128
opts.drivers.chrome.baseURL
121129
);
@@ -143,7 +151,7 @@ async function computeDownloadUrls(options) {
143151
urls.chrome,
144152
opts.drivers.chrome.baseURL,
145153
opts.drivers.chrome.version,
146-
getChromeDriverArchitecture(opts.drivers.chrome.arch, opts.drivers.chrome.version)
154+
getChromeDriverArchitectureOld(opts.drivers.chrome.arch, opts.drivers.chrome.version)
147155
);
148156
}
149157
}
@@ -154,7 +162,7 @@ async function computeDownloadUrls(options) {
154162
urls.ie,
155163
opts.drivers.ie.baseURL,
156164
opts.drivers.ie.version.slice(0, opts.drivers.ie.version.lastIndexOf('.')),
157-
getIeDriverArchitecture(opts.drivers.ie.arch),
165+
getIeDriverArchitectureOld(opts.drivers.ie.arch),
158166
opts.drivers.ie.version
159167
);
160168
}
@@ -168,7 +176,7 @@ async function computeDownloadUrls(options) {
168176
`v${opts.drivers.firefox.version}`,
169177
'geckodriver',
170178
`v${opts.drivers.firefox.version}`,
171-
getFirefoxDriverArchitecture(opts.drivers.firefox.arch)
179+
getFirefoxDriverArchitectureOld(opts.drivers.firefox.arch)
172180
);
173181
}
174182
if (opts.drivers.edge) {
@@ -186,73 +194,12 @@ async function computeDownloadUrls(options) {
186194
urls.chromiumedge,
187195
opts.drivers.chromiumedge.baseURL,
188196
opts.drivers.chromiumedge.version,
189-
getChromiumEdgeDriverArchitecture(opts.drivers.chromiumedge.arch, opts.drivers.chromiumedge.version)
197+
getChromiumEdgeDriverArchitectureOld(opts.drivers.chromiumedge.arch, opts.drivers.chromiumedge.version)
190198
);
191199
}
192200
return downloadUrls;
193201
}
194202

195-
function getChromeDriverArchitecture(wantedArchitecture, version) {
196-
let platform;
197-
198-
if (process.platform === 'linux') {
199-
platform = 'linux64';
200-
} else if (process.platform === 'darwin') {
201-
if (process.arch === 'arm64') {
202-
const [major] = version.split('.');
203-
platform = parseInt(major, 10) > 105 ? 'mac_arm64' : 'mac64_m1';
204-
} else {
205-
platform = 'mac64';
206-
}
207-
} else {
208-
platform = 'win32';
209-
}
210-
211-
return platform;
212-
}
213-
214-
function getIeDriverArchitecture(wanted) {
215-
let platform;
216-
217-
if (wanted === 'ia32') {
218-
platform = 'Win32';
219-
} else {
220-
platform = 'x64';
221-
}
222-
223-
return platform;
224-
}
225-
226-
function getFirefoxDriverArchitecture(wantedArchitecture) {
227-
const extension = '.tar.gz';
228-
229-
switch (process.platform) {
230-
case 'linux':
231-
return getLinuxFirefoxDriverArchitecture(extension, wantedArchitecture);
232-
case 'darwin':
233-
return getMacFirefoxDriverArchitecture(extension);
234-
case 'win32':
235-
return getWindowsFirefoxDriverArchitecture(wantedArchitecture);
236-
default:
237-
throw new Error('No Firefox driver is available for platform "' + process.platform + '"');
238-
}
239-
}
240-
241-
function getLinuxFirefoxDriverArchitecture(extension, wantedArchitecture = 'x64') {
242-
const arch = wantedArchitecture === 'x64' ? '64' : '32';
243-
return 'linux' + arch + extension;
244-
}
245-
246-
function getMacFirefoxDriverArchitecture(extension) {
247-
return 'macos' + (process.arch === 'arm64' ? '-aarch64' : '') + extension;
248-
}
249-
250-
function getWindowsFirefoxDriverArchitecture(wantedArchitecture = '64') {
251-
const arch = wantedArchitecture.substr(-2) === '64' ? '64' : '32';
252-
253-
return `win${arch}.zip`;
254-
}
255-
256203
const microsoftEdgeReleases = require('./microsoft-edge-releases');
257204

258205
function getEdgeDriverUrl(version) {
@@ -266,33 +213,12 @@ function getEdgeDriverUrl(version) {
266213
return release.url;
267214
}
268215

269-
function getChromiumEdgeDriverArchitecture(wantedArchitecture, version) {
270-
let platform;
271-
272-
if (process.platform === 'linux') {
273-
platform = 'linux64';
274-
} else if (process.platform === 'darwin') {
275-
if (process.arch === 'arm64') {
276-
const [major] = version.split('.');
277-
platform = parseInt(major, 10) > 104 ? 'mac64_m1' : 'mac64';
278-
} else {
279-
platform = 'mac64';
280-
}
281-
} else if (wantedArchitecture === 'x32') {
282-
platform = 'win32';
283-
} else {
284-
platform = 'win64';
285-
}
286-
287-
return platform;
288-
}
289-
290216
async function chromiumEdgeBundleAvailable(opts) {
291217
const url = util.format(
292218
urls.chromiumedge,
293219
opts.drivers.chromiumedge.baseURL,
294220
opts.drivers.chromiumedge.version,
295-
getChromiumEdgeDriverArchitecture(opts.drivers.chromiumedge.platform)
221+
getChromiumEdgeDriverArchitectureOld(opts.drivers.chromiumedge.platform)
296222
);
297223
try {
298224
await got.head(url, { timeout: 10000 });
@@ -362,23 +288,8 @@ function resolveDownloadUrl(
362288
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
363289
}
364290

365-
function folder(platform) {
366-
switch (platform) {
367-
case 'linux':
368-
return 'linux64';
369-
case 'mac_arm':
370-
return 'mac-arm64';
371-
case 'mac':
372-
return 'mac-x64';
373-
case 'win32':
374-
return 'win32';
375-
case 'win64':
376-
return 'win64';
377-
}
378-
}
379-
380291
function resolveDownloadPath(platform, buildId) {
381-
return [buildId, folder(platform), `chromedriver-${folder(platform)}.zip`];
292+
return [buildId, getArhType(platform), `chromedriver-${getArhType(platform)}.zip`];
382293
}
383294

384295
async function getLastChromedriverVersionFromMajor(version) {

lib/compute-fs-paths.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = computeFsPaths;
33
const path = require('path');
44
const { getLastChromedriverVersionFromMajor, getLatestChromium } = require('./compute-download-urls');
55
const { validateMajorVersionPrefix } = require('./validation');
6+
const { detectBrowserPlatformCustom } = require('./platformDetection');
67

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

@@ -36,7 +37,7 @@ async function computeFsPaths(options) {
3637
installPath: path.join(
3738
opts.basePath,
3839
'chromedriver',
39-
opts.drivers.chrome.version + '-' + opts.drivers.chrome.arch,
40+
`${opts.drivers.chrome.version}-${detectBrowserPlatformCustom(opts.drivers.chrome.arch)}`,
4041
'chromedriver'
4142
),
4243
requireChmod: true,
@@ -48,7 +49,7 @@ async function computeFsPaths(options) {
4849
installPath: path.join(
4950
opts.basePath,
5051
'iedriver',
51-
opts.drivers.ie.version + '-' + opts.drivers.ie.arch,
52+
`${opts.drivers.ie.version}-${detectBrowserPlatformCustom(opts.drivers.ie.arch)}`,
5253
'IEDriverServer.exe'
5354
),
5455
};
@@ -65,7 +66,7 @@ async function computeFsPaths(options) {
6566
installPath: path.join(
6667
opts.basePath,
6768
'geckodriver',
68-
opts.drivers.firefox.version + '-' + opts.drivers.firefox.arch,
69+
`${opts.drivers.firefox.version}-${detectBrowserPlatformCustom(opts.drivers.firefox.arch)}`,
6970
'geckodriver'
7071
),
7172
requireChmod: true,
@@ -77,7 +78,7 @@ async function computeFsPaths(options) {
7778
installPath: path.join(
7879
opts.basePath,
7980
'chromiumedgedriver',
80-
opts.drivers.chromiumedge.version + '-' + opts.drivers.chromiumedge.arch,
81+
`${opts.drivers.chromiumedge.version}-${detectBrowserPlatformCustom(opts.drivers.chromiumedge.arch)}`,
8182
'msedgedriver'
8283
),
8384
requireChmod: true,
@@ -98,7 +99,6 @@ async function computeFsPaths(options) {
9899
} else {
99100
downloadPath = acc[name].installPath + '.zip';
100101
}
101-
102102
acc[name].downloadPath = downloadPath;
103103
return acc;
104104
}, fsPaths);

lib/default-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = () => {
22
const config = {
33
baseURL: 'https://github.com/SeleniumHQ/selenium/releases/download',
4-
version: process.env.SELENIUM_VERSION || '4.4.0',
4+
version: process.env.SELENIUM_VERSION || '4.9.0',
55
drivers: {
66
chrome: {
77
version: 'latest',

0 commit comments

Comments
 (0)