Skip to content

Commit 63c7d4e

Browse files
feat(cli): better error message for ChromeDriver version mismatch
Fixes #679.
1 parent b142be9 commit 63c7d4e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/cli/src/bin/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import axeTestUrls from '../lib/axe-test-urls';
1616
import event from '../lib/events';
1717
import { startDriver } from '../lib/webdriver';
18+
import { error as selenium_error } from 'selenium-webdriver';
1819

1920
const cli = async (
2021
args: OptionValues,
@@ -107,7 +108,28 @@ const cli = async (
107108
disable
108109
};
109110
try {
110-
const outcome = await axeTestUrls(urls, testPageConfigParams, events);
111+
let outcome;
112+
try {
113+
outcome = await axeTestUrls(urls, testPageConfigParams, events);
114+
} catch (e) {
115+
// Provide a more user-friendly error message when there's a ChromeDriver/Chrome version mismatch.
116+
if (e instanceof selenium_error.SessionNotCreatedError && e.message.includes(
117+
'This version of ChromeDriver only supports'
118+
// This string has to match the error message printed by chromedriver, see
119+
// https://chromium.googlesource.com/chromium/src/+/refs/tags/110.0.5481.194/chrome/test/chromedriver/chrome_launcher.cc#300.
120+
)) {
121+
console.error(error('Error: %s'), e.message);
122+
console.log(`\nConsider installing a matching version of ChromeDriver with:
123+
124+
npm install -g chromedriver@<version>
125+
126+
(where <version> is the desired version of Chromedriver.)
127+
And running \`axe\` with \`--chromedriver-path $(npm root -g)/chromedriver/bin/chromedriver\`.`)
128+
process.exit(2);
129+
} else {
130+
throw e;
131+
}
132+
}
111133
if (silentMode) {
112134
process.stdout.write(JSON.stringify(outcome, null, 2));
113135
return;

0 commit comments

Comments
 (0)