Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 918865b

Browse files
committed
chore(webdriver): fix version support
1 parent 7372267 commit 918865b

File tree

2 files changed

+69
-102
lines changed

2 files changed

+69
-102
lines changed

Diff for: bin/webdriver-manager

+67-100
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,34 @@ var binaries = {
3838
standalone: {
3939
name: 'selenium standalone',
4040
isDefault: true,
41-
defaultVersion: versions.selenium,
4241
osType: 'ANY',
43-
prefix: function() {
44-
return seleniumPrefix;
45-
},
46-
version: function() {
47-
return seleniumVersion;
42+
prefix: 'selenium-server-standalone-',
43+
defaultVersion: versions.selenium,
44+
version: versions.selenium,
45+
getVersion: function() {
46+
return this.version;
4847
},
4948
suffix: function() {
5049
return '.jar';
5150
},
5251
filename: function() {
53-
return this.prefix() + this.version() + this.suffix();
52+
return this.prefix + this.getVersion() + this.suffix();
5453
},
5554
cdn: 'https://selenium-release.storage.googleapis.com/',
5655
url: function() {
57-
return this.cdn + shortVersion(this.version()) + '/' +
58-
this.prefix() + this.version() + this.suffix();
56+
return this.cdn + shortVersion(this.getVersion()) + '/' +
57+
this.prefix + this.getVersion() + this.suffix();
5958
}
6059
},
6160
chrome: {
6261
name: 'chromedriver',
6362
isDefault: true,
6463
osType: 'ANY',
64+
prefix: 'chromedriver_',
6565
defaultVersion: versions.chromedriver,
66-
prefix: function() {
67-
return chromePrefix;
68-
},
69-
version: function() {
70-
return chromeVersion;
66+
version: versions.chromedriver,
67+
getVersion: function() {
68+
return this.version;
7169
},
7270
suffix: function() {
7371
if (os.type() == 'Darwin') {
@@ -83,66 +81,41 @@ var binaries = {
8381
}
8482
},
8583
filename: function() {
86-
return this.prefix() + this.version() + this.suffix();
84+
return this.prefix + this.getVersion() + this.suffix();
8785
},
8886
cdn: 'https://chromedriver.storage.googleapis.com/',
8987
url: function() {
90-
return this.cdn + this.version() + '/' + this.prefix() + this.suffix();
88+
return this.cdn + this.getVersion() + '/' + this.prefix + this.suffix();
9189
}
9290
},
9391
ie: {
9492
name: 'IEDriver',
9593
isDefault: false,
9694
osType: 'Windows_NT',
95+
prefix: 'IEDriverServer',
96+
selectIe32: false,
9797
defaultVersion: versions.iedriver,
98-
prefix: function() {
98+
version: versions.iedriver,
99+
getVersion: function() {
99100
if (os.type() == 'Windows_NT') {
100-
if (os.arch() == 'x64') {
101-
return iePrefix + 'x64_';
101+
if (this.selectIe32 || os.arch() != 'x64') {
102+
return '_Win32_' + this.version;
102103
} else {
103-
return iePrefix + 'Win32_';
104+
return '_x64_' + this.version;
104105
}
105106
}
106-
return iePrefix;
107-
},
108-
version: function() {
109-
return ieVersion;
107+
return '';
110108
},
111109
suffix: function() {
112110
return '.zip';
113111
},
114112
filename: function() {
115-
return this.prefix() + this.version() + this.suffix();
113+
return this.prefix + this.getVersion() + this.suffix();
116114
},
117115
cdn: 'https://selenium-release.storage.googleapis.com/',
118116
url: function() {
119-
return this.cdn + shortVersion(this.version()) + '/' +
120-
this.prefix() + this.version() + this.suffix();
121-
}
122-
},
123-
ie32: {
124-
name: 'IEDriver-32bit',
125-
isDefault: false,
126-
osType: 'Windows_NT',
127-
defaultVersion: versions.iedriver,
128-
prefix: function() {
129-
if (os.type() == 'Windows_NT') {
130-
return iePrefix + 'Win32_';
131-
}
132-
},
133-
version: function() {
134-
return ieVersion;
135-
},
136-
suffix: function() {
137-
return '.zip';
138-
},
139-
filename: function() {
140-
return this.prefix() + this.version() + this.suffix();
141-
},
142-
cdn: 'https://selenium-release.storage.googleapis.com/',
143-
url: function() {
144-
return this.cdn + shortVersion(this.version()) + '/' +
145-
this.prefix() + this.version() + this.suffix();
117+
return this.cdn + shortVersion(this.version) + '/' +
118+
this.prefix + this.getVersion() + this.suffix();
146119
}
147120
}
148121
};
@@ -161,13 +134,13 @@ var cli = optimist.
161134
describe('versions.standalone', 'Optional selenium standalone server version').
162135
default('versions.standalone', versions.selenium).
163136
string('versions.standalone').
164-
describe('versions.chromedriver', 'Optional chrome driver version').
165-
default('versions.chromedriver', versions.chromedriver).
166-
string('versions.chromedriver');
137+
describe('versions.chrome', 'Optional chrome driver version').
138+
default('versions.chrome', versions.chromedriver).
139+
string('versions.chrome');
167140
if (os.type() == 'Windows_NT') {
168-
cli.describe('versions.iedriver', 'Optional internet explorer version').
169-
default('versions.iedriver', versions.iedriver).
170-
string('versions.iedriver');
141+
cli.describe('versions.ie', 'Optional internet explorer version').
142+
default('versions.ie', versions.iedriver).
143+
string('versions.ie');
171144
}
172145
cli.describe('ignore_ssl', 'Ignore SSL certificates').boolean('ignore_ssl').
173146
default('ignore_ssl', false).
@@ -180,6 +153,12 @@ for (var bin in binaries) {
180153
boolean(bin).
181154
default(bin, binaries[bin].isDefault);
182155
}
156+
157+
}
158+
if (os.type() == 'Windows_NT') {
159+
cli.describe('ie32', 'Install or update IEDriver 32-bit (overrides ie option)').
160+
boolean('ie32').
161+
default('ie32', false);
183162
}
184163

185164
var argv = cli.
@@ -279,10 +258,10 @@ var spawnCommand = function(command, args) {
279258
*/
280259
var downloadIfNew = function(bin, outputDir, existingFiles, opt_callback) {
281260
if (!bin.exists) {
282-
console.log('Updating ' + bin.name + ' to version ' + bin.version());
261+
console.log('Updating ' + bin.name + ' to version ' + bin.version);
283262
var url = bin.url();
284263
if (!url) {
285-
console.error(bin.name + ' v' + bin.version() +
264+
console.error(bin.name + ' v' + bin.version +
286265
' is not available for your system.');
287266
return;
288267
}
@@ -313,24 +292,22 @@ var existingFiles = fs.readdirSync(argv.out_dir);
313292

314293
// update versions
315294
if (argv.versions) {
316-
if (argv.versions.standalone) {
317-
seleniumVersion = argv.versions.standalone;
318-
}
319-
if (argv.versions.chromedriver) {
320-
chromeVersion = argv.versions.chromedriver;
321-
}
322-
if (argv.versions.iedriver) {
323-
ieVersion = argv.versions.iedriver;
295+
for (binary in argv.versions) {
296+
if (binaries[binary]) {
297+
binaries[binary].version = argv.versions[binary];
298+
}
324299
}
325-
326300
}
327301

302+
// update the ie32 flag
303+
binaries.ie.selectIe32 = argv.ie32;
304+
328305
for (name in binaries) {
329306
bin = binaries[name];
330307
bin.cdn = argv.alternate_cdn || bin.cdn;
331308
var exists = fs.existsSync(path.join(argv.out_dir, bin.filename()));
332309
var outOfDateExists = existingFiles.some(function(file) {
333-
return file.indexOf(bin.prefix()) !== -1 && file !== bin.filename();
310+
return file.indexOf(bin.prefix !== -1 && file !== bin.filename());
334311
});
335312
bin.exists = exists;
336313
bin.outOfDateExists = outOfDateExists;
@@ -351,12 +328,12 @@ switch (argv._[0]) {
351328
if (binaries.chrome.exists) {
352329
args.push('-Dwebdriver.chrome.driver=' +
353330
path.join(argv.out_dir, executableName(
354-
binaries.chrome.prefix() + binaries.chrome.version())));
331+
binaries.chrome.prefix + binaries.chrome.getVersion())));
355332
}
356-
if (binaries.ie.exists || binaries.ie32.exists) {
333+
if (binaries.ie.exists) {
357334
args.push('-Dwebdriver.ie.driver=' +
358335
path.join(argv.out_dir, executableName(
359-
binaries.ie.prefix() + binaries.ie.version())));
336+
binaries.ie.prefix + binaries.ie.getVersion())));
360337
}
361338
var seleniumProcess = spawnCommand('java', args);
362339
console.log('seleniumProcess.pid: ' + seleniumProcess.pid);
@@ -385,10 +362,10 @@ switch (argv._[0]) {
385362
if (existFile.endsWith('.zip')) {
386363
continue;
387364
}
388-
if (existFile.includes(bin.prefix())) {
365+
if (existFile.includes(bin.prefix)) {
389366
binaryExists = true;
390367
versionsDl.push(existFile
391-
.replace(bin.prefix(),'').replace(bin.suffix(),''));
368+
.replace(bin.prefix,'').replace(bin.suffix(),''));
392369
}
393370
}
394371

@@ -402,6 +379,12 @@ switch (argv._[0]) {
402379
}
403380
for (var versionPos in versionsDl) {
404381
var version = versionsDl[versionPos];
382+
if (version.endsWith('.exe')) {
383+
version = version.replace('.exe', '');
384+
}
385+
if (version.startsWith('_')) {
386+
version = version.substring(1, version.length);
387+
}
405388
versionLog += version;
406389
if (version == bin.defaultVersion) {
407390
versionLog += ' [default]'
@@ -428,39 +411,27 @@ switch (argv._[0]) {
428411
// windows: chromedriver.exe
429412
zip.extractAllTo(argv.out_dir, true);
430413
if (os.type() != 'Windows_NT') {
431-
var filePath = path.join(argv.out_dir, binaries.chrome.prefix() +
432-
binaries.chrome.version());
414+
var filePath = path.join(argv.out_dir, binaries.chrome.prefix +
415+
binaries.chrome.getVersion());
433416
fs.renameSync(path.join(argv.out_dir, 'chromedriver'), filePath);
434417
fs.chmodSync(filePath, 0755);
435418
}
436419
else {
437-
var filePath = path.join(argv.out_dir, binaries.chrome.prefix() +
438-
binaries.chrome.version() + '.exe');
420+
var filePath = path.join(argv.out_dir, binaries.chrome.prefix +
421+
binaries.chrome.getVersion() + '.exe');
439422
fs.renameSync(path.join(argv.out_dir, 'chromedriver.exe'), filePath);
440423
}
441424
});
442425
}
443-
if (argv.ie) {
444-
downloadIfNew(binaries.ie, argv.out_dir, existingFiles,
445-
function(filename) {
446-
var zip = new AdmZip(filename);
447-
// Expected contents of the zip:
448-
// IEDriverServer.exe
449-
zip.extractAllTo(argv.out_dir, true);
450-
var filePath = path.join(argv.out_dir, bianries.ie.prefix() +
451-
binaries.ie.version());
452-
fs.renameSync(path.join(argv.out_dir, 'IEDriverServer.exe'), filePath);
453-
});
454-
}
455-
if (argv.ie32) {
456-
downloadIfNew(binaries.ie32, argv.out_dir, existingFiles,
426+
if (argv.ie || argv.ie32) {
427+
downloadIfNew(binaries.ie, argv.out_dir, existingFiles,
457428
function(filename) {
458429
var zip = new AdmZip(filename);
459430
// Expected contents of the zip:
460431
// IEDriverServer.exe
461432
zip.extractAllTo(argv.out_dir, true);
462-
var filePath = path.join(argv.out_dir, bianries.ie32.prefix() +
463-
binaries.ie32.version());
433+
var filePath = path.join(argv.out_dir, binaries.ie.prefix +
434+
binaries.ie.getVersion());
464435
fs.renameSync(path.join(argv.out_dir, 'IEDriverServer.exe'), filePath);
465436
});
466437
}
@@ -469,11 +440,7 @@ switch (argv._[0]) {
469440
existingFiles.forEach(function(file) {
470441
for (var binPos in binaries) {
471442
var bin = binaries[binPos];
472-
var prefix = bin.prefix();
473-
if (prefix && (prefix.endsWith('_') || prefix.endsWith('-'))) {
474-
prefix = prefix.substring(0, prefix.length - 1);
475-
}
476-
if (file.indexOf(prefix) != -1) {
443+
if (file.indexOf(bin.prefix) != -1) {
477444
fs.unlinkSync(path.join(argv.out_dir, file));
478445
}
479446
}

Diff for: config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"webdriverVersions": {
3-
"selenium": "2.51.0",
3+
"selenium": "2.52.0",
44
"chromedriver": "2.21",
5-
"iedriver": "2.51.0"
5+
"iedriver": "2.52.0"
66
}
77
}

0 commit comments

Comments
 (0)