2022-05-13 17:55:34 +00:00
|
|
|
/* eslint-disable no-undef */
|
|
|
|
|
|
|
|
// This file extends the base functionality of the playwright test framework
|
|
|
|
const base = require('@playwright/test');
|
|
|
|
const { expect } = require('@playwright/test');
|
|
|
|
|
2022-06-08 20:05:08 +00:00
|
|
|
/**
|
|
|
|
* Takes a `ConsoleMessage` and returns a formatted string
|
|
|
|
* @param {import('@playwright/test').ConsoleMessage} msg
|
|
|
|
* @returns {String} formatted string with message type, text, url, and line and column numbers
|
|
|
|
*/
|
|
|
|
function consoleMessageToString(msg) {
|
|
|
|
const { url, lineNumber, columnNumber } = msg.location();
|
|
|
|
|
|
|
|
return `[${msg.type()}] ${msg.text()}
|
|
|
|
at (${url} ${lineNumber}:${columnNumber})`;
|
|
|
|
}
|
|
|
|
|
2022-05-13 17:55:34 +00:00
|
|
|
exports.test = base.test.extend({
|
|
|
|
page: async ({ baseURL, page }, use) => {
|
|
|
|
const messages = [];
|
2022-06-08 20:05:08 +00:00
|
|
|
page.on('console', (msg) => messages.push(msg));
|
2022-05-13 17:55:34 +00:00
|
|
|
await use(page);
|
2022-06-08 20:05:08 +00:00
|
|
|
messages.forEach(
|
|
|
|
msg => expect.soft(msg.type(), `Console error detected: ${consoleMessageToString(msg)}`).not.toEqual('error')
|
|
|
|
);
|
2022-05-13 17:55:34 +00:00
|
|
|
},
|
|
|
|
browser: async ({ playwright, browser }, use, workerInfo) => {
|
2022-06-08 20:05:08 +00:00
|
|
|
// Use browserless if configured
|
2022-05-13 17:55:34 +00:00
|
|
|
if (workerInfo.project.name.match(/browserless/)) {
|
|
|
|
const vBrowser = await playwright.chromium.connectOverCDP({
|
|
|
|
endpointURL: 'ws://localhost:3003'
|
|
|
|
});
|
|
|
|
await use(vBrowser);
|
|
|
|
} else {
|
|
|
|
// Use Local Browser for testing.
|
|
|
|
await use(browser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|