1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

[e2e]: log exceptions when tests fail (#16453)

* log exceptions inc background

* show full stacktrace

* use driver api

* lint
This commit is contained in:
Peter Yinusa 2022-11-14 14:35:08 +00:00 committed by GitHub
parent 8f30e03613
commit b2293e6648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 5 deletions

View File

@ -51,6 +51,8 @@ async function withFixtures(options, testSuite) {
const phishingPageServer = new PhishingWarningPageServer(); const phishingPageServer = new PhishingWarningPageServer();
let webDriver; let webDriver;
let driver;
const errors = [];
let failed = false; let failed = false;
try { try {
await ganacheServer.start(ganacheOptions); await ganacheServer.start(ganacheOptions);
@ -110,8 +112,12 @@ async function withFixtures(options, testSuite) {
) { ) {
await ensureXServerIsRunning(); await ensureXServerIsRunning();
} }
const { driver } = await buildWebDriver(driverOptions); driver = (await buildWebDriver(driverOptions)).driver;
webDriver = driver; webDriver = driver.driver;
if (process.env.SELENIUM_BROWSER === 'chrome') {
await driver.checkBrowserForExceptions();
}
await testSuite({ await testSuite({
driver, driver,
@ -120,7 +126,7 @@ async function withFixtures(options, testSuite) {
}); });
if (process.env.SELENIUM_BROWSER === 'chrome') { if (process.env.SELENIUM_BROWSER === 'chrome') {
const errors = await driver.checkBrowserForConsoleErrors(driver); errors.concat(await driver.checkBrowserForConsoleErrors(driver));
if (errors.length) { if (errors.length) {
const errorReports = errors.map((err) => err.message); const errorReports = errors.map((err) => err.message);
const errorMessage = `Errors found in browser console:\n${errorReports.join( const errorMessage = `Errors found in browser console:\n${errorReports.join(
@ -137,10 +143,20 @@ async function withFixtures(options, testSuite) {
failed = true; failed = true;
if (webDriver) { if (webDriver) {
try { try {
await webDriver.verboseReportOnFailure(title); await driver.verboseReportOnFailure(title);
} catch (verboseReportError) { } catch (verboseReportError) {
console.error(verboseReportError); console.error(verboseReportError);
} }
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; throw error;
} finally { } finally {
@ -151,7 +167,7 @@ async function withFixtures(options, testSuite) {
await secondaryGanacheServer.quit(); await secondaryGanacheServer.quit();
} }
if (webDriver) { if (webDriver) {
await webDriver.quit(); await driver.quit();
} }
if (dapp) { if (dapp) {
for (let i = 0; i < numberOfDapps; i++) { for (let i = 0; i < numberOfDapps; i++) {

View File

@ -49,6 +49,7 @@ class Driver {
this.browser = browser; this.browser = browser;
this.extensionUrl = extensionUrl; this.extensionUrl = extensionUrl;
this.timeout = timeout; this.timeout = timeout;
this.exceptions = [];
// The following values are found in // The following values are found in
// https://github.com/SeleniumHQ/selenium/blob/trunk/javascript/node/selenium-webdriver/lib/input.js#L50-L110 // 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. // These should be replaced with string constants 'Enter' etc for playwright.
@ -429,6 +430,15 @@ class Driver {
return browserLogs; return browserLogs;
} }
async checkBrowserForExceptions() {
const { exceptions } = this;
const cdpConnection = await this.driver.createCDPConnection('page');
await this.driver.onLogException(cdpConnection, function (exception) {
const { description } = exception.exceptionDetails.exception;
exceptions.push(description);
});
}
async checkBrowserForConsoleErrors() { async checkBrowserForConsoleErrors() {
const ignoredLogTypes = ['WARNING']; const ignoredLogTypes = ['WARNING'];
const ignoredErrorMessages = [ const ignoredErrorMessages = [