smoke - also screenshot on failure

This commit is contained in:
Benjamin Pasero 2022-04-09 13:55:56 +02:00
parent d9db5d10ec
commit e358a02a35
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65

View file

@ -14,6 +14,7 @@ import { teardown } from './playwrightBrowser';
export class PlaywrightDriver implements IDriver {
private static traceCounter = 1;
private static screenShotCounter = 1;
private static readonly vscodeToPlaywrightKey: { [key: string]: string } = {
cmd: 'Meta',
@ -68,6 +69,24 @@ export class PlaywrightDriver implements IDriver {
}
await measureAndLog(this.context.tracing.stopChunk({ path: persistPath }), `stopTracing for ${name}`, this.options.logger);
// To ensure we have a screenshot at the end where
// it failed, also trigger one explicitly. Tracing
// does not guarantee to give us a screenshot unless
// some driver action ran before.
if (persist) {
await this.takeScreenshot(name);
}
} catch (error) {
// Ignore
}
}
private async takeScreenshot(name: string): Promise<void> {
try {
const persistPath = join(this.options.logsPath, `playwright-screenshot-${PlaywrightDriver.screenShotCounter++}-${name.replace(/\s+/g, '-')}.png`);
await measureAndLog(this.page.screenshot({ path: persistPath, type: 'png' }), 'takeScreenshot', this.options.logger);
} catch (error) {
// Ignore
}