diff --git a/autotests/tests/main/exists.ts b/autotests/tests/main/exists.ts index 5ed18782..d92a9840 100644 --- a/autotests/tests/main/exists.ts +++ b/autotests/tests/main/exists.ts @@ -89,6 +89,7 @@ test('exists', {meta: {testId: '1'}, testIdleTimeout: 12_000, testTimeout: 20_00 const successfulResponsePromise = waitForResponse( ({statusCode}) => statusCode === OK_STATUS_CODE, + {includeNavigationRequest: true}, ); await pressKey('Enter'); diff --git a/src/utils/report/client/chooseTestRun.tsx b/src/utils/report/client/chooseTestRun.tsx index e62b0b4b..2ee84276 100644 --- a/src/utils/report/client/chooseTestRun.tsx +++ b/src/utils/report/client/chooseTestRun.tsx @@ -1,15 +1,15 @@ -/* eslint-disable no-console */ - import {assertValueIsDefined as clientAssertValueIsDefined} from './assertValueIsDefined'; import { MaybeApiStatistics as clientMaybeApiStatistics, TestRunDetails as clientTestRunDetails, } from './render'; +import {setDomElementsToClientState as clientSetDomElementsToClientState} from './setDomElementsToClientState'; import type {ReportClientState, RunHash} from '../../../types/internal'; const assertValueIsDefined: typeof clientAssertValueIsDefined = clientAssertValueIsDefined; const MaybeApiStatistics = clientMaybeApiStatistics; +const setDomElementsToClientState = clientSetDomElementsToClientState; const TestRunDetails = clientTestRunDetails; declare const jsx: JSX.Runtime; @@ -20,15 +20,13 @@ declare const reportClientState: ReportClientState; * This base client function should not use scope variables (except other base functions). * @internal */ -// eslint-disable-next-line max-statements +// eslint-disable-next-line complexity, max-statements export const chooseTestRun = (runHash: RunHash): void => { + setDomElementsToClientState(); + const {e2edRightColumnContainer} = reportClientState; if (!e2edRightColumnContainer) { - console.error( - 'Cannot find right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later', - ); - return; } @@ -46,6 +44,7 @@ export const chooseTestRun = (runHash: RunHash): void => { e2edRightColumnContainer.firstElementChild as HTMLElement | null; if (!previousTestRunDetailsElement) { + // eslint-disable-next-line no-console console.error( 'Cannot find first child element in right column container (id="e2edRightColumnContainer"). Probably page not yet completely loaded. Please try click again later', ); @@ -77,6 +76,7 @@ export const chooseTestRun = (runHash: RunHash): void => { const fullTestRun = fullTestRuns.find((testRun) => testRun.runHash === runHash); if (fullTestRun === undefined) { + // eslint-disable-next-line no-console console.error( `Cannot find test run with hash ${runHash} in JSON report data. Probably JSON report data for this test run not yet loaded. Please try click again later`, ); diff --git a/src/utils/report/client/index.ts b/src/utils/report/client/index.ts index cd1a4bb6..7b88fc1b 100644 --- a/src/utils/report/client/index.ts +++ b/src/utils/report/client/index.ts @@ -56,4 +56,6 @@ export { sanitizeValue, } from './sanitizeHtml'; /** @internal */ +export {setDomElementsToClientState} from './setDomElementsToClientState'; +/** @internal */ export {setReadJsonReportDataObservers} from './setReadJsonReportDataObservers'; diff --git a/src/utils/report/client/onDomContentLoad.ts b/src/utils/report/client/onDomContentLoad.ts index 04790b9d..1b7d3071 100644 --- a/src/utils/report/client/onDomContentLoad.ts +++ b/src/utils/report/client/onDomContentLoad.ts @@ -1,10 +1,12 @@ import {readJsonReportData as clientReadJsonReportData} from './readJsonReportData'; +import {setDomElementsToClientState as clientSetDomElementsToClientState} from './setDomElementsToClientState'; import type {ReportClientState} from '../../../types/internal'; declare const reportClientState: ReportClientState; const readJsonReportData = clientReadJsonReportData; +const setDomElementsToClientState = clientSetDomElementsToClientState; /** * `DOMContentLoaded` handler for report page. @@ -12,18 +14,7 @@ const readJsonReportData = clientReadJsonReportData; * @internal */ export const onDomContentLoad = (): void => { - const e2edRightColumnContainer = document.getElementById('e2edRightColumnContainer') ?? undefined; - - if (!e2edRightColumnContainer) { - // eslint-disable-next-line no-console - console.error( - 'Cannot find right column container (id="e2edRightColumnContainer") after DOMContentLoaded.', - ); - } else { - Object.assign>(reportClientState, { - e2edRightColumnContainer, - }); - } + setDomElementsToClientState({afterDomContentLoad: true}); readJsonReportData(true); diff --git a/src/utils/report/client/setDomElementsToClientState.ts b/src/utils/report/client/setDomElementsToClientState.ts new file mode 100644 index 00000000..c0a0ff26 --- /dev/null +++ b/src/utils/report/client/setDomElementsToClientState.ts @@ -0,0 +1,35 @@ +import type {ReportClientState} from '../../../types/internal'; + +declare const reportClientState: ReportClientState; + +type Options = Readonly<{afterDomContentLoad?: boolean}> | undefined; + +/** + * Set dynamic DOM elements to `reportClientState`. + * This client function should not use scope variables (except global functions). + * @internal + */ +export const setDomElementsToClientState = ({afterDomContentLoad = false}: Options = {}): void => { + let {e2edRightColumnContainer} = reportClientState; + + if (e2edRightColumnContainer) { + return; + } + + e2edRightColumnContainer = document.getElementById('e2edRightColumnContainer') ?? undefined; + + if (e2edRightColumnContainer) { + Object.assign>(reportClientState, { + e2edRightColumnContainer, + }); + + return; + } + + const messageTail = afterDomContentLoad + ? ' after DOMContentLoaded' + : '. Probably page not yet completely loaded. Please try click again later'; + + // eslint-disable-next-line no-console + console.error(`Cannot find right column container (id="e2edRightColumnContainer")${messageTail}`); +};