diff --git a/packages/cli/src/bin/index.ts b/packages/cli/src/bin/index.ts index 541a2d9e..15c4678c 100644 --- a/packages/cli/src/bin/index.ts +++ b/packages/cli/src/bin/index.ts @@ -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, @@ -107,7 +108,31 @@ 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(`\nPlease install a matching version of ChromeDriver and run axe with the --chromedriver-path option: + + $ npm install -g chromedriver@ + $ axe --chromedriver-path $(npm root -g)/chromedriver/bin/chromedriver + +(where is the first number of the "current browser version" reported above.)`); + process.exit(2); + } else { + throw e; + } + } if (silentMode) { process.stdout.write(JSON.stringify(outcome, null, 2)); return;