-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FI-1011 fix: error with
stabilizationInterval
argument
fix: by default open failed test in HTML report (if any) fix: add timeout option to `takeScreenshot` action
- Loading branch information
Showing
11 changed files
with
136 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
import {LogEventType} from '../constants/internal'; | ||
import {testController} from '../testController'; | ||
import {E2edError} from '../utils/error'; | ||
import {getDurationWithUnits} from '../utils/getDurationWithUnits'; | ||
import {log} from '../utils/log'; | ||
import {getPromiseWithResolveAndReject} from '../utils/promise'; | ||
|
||
import type {Inner} from 'testcafe-without-typecheck'; | ||
|
||
type TakeScreenshot = ((path?: string) => Promise<void>) & | ||
((options: Inner.TakeScreenshotOptions) => Promise<void>); | ||
((options: Inner.TakeScreenshotOptions & Readonly<{timeout?: number}>) => Promise<void>); | ||
|
||
/** | ||
* Takes a screenshot of the tested page. | ||
*/ | ||
export const takeScreenshot: TakeScreenshot = (pathOrOptions) => { | ||
const options: Inner.TakeScreenshotOptions | undefined = | ||
typeof pathOrOptions === 'string' ? {path: pathOrOptions} : pathOrOptions; | ||
const {fullPage, path: pathToScreenshot} = options ?? {}; | ||
const options = typeof pathOrOptions === 'string' ? {path: pathOrOptions} : pathOrOptions; | ||
const {fullPage, path: pathToScreenshot, timeout = 10_0000} = options ?? {}; | ||
|
||
log('Take a screenshot of the page', {fullPage, pathToScreenshot}, LogEventType.InternalAction); | ||
const timeoutWithUnits = getDurationWithUnits(timeout); | ||
|
||
return testController.takeScreenshot(pathOrOptions as never); | ||
log( | ||
'Take a screenshot of the page', | ||
{fullPage, pathToScreenshot, timeoutWithUnits}, | ||
LogEventType.InternalAction, | ||
); | ||
|
||
const {promise, reject, setRejectTimeoutFunction} = getPromiseWithResolveAndReject(timeout); | ||
|
||
setRejectTimeoutFunction(() => { | ||
const error = new E2edError( | ||
`takeScreenshot promise rejected after ${timeoutWithUnits} timeout`, | ||
{fullPage, pathToScreenshot}, | ||
); | ||
|
||
reject(error); | ||
}); | ||
|
||
return Promise.race([ | ||
promise, | ||
testController.takeScreenshot({ | ||
fullPage, | ||
path: pathToScreenshot, | ||
} as Inner.TakeScreenshotOptions), | ||
]) as Promise<void>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {clickOnTestRun as clientClickOnTestRun} from './clickOnTestRun'; | ||
|
||
const clickOnTestRun = clientClickOnTestRun; | ||
|
||
declare const e2edTestRunDetailsContainer: HTMLElement; | ||
|
||
/** | ||
* Handler of loading first part of JSON report data for report page. | ||
* This client function should not use scope variables (except global functions). | ||
* @internal | ||
*/ | ||
export function onFirstJsonReportDataLoad(): void { | ||
if (window.location.hash !== '') { | ||
return; | ||
} | ||
|
||
const buttonForFailedTestRun = document.querySelector( | ||
'.retry:not([hidden]) .test-button_status_failed', | ||
); | ||
|
||
if (!buttonForFailedTestRun) { | ||
return; | ||
} | ||
|
||
clickOnTestRun(buttonForFailedTestRun as HTMLElement); | ||
|
||
const buttonOfOpenStep = document.querySelector('.step-expanded[aria-expanded="true"]'); | ||
|
||
if (buttonOfOpenStep) { | ||
const {top} = buttonOfOpenStep.getBoundingClientRect(); | ||
|
||
setTimeout(() => { | ||
e2edTestRunDetailsContainer.scrollTop = top; | ||
}, 8); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type {FullTestRun, ReportClientState} from '../../../types/internal'; | ||
|
||
declare const reportClientState: ReportClientState; | ||
|
||
type Options = Readonly<{ | ||
scriptToRead: Element | undefined; | ||
shouldLogError: boolean; | ||
}>; | ||
|
||
/** | ||
* Reads part of JSON report data from script tag. | ||
* Returns `true` if read successfully, and `false` if it has parse errors. | ||
* This client function should not use scope variables (except global functions). | ||
* @internal | ||
*/ | ||
export function readPartOfJsonReportData({scriptToRead, shouldLogError}: Options): boolean { | ||
try { | ||
const fullTestRuns = JSON.parse(scriptToRead?.textContent ?? '') as readonly FullTestRun[]; | ||
|
||
(reportClientState.fullTestRuns as FullTestRun[]).push(...fullTestRuns); | ||
} catch (error) { | ||
if (shouldLogError) { | ||
// eslint-disable-next-line no-console | ||
console.error('Cannot parse JSON report data from script', error); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters