diff --git a/e2e/utils/ScreenCatcher.ts b/e2e/utils/ScreenCatcher.ts index 1b0f0fee918..c26315f2de3 100644 --- a/e2e/utils/ScreenCatcher.ts +++ b/e2e/utils/ScreenCatcher.ts @@ -19,8 +19,9 @@ export class ScreenCatcher { async catchMethodScreen(methodName: string, methodIndex: number, screenshotIndex: number) { const executionScreenCastDir = `${TestConstants.TS_SELENIUM_REPORT_FOLDER}/executionScreencast`; - const formattedMethodIndex: string = new Intl.NumberFormat('en-us', {minimumIntegerDigits: 3}).format(methodIndex); - const formattedScreenshotIndex: string = new Intl.NumberFormat('en-us', {minimumIntegerDigits: 5}).format(screenshotIndex).replace(/,/g, ''); + const executionScreenCastErrorsDir = `${TestConstants.TS_SELENIUM_REPORT_FOLDER}/executionScreencastErrors`; + const formattedMethodIndex: string = new Intl.NumberFormat('en-us', { minimumIntegerDigits: 3 }).format(methodIndex); + const formattedScreenshotIndex: string = new Intl.NumberFormat('en-us', { minimumIntegerDigits: 5 }).format(screenshotIndex).replace(/,/g, ''); if (!fs.existsSync(TestConstants.TS_SELENIUM_REPORT_FOLDER)) { fs.mkdirSync(TestConstants.TS_SELENIUM_REPORT_FOLDER); @@ -31,11 +32,21 @@ export class ScreenCatcher { } const date: Date = new Date(); - const timeStr: string = date.toLocaleTimeString('en-us', {hour12: false}) + '.' + new Intl.NumberFormat('en-us', {minimumIntegerDigits: 3}).format(date.getMilliseconds()); + const timeStr: string = date.toLocaleTimeString('en-us', { hour12: false }) + '.' + new Intl.NumberFormat('en-us', { minimumIntegerDigits: 3 }).format(date.getMilliseconds()); const screenshotPath: string = `${executionScreenCastDir}/${formattedMethodIndex}${formattedScreenshotIndex}--(${timeStr}): ${methodName}.png`; - await this.catchScreen(screenshotPath); + try { + await this.catchScreen(screenshotPath); + } catch (err) { + if (!fs.existsSync(executionScreenCastErrorsDir)) { + fs.mkdirSync(executionScreenCastErrorsDir); + } + + let errorLogFilePath: string = screenshotPath.replace('.png', '.txt'); + errorLogFilePath = errorLogFilePath.replace(executionScreenCastDir, executionScreenCastErrorsDir); + await this.writeErrorLog(errorLogFilePath, err); + } } async catchScreen(screenshotPath: string) { @@ -45,4 +56,14 @@ export class ScreenCatcher { screenshotStream.end(); } + async writeErrorLog(errorLogPath: string, err: Error) { + console.log(`Failed to save screenshot, additional information in the ${errorLogPath}`); + + if (err.stack) { + const screenshotStream = fs.createWriteStream(errorLogPath); + screenshotStream.write(new Buffer(err.stack, 'utf8')); + screenshotStream.end(); + } + } + }