From 475bc91a3b00715215b04b85bc15a6a917e3b9c7 Mon Sep 17 00:00:00 2001 From: PeterYinusa Date: Thu, 10 Nov 2022 17:44:52 +0000 Subject: [PATCH 1/4] log exceptions inc background --- test/e2e/helpers.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index b3f74418a017..c7fa87e4486f 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -51,6 +51,9 @@ async function withFixtures(options, testSuite) { const phishingPageServer = new PhishingWarningPageServer(); let webDriver; + let driver; + const errors = []; + const exceptions = []; let failed = false; try { await ganacheServer.start(ganacheOptions); @@ -110,8 +113,18 @@ async function withFixtures(options, testSuite) { ) { await ensureXServerIsRunning(); } - const { driver } = await buildWebDriver(driverOptions); - webDriver = driver; + driver = (await buildWebDriver(driverOptions)).driver; + webDriver = driver.driver; + + if (process.env.SELENIUM_BROWSER === 'chrome') { + const cdpConnection = await webDriver.createCDPConnection('page'); + await webDriver.onLogException(cdpConnection, function (exception) { + const { description } = exception.exceptionDetails.exception; + const message = description.substring(0, description.indexOf('\n')); + exception.message = exception.message || message; + exceptions.push(exception); + }); + } await testSuite({ driver, @@ -120,7 +133,7 @@ async function withFixtures(options, testSuite) { }); if (process.env.SELENIUM_BROWSER === 'chrome') { - const errors = await driver.checkBrowserForConsoleErrors(driver); + errors.concat(await driver.checkBrowserForConsoleErrors(driver)); if (errors.length) { const errorReports = errors.map((err) => err.message); const errorMessage = `Errors found in browser console:\n${errorReports.join( @@ -137,11 +150,15 @@ async function withFixtures(options, testSuite) { failed = true; if (webDriver) { try { - await webDriver.verboseReportOnFailure(title); + await driver.verboseReportOnFailure(title); } catch (verboseReportError) { console.error(verboseReportError); } } + if (errors.length === 0 && exceptions.length > 0 && failOnConsoleError) { + const [exception] = exceptions; + throw Error(exception.message); + } throw error; } finally { if (!failed || process.env.E2E_LEAVE_RUNNING !== 'true') { @@ -151,7 +168,7 @@ async function withFixtures(options, testSuite) { await secondaryGanacheServer.quit(); } if (webDriver) { - await webDriver.quit(); + await driver.quit(); } if (dapp) { for (let i = 0; i < numberOfDapps; i++) { From f0a1eb880b4eb18818cee5157c1ad0b6000f3237 Mon Sep 17 00:00:00 2001 From: PeterYinusa Date: Fri, 11 Nov 2022 10:38:49 +0000 Subject: [PATCH 2/4] show full stacktrace --- test/e2e/helpers.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index c7fa87e4486f..791f0d887cd2 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -120,9 +120,7 @@ async function withFixtures(options, testSuite) { const cdpConnection = await webDriver.createCDPConnection('page'); await webDriver.onLogException(cdpConnection, function (exception) { const { description } = exception.exceptionDetails.exception; - const message = description.substring(0, description.indexOf('\n')); - exception.message = exception.message || message; - exceptions.push(exception); + exceptions.push(description); }); } @@ -157,7 +155,7 @@ async function withFixtures(options, testSuite) { } if (errors.length === 0 && exceptions.length > 0 && failOnConsoleError) { const [exception] = exceptions; - throw Error(exception.message); + throw Error(exception); } throw error; } finally { From a76177a20cef2f753b7440d57463c1a75c7dcf2b Mon Sep 17 00:00:00 2001 From: PeterYinusa Date: Fri, 11 Nov 2022 11:48:21 +0000 Subject: [PATCH 3/4] use driver api --- test/e2e/helpers.js | 17 +++++++---------- test/e2e/webdriver/driver.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 791f0d887cd2..cff2246d1645 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -53,7 +53,6 @@ async function withFixtures(options, testSuite) { let webDriver; let driver; const errors = []; - const exceptions = []; let failed = false; try { await ganacheServer.start(ganacheOptions); @@ -117,11 +116,7 @@ async function withFixtures(options, testSuite) { webDriver = driver.driver; if (process.env.SELENIUM_BROWSER === 'chrome') { - const cdpConnection = await webDriver.createCDPConnection('page'); - await webDriver.onLogException(cdpConnection, function (exception) { - const { description } = exception.exceptionDetails.exception; - exceptions.push(description); - }); + await driver.checkBrowserForExceptions(); } await testSuite({ @@ -152,10 +147,12 @@ async function withFixtures(options, testSuite) { } catch (verboseReportError) { console.error(verboseReportError); } - } - if (errors.length === 0 && exceptions.length > 0 && failOnConsoleError) { - const [exception] = exceptions; - throw Error(exception); + if (errors.length === 0 && driver.exceptions.length > 0 && failOnConsoleError) { + const errorMessage = `Errors found in browser console:\n${driver.exceptions.join( + '\n', + )}`; + throw Error(errorMessage); + } } throw error; } finally { diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 1969ddfcf5bb..6a63a862c4dc 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -49,6 +49,7 @@ class Driver { this.browser = browser; this.extensionUrl = extensionUrl; this.timeout = timeout; + this.exceptions = []; // The following values are found in // https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/input.js#L50-L110 // These should be replaced with string constants 'Enter' etc for playwright. @@ -429,6 +430,15 @@ class Driver { return browserLogs; } + async checkBrowserForExceptions() { + const exceptions = this.exceptions; + const cdpConnection = await this.driver.createCDPConnection('page'); + await this.driver.onLogException(cdpConnection, function (exception) { + const { description } = exception.exceptionDetails.exception; + exceptions.push(description); + }); + } + async checkBrowserForConsoleErrors() { const ignoredLogTypes = ['WARNING']; const ignoredErrorMessages = [ From 9d14fc26494e5480d521ca1931dd1ca50afdc82b Mon Sep 17 00:00:00 2001 From: PeterYinusa Date: Fri, 11 Nov 2022 11:49:02 +0000 Subject: [PATCH 4/4] lint --- test/e2e/helpers.js | 6 +++++- test/e2e/webdriver/driver.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index cff2246d1645..d950f0c0582d 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -147,7 +147,11 @@ async function withFixtures(options, testSuite) { } catch (verboseReportError) { console.error(verboseReportError); } - if (errors.length === 0 && driver.exceptions.length > 0 && failOnConsoleError) { + if ( + errors.length === 0 && + driver.exceptions.length > 0 && + failOnConsoleError + ) { const errorMessage = `Errors found in browser console:\n${driver.exceptions.join( '\n', )}`; diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 6a63a862c4dc..4507d490513d 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -431,7 +431,7 @@ class Driver { } async checkBrowserForExceptions() { - const exceptions = this.exceptions; + const { exceptions } = this; const cdpConnection = await this.driver.createCDPConnection('page'); await this.driver.onLogException(cdpConnection, function (exception) { const { description } = exception.exceptionDetails.exception;