Skip to content

Commit

Permalink
feat(cli): better error message for ChromeDriver version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
not-my-profile committed Mar 6, 2023
1 parent b142be9 commit 63c7d4e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/cli/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import axeTestUrls from '../lib/axe-test-urls';
import event from '../lib/events';
import { startDriver } from '../lib/webdriver';
import { error as selenium_error } from 'selenium-webdriver';

const cli = async (
args: OptionValues,
Expand Down Expand Up @@ -107,7 +108,28 @@ const cli = async (
disable
};
try {
const outcome = await axeTestUrls(urls, testPageConfigParams, events);
let outcome;
try {
outcome = await axeTestUrls(urls, testPageConfigParams, events);
} catch (e) {
// Provide a more user-friendly error message when there's a ChromeDriver/Chrome version mismatch.
if (e instanceof selenium_error.SessionNotCreatedError && e.message.includes(
'This version of ChromeDriver only supports'
// This string has to match the error message printed by chromedriver, see
// https://chromium.googlesource.com/chromium/src/+/refs/tags/110.0.5481.194/chrome/test/chromedriver/chrome_launcher.cc#300.
)) {
console.error(error('Error: %s'), e.message);
console.log(`\nConsider installing a matching version of ChromeDriver with:
npm install -g chromedriver@<version>
(where <version> is the desired version of Chromedriver.)
And running \`axe\` with \`--chromedriver-path $(npm root -g)/chromedriver/bin/chromedriver\`.`)
process.exit(2);
} else {
throw e;
}
}
if (silentMode) {
process.stdout.write(JSON.stringify(outcome, null, 2));
return;
Expand Down

0 comments on commit 63c7d4e

Please sign in to comment.