From fea7068f59e697a25c595662e03964f1273ba8ba Mon Sep 17 00:00:00 2001 From: Andrew Henry Date: Wed, 16 Apr 2025 17:48:20 -0700 Subject: [PATCH] Fixed broken tests --- e2e/baseFixtures.js | 25 ++++++++++++++++++++----- e2e/playwright-ci.config.js | 2 +- e2e/tests/functional/search.e2e.spec.js | 5 +++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/e2e/baseFixtures.js b/e2e/baseFixtures.js index 6d0662a875..5d9644f18c 100644 --- a/e2e/baseFixtures.js +++ b/e2e/baseFixtures.js @@ -103,25 +103,40 @@ const extendedTest = test.extend({ * Default: `true` */ failOnConsoleError: [true, { option: true }], + ignore404s: [[], { option: true }], /** * Extends the base page class to enable console log error detection. * @see {@link https://github.com/microsoft/playwright/discussions/11690 Github Discussion} */ - page: async ({ page, failOnConsoleError }, use) => { + page: async ({ page, failOnConsoleError, ignore404s }, use) => { // Capture any console errors during test execution - const messages = []; + let messages = []; page.on('console', (msg) => messages.push(msg)); - + await use(page); + if (ignore404s.length > 0){ + messages = messages.filter(msg => { + let keep = true; + + if (msg.text().match(/404 \(Object Not Found\)/) !== null) { + keep = ignore404s.every(ignoreRule => { + return msg.location().url.match(ignoreRule) === null; + }); + } + + return keep; + }); + } + // Assert against console errors during teardown if (failOnConsoleError) { - messages.forEach((msg) => + messages.forEach(async (msg) => { // eslint-disable-next-line playwright/no-standalone-expect expect .soft(msg.type(), `Console error detected: ${_consoleMessageToString(msg)}`) .not.toEqual('error') - ); + }); } } }); diff --git a/e2e/playwright-ci.config.js b/e2e/playwright-ci.config.js index f4d07ca651..0499304c46 100644 --- a/e2e/playwright-ci.config.js +++ b/e2e/playwright-ci.config.js @@ -25,7 +25,7 @@ const config = { workers: NUM_WORKERS, //Limit to 2 for CircleCI Agent use: { baseURL: 'http://localhost:8080/', - headless: true, + headless: false, ignoreHTTPSErrors: true, screenshot: 'only-on-failure', trace: 'on-first-retry', diff --git a/e2e/tests/functional/search.e2e.spec.js b/e2e/tests/functional/search.e2e.spec.js index f0a7357a13..f3e6702621 100644 --- a/e2e/tests/functional/search.e2e.spec.js +++ b/e2e/tests/functional/search.e2e.spec.js @@ -31,6 +31,8 @@ import { expect, test } from '../../pluginFixtures.js'; test.describe('Grand Search', () => { let grandSearchInput; + test.use({ignore404s: [/_design\/object_names\/_view\/object_names$/]}); + test.beforeEach(async ({ page }) => { grandSearchInput = page .getByLabel('OpenMCT Search') @@ -192,6 +194,8 @@ test.describe('Grand Search', () => { }); test('Search results are debounced @couchdb @network', async ({ page }) => { + //Unfortunately 404s are always logged to the JavaScript console and can't be surpressed + //A 404 is now thrown when we test for the presence of the object names view used by search. test.info().annotations.push({ type: 'issue', description: 'https://github.com/nasa/openmct/issues/6179' @@ -199,6 +203,7 @@ test.describe('Grand Search', () => { await createObjectsForSearch(page); let networkRequests = []; + page.on('request', (request) => { const searchRequest = request.url().endsWith('_find') || request.url().includes('by_keystring');