Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update screencatcher in the e2e folder for avoiding errors #14394

Merged
merged 3 commits into from
Aug 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions e2e/utils/ScreenCatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can just add .txt, or, more obvious, .error.log to the screenshotPath, to have file name like the follow:

0010002--(10:04:38.853): Open workspace.png.error.log

errorLogFilePath = errorLogFilePath.replace(executionScreenCastDir, executionScreenCastErrorsDir);
await this.writeErrorLog(errorLogFilePath, err);
}
}

async catchScreen(screenshotPath: string) {
Expand All @@ -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();
}
}

}