Skip to content

Commit c9a52b2

Browse files
authored
feat(max_versions): set max versions based on string matching (#369)
- Do a version match based on string startsWith of the maxVersion An example: Matching "0.1" might find versions 0.14.0, 0.151.0, 0.1.0. It will then get the max version which is 0.151. If a user wanted to get 0.1, then they could specify version "0.1." - Added a unit test to the version_list to find max versions. - Fix / update interchangable aliases: - selenium == standalone - chromedriver == chrome - geckodriver == gecko - iedriver = ie Tagging #280, #358, #353. Additional work is still required to have a config file that has this information instead of hard coding it.
1 parent 0b8679b commit c9a52b2

13 files changed

+258
-134
lines changed

lib/cli/index.ts

+99-38
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import * as start from '../cmds/start';
55
import * as status from '../cmds/status';
66
import * as update from '../cmds/update';
77

8-
const CHROME = 'chrome';
9-
const chromeOption: yargs.Options = {
8+
const CHROMEDRIVER_ALIAS = 'chrome';
9+
const CHROMEDRIVER = 'chromedriver';
10+
const chromedriverOption: yargs.Options = {
1011
describe: 'Install or update chromedriver.',
1112
default: true,
1213
type: 'boolean'
1314
};
14-
const CHROME_LOGS = 'chrome_logs';
15-
const chromeLogsOption: yargs.Options = {
15+
const CHROMEDRIVER_LOGS_ALIAS = 'chrome_logs';
16+
const CHROMEDRIVER_LOGS = 'chromedriver_logs';
17+
const chromedriverLogsOption: yargs.Options = {
1618
describe: 'File path to chrome logs.',
1719
type: 'string'
1820
};
@@ -30,8 +32,9 @@ const edgeOption: yargs.Options = {
3032
'"C:\Program Files (x86)\Microsoft Web Driver\MirosoftWebDriver.exe"',
3133
type: 'string'
3234
};
33-
const GECKO = 'gecko';
34-
const geckoOption: yargs.Options = {
35+
const GECKODRIVER_ALIAS = 'gecko';
36+
const GECKODRIVER = 'geckodriver';
37+
const geckodriverOption: yargs.Options = {
3538
describe: 'Install or update geckodriver.',
3639
default: true,
3740
type: 'boolean'
@@ -41,8 +44,9 @@ const githubTokenOption: yargs.Options = {
4144
describe: 'Use a GitHub token to prevent rate limit issues.',
4245
type: 'string'
4346
};
47+
const IEDRIVER_ALIAS = 'ie';
4448
const IEDRIVER = 'iedriver';
45-
const ieOption: yargs.Options = {
49+
const iedriverOption: yargs.Options = {
4650
describe: 'Install or update ie driver.',
4751
default: false,
4852
type: 'boolean'
@@ -58,6 +62,31 @@ const logLevelOption: yargs.Options = {
5862
default: 'info',
5963
type: 'string'
6064
};
65+
const MAX_VERSIONS_CHROMEDRIVER_ALIAS = 'max_versions.chrome';
66+
const MAX_VERSIONS_CHROMEDRIVER = 'max_versions.chromedriver';
67+
const maxVersionsChromedriverOption: yargs.Options = {
68+
describe: 'The chromedriver max version used only for update.',
69+
type: 'string'
70+
};
71+
const MAX_VERSIONS_GECKODRIVER_ALIAS = 'max_versions.gecko';
72+
const MAX_VERSIONS_GECKODRIVER = 'max_versions.geckodriver';
73+
const maxVersionsGeckodriverOption: yargs.Options = {
74+
describe: 'The geckodriver max version used only for update.',
75+
type: 'string'
76+
};
77+
const MAX_VERSIONS_IEDRIVER_ALIAS = 'max_versions.ie';
78+
const MAX_VERSIONS_IEDRIVER = 'max_versions.iedriver';
79+
const maxVersionsIedriverOption: yargs.Options = {
80+
describe: 'The ie driver max version used only for update.',
81+
type: 'string'
82+
};
83+
const MAX_VERSIONS_SELENIUM_ALIAS = 'max_versions.standalone';
84+
const MAX_VERSIONS_SELENIUM = 'max_versions.selenium';
85+
const maxVersionsSeleniumOption: yargs.Options = {
86+
describe: 'The selenium server standalone max version used only for update.',
87+
type: 'string'
88+
};
89+
6190
const OUT_DIR = 'out_dir';
6291
const outDirOption: yargs.Options = {
6392
describe: 'Location of output.',
@@ -79,34 +108,40 @@ const seleniumLogLevelOption: yargs.Options = {
79108
describe: 'Set the -Dselenium.LOGGER.level flag when starting the server',
80109
type: 'string'
81110
};
82-
const STANDALONE = 'standalone';
83-
const standaloneOption: yargs.Options = {
111+
const SELENIUM_ALIAS = 'standalone';
112+
const SELENIUM = 'selenium';
113+
const seleniumOption: yargs.Options = {
84114
describe: 'Install or update selenium server standalone.',
85115
default: true,
86116
type: 'boolean'
87117
};
88-
const STANDALONE_NODE = 'standalone_node';
89-
const standaloneNodeOption: yargs.Options = {
118+
const SELENIUM_NODE_ALIAS = 'standalone_node';
119+
const SELENIUM_NODE = 'selenium_node';
120+
const seleniumNodeOption: yargs.Options = {
90121
describe: 'Start the selenium server standalone with role set to "node".',
91122
type: 'boolean'
92123
};
93-
const VERSIONS_CHROME = 'versions.chrome';
94-
const versionsChromeOption: yargs.Options = {
124+
const VERSIONS_CHROMEDRIVER_ALIAS = 'versions.chrome';
125+
const VERSIONS_CHROMEDRIVER = 'versions.chromedriver';
126+
const versionsChromedriverOption: yargs.Options = {
95127
describe: 'The chromedriver version.',
96128
type: 'string'
97129
};
98-
const VERSIONS_GECKO = 'versions.gecko';
99-
const versionsGeckoOption: yargs.Options = {
130+
const VERSIONS_GECKODRIVER_ALIAS = 'versions.gecko';
131+
const VERSIONS_GECKODRIVER = 'versions.geckodriver';
132+
const versionsGeckodriverOption: yargs.Options = {
100133
describe: 'The geckodriver version.',
101134
type: 'string'
102135
};
103-
const VERSIONS_IE = 'versions.ie';
104-
const versionsIeOption: yargs.Options = {
136+
const VERSIONS_IEDRIVER_ALIAS = 'versions.ie';
137+
const VERSIONS_IEDRIVER = 'versions.iedriver';
138+
const versionsIedriverOption: yargs.Options = {
105139
describe: 'The ie driver version.',
106140
type: 'string'
107141
};
108-
const VERSIONS_STANDALONE = 'versions.standalone';
109-
const versionsStandaloneOption: yargs.Options = {
142+
const VERSIONS_SELENIUM_ALIAS = 'versions.standalone';
143+
const VERSIONS_SELENIUM = 'versions.selenium';
144+
const versionsSeleniumOption: yargs.Options = {
110145
describe: 'The selenium server standalone version.',
111146
type: 'string'
112147
};
@@ -133,22 +168,33 @@ yargs
133168
.command(
134169
'start', 'Start up the selenium server.',
135170
(yargs: yargs.Argv) => {
136-
return yargs.option(CHROME, chromeOption)
137-
.option(CHROME_LOGS, chromeLogsOption)
171+
return yargs
172+
.option(CHROMEDRIVER, chromedriverOption)
173+
.alias(CHROMEDRIVER_ALIAS, CHROMEDRIVER)
174+
.option(CHROMEDRIVER_LOGS, chromedriverLogsOption)
175+
.alias(CHROMEDRIVER_LOGS_ALIAS, CHROMEDRIVER_LOGS)
138176
.option(DETACH, detachOption)
139177
.option(EDGE, edgeOption)
140-
.option(GECKO, geckoOption)
141-
.option(IEDRIVER, ieOption)
178+
.option(GECKODRIVER, geckodriverOption)
179+
.alias(GECKODRIVER_ALIAS, GECKODRIVER)
180+
.option(IEDRIVER, iedriverOption)
181+
.alias(IEDRIVER_ALIAS, IEDRIVER)
142182
.option(LOG_LEVEL, logLevelOption)
143183
.option(OUT_DIR, outDirOption)
144-
.option(SELENIUM_PORT, seleniumPort)
184+
.option(SELENIUM, seleniumOption)
185+
.alias(SELENIUM_ALIAS, SELENIUM)
145186
.option(SELENIUM_LOG_LEVEL, seleniumLogLevelOption)
146-
.option(STANDALONE, standaloneOption)
147-
.option(STANDALONE_NODE, standaloneNodeOption)
148-
.option(VERSIONS_CHROME, versionsChromeOption)
149-
.option(VERSIONS_GECKO, versionsGeckoOption)
150-
.option(VERSIONS_IE, versionsIeOption)
151-
.option(VERSIONS_STANDALONE, versionsStandaloneOption);
187+
.option(SELENIUM_NODE, seleniumNodeOption)
188+
.alias(SELENIUM_NODE_ALIAS, SELENIUM_NODE)
189+
.option(SELENIUM_PORT, seleniumPort)
190+
.option(VERSIONS_CHROMEDRIVER, versionsChromedriverOption)
191+
.alias(VERSIONS_CHROMEDRIVER_ALIAS, VERSIONS_CHROMEDRIVER)
192+
.option(VERSIONS_GECKODRIVER, versionsGeckodriverOption)
193+
.alias(VERSIONS_GECKODRIVER_ALIAS, VERSIONS_GECKODRIVER)
194+
.option(VERSIONS_IEDRIVER, versionsIedriverOption)
195+
.alias(VERSIONS_IEDRIVER_ALIAS, VERSIONS_IEDRIVER)
196+
.option(VERSIONS_SELENIUM, versionsSeleniumOption)
197+
.alias(VERSIONS_SELENIUM_ALIAS, VERSIONS_SELENIUM);
152198
},
153199
(argv: yargs.Arguments) => {
154200
start.handler(argv);
@@ -166,19 +212,34 @@ yargs
166212
'update', 'Install or update selected binaries.',
167213
(yargs: yargs.Argv) => {
168214
return yargs.option(OUT_DIR, outDirOption)
169-
.option(CHROME, chromeOption)
170-
.option(GECKO, geckoOption)
215+
.option(CHROMEDRIVER, chromedriverOption)
216+
.alias(CHROMEDRIVER_ALIAS, CHROMEDRIVER)
217+
.option(GECKODRIVER, geckodriverOption)
218+
.alias(GECKODRIVER_ALIAS, GECKODRIVER)
171219
.option(GITHUB_TOKEN, githubTokenOption)
172-
.option(IEDRIVER, ieOption)
220+
.option(IEDRIVER, iedriverOption)
221+
.alias(IEDRIVER_ALIAS, IEDRIVER)
173222
.option(IGNORE_SSL, ignoreSSLOption)
174223
.option(LOG_LEVEL, logLevelOption)
224+
.option(MAX_VERSIONS_CHROMEDRIVER, maxVersionsChromedriverOption)
225+
.alias(MAX_VERSIONS_CHROMEDRIVER_ALIAS, MAX_VERSIONS_CHROMEDRIVER)
226+
.option(MAX_VERSIONS_GECKODRIVER, maxVersionsGeckodriverOption)
227+
.alias(MAX_VERSIONS_GECKODRIVER_ALIAS, MAX_VERSIONS_GECKODRIVER)
228+
.option(MAX_VERSIONS_IEDRIVER, maxVersionsIedriverOption)
229+
.alias(MAX_VERSIONS_IEDRIVER_ALIAS, MAX_VERSIONS_IEDRIVER)
230+
.option(MAX_VERSIONS_SELENIUM, maxVersionsSeleniumOption)
175231
.option(OUT_DIR, outDirOption)
176232
.option(PROXY, proxyOption)
177-
.option(STANDALONE, standaloneOption)
178-
.option(VERSIONS_CHROME, versionsChromeOption)
179-
.option(VERSIONS_GECKO, versionsGeckoOption)
180-
.option(VERSIONS_IE, versionsIeOption)
181-
.option(VERSIONS_STANDALONE, versionsStandaloneOption);
233+
.option(SELENIUM, seleniumOption)
234+
.alias(SELENIUM_ALIAS, SELENIUM)
235+
.option(VERSIONS_CHROMEDRIVER, versionsChromedriverOption)
236+
.alias(VERSIONS_CHROMEDRIVER_ALIAS, VERSIONS_CHROMEDRIVER)
237+
.option(VERSIONS_GECKODRIVER, versionsGeckodriverOption)
238+
.alias(VERSIONS_GECKODRIVER_ALIAS, VERSIONS_GECKODRIVER)
239+
.option(VERSIONS_IEDRIVER, versionsIedriverOption)
240+
.alias(VERSIONS_IEDRIVER_ALIAS, VERSIONS_IEDRIVER)
241+
.option(VERSIONS_SELENIUM, versionsSeleniumOption)
242+
.alias(VERSIONS_SELENIUM_ALIAS, VERSIONS_SELENIUM);
182243
},
183244
(argv: yargs.Arguments) => {
184245
update.handler(argv);

lib/cmds/cmds.spec-e2e.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ describe('using the cli', () => {
3939
it('should download the files', async () => {
4040
const argv = {
4141
_: ['foobar'],
42-
chrome: true,
43-
standalone: true,
42+
chromedriver: true,
43+
selenium: true,
4444
out_dir: tmpDir,
4545
'$0': 'bin\\webdriver-manager'
4646
};
@@ -70,9 +70,9 @@ describe('using the cli', () => {
7070
it('should start the selenium server standalone in role=node', async () => {
7171
const argv = {
7272
_: ['foobar'],
73-
chrome: true,
74-
standalone: true,
75-
standalone_node: true,
73+
chromedriver: true,
74+
selenium: true,
75+
selenium_node: true,
7676
out_dir: tmpDir,
7777
'$0': 'bin\\webdriver-manager'
7878
};
@@ -104,8 +104,8 @@ describe('using the cli', () => {
104104
it('should start the selenium server standalone', async () => {
105105
const argv = {
106106
_: ['foobar'],
107-
chrome: true,
108-
standalone: true,
107+
chromedriver: true,
108+
selenium: true,
109109
out_dir: tmpDir,
110110
'$0': 'bin\\webdriver-manager'
111111
};

lib/cmds/options.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ export interface Options {
1616
githubToken?: string;
1717
}
1818

19+
export type BrowserDriverName = 'chromedriver'|'geckodriver'|'iedriver';
20+
1921
/**
2022
* Contains information about a browser driver.
2123
*/
2224
export interface BrowserDriver {
2325
// The name of the browser driver.
24-
name?: 'chromedriver'|'geckodriver'|'iedriver';
26+
name?: BrowserDriverName;
2527
// The version which does not have to follow semver.
2628
version?: string;
29+
// A max version that either fully or partially matches the version.
30+
maxVersion?: string;
2731
}
2832

2933
/**
@@ -35,6 +39,8 @@ export interface Server {
3539
name?: 'selenium';
3640
// The version which does not have to follow semver.
3741
version?: string;
42+
// A max version that either fully or partially matches the version.
43+
maxVersion?: string;
3844
// Run as role = node option.
3945
runAsNode?: boolean;
4046
// The relative or full path to the chrome logs file.

lib/cmds/update.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const log = loglevel.getLogger('webdriver-manager');
1111
* @param argv The argv from yargs.
1212
*/
1313
export async function handler(argv: yargs.Arguments) {
14-
log.setLevel(argv.log_level);
14+
log.setLevel(argv['log_level']);
1515
const options = convertArgs2Options(argv);
1616
await update(options);
1717
}
@@ -35,12 +35,14 @@ export function updateBinary(optionsBinary: OptionsBinary): Promise<void[]> {
3535
const promises = [];
3636
if (optionsBinary.browserDrivers) {
3737
for (const provider of optionsBinary.browserDrivers) {
38-
promises.push(provider.binary.updateBinary(provider.version));
38+
promises.push(provider.binary.updateBinary(provider.version,
39+
provider.maxVersion));
3940
}
4041
}
4142
if (optionsBinary.server && optionsBinary.server.binary) {
4243
promises.push(
43-
optionsBinary.server.binary.updateBinary(optionsBinary.server.version));
44+
optionsBinary.server.binary.updateBinary(optionsBinary.server.version,
45+
optionsBinary.server.maxVersion));
4446
}
4547
return Promise.all(promises);
4648
}

lib/cmds/utils.spec-unit.ts

+5-19
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,16 @@ describe('utils', () => {
66
const argv = {
77
_: ['foobar'],
88
proxy: 'http://some.proxy.com',
9-
versions: {gecko: '0.16.0', chrome: '2.20'},
9+
versions: {geckodriver: '0.16.0', chromedriver: '2.20'},
1010
out_dir: 'foobar_download',
1111
ignore_ssl: false,
1212
'$0': 'bin\\webdriver-manager'
1313
};
1414
const options = convertArgs2AllOptions(argv);
1515
expect(options.browserDrivers).toBeTruthy();
1616
expect(options.browserDrivers.length).toBe(3);
17-
for (const provider of options.browserDrivers) {
18-
if (provider.name === 'geckodriver') {
19-
expect(provider.version).toBe('0.16.0');
20-
}
21-
if (provider.name === 'chromedriver') {
22-
expect(provider.version).toBe('2.20');
23-
}
24-
if (provider.name === 'iedriver') {
25-
expect(provider.version).toBeUndefined();
26-
}
27-
}
2817
expect(options.server).toBeTruthy();
2918
expect(options.server.name).toBe('selenium');
30-
expect(options.server.version).toBeUndefined();
31-
expect(options.proxy).toBe('http://some.proxy.com');
32-
expect(options.ignoreSSL).toBeFalsy();
3319
expect(options.outDir).toBe('foobar_download');
3420
});
3521
});
@@ -38,10 +24,10 @@ describe('utils', () => {
3824
it('should create the default providers', () => {
3925
const argv = {
4026
_: ['foobar'],
41-
chrome: true,
42-
gecko: true,
43-
standalone: true,
44-
versions: {gecko: '0.16.0', chrome: '2.20'},
27+
chromedriver: true,
28+
geckodriver: true,
29+
selenium: true,
30+
versions: {geckodriver: '0.16.0', chromedriver: '2.20'},
4531
out_dir: 'foobar_download',
4632
'$0': 'bin\\webdriver-manager'
4733
};

0 commit comments

Comments
 (0)