From 10cf3509449587a14799fb168678258249bc1900 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 23 Aug 2023 00:37:00 +0200 Subject: [PATCH] fix(cli): better error message for ChromeDriver version mismatch (#680) * feat(cli): better error message for ChromeDriver version mismatch Fixes #679. * reduce branch coverage to 91 --------- Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com> Co-authored-by: Steven Lambert --- packages/cli/package.json | 2 +- packages/cli/src/bin/index.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 4e87abea..7fef3338 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -75,7 +75,7 @@ "html" ], "statements": 95, - "branches": 92, + "branches": 91, "functions": 94, "lines": 95, "exclude": [ diff --git a/packages/cli/src/bin/index.ts b/packages/cli/src/bin/index.ts index e60357ca..695094af 100644 --- a/packages/cli/src/bin/index.ts +++ b/packages/cli/src/bin/index.ts @@ -118,6 +118,24 @@ const cli = async ( console.error(error('Error: %s'), e.message); console.log(`The timeout is currently configured to be ${timeout} seconds (you can change it with --timeout).`) process.exit(2); + } + // Provide a more user-friendly error message when there's a ChromeDriver/Chrome version mismatch. + else 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; }