Skip to content

Commit

Permalink
log exceptions inc background
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterYinusa committed Nov 10, 2022
1 parent 4b08d2e commit 475bc91
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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') {
Expand All @@ -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++) {
Expand Down

0 comments on commit 475bc91

Please sign in to comment.