UNPKG

@serenity-js/playwright-test

Version:

Serenity/JS test runner adapter for Playwright Test, combining Playwright's developer experience with the advanced reporting and automation capabilities of Serenity/JS

38 lines 1.69 kB
import { ActivityRelatedArtifactGenerated, AsyncOperationAttempted, AsyncOperationCompleted, SceneTagged, } from '@serenity-js/core/events'; import { BrowserTag, CorrelationId, Description, Name, Photo, PlatformTag } from '@serenity-js/core/model'; export class PlaywrightStepReporter { testInfo; stage; constructor(testInfo, stage) { this.testInfo = testInfo; this.stage = stage; } assignedTo(stage) { this.stage = stage; return this; } notifyOf(event) { if (event instanceof ActivityRelatedArtifactGenerated && event.artifact instanceof Photo) { this.attachPhotoFrom(event); } if (event instanceof SceneTagged && this.shouldAddTag(event.tag)) { this.addTag(event.tag); } } attachPhotoFrom(event) { const id = CorrelationId.create(); this.stage.announce(new AsyncOperationAttempted(new Name(this.constructor.name), new Description(`Attaching screenshot of '${event.name.value}'...`), id, this.stage.currentTime())); this.testInfo.attach(event.name.value, { body: Buffer.from(event.artifact.base64EncodedValue, 'base64'), contentType: 'image/png' }) .then(() => { this.stage.announce(new AsyncOperationCompleted(id, this.stage.currentTime())); }); } shouldAddTag(tag) { // don't include platform and browser tags as Playwright already includes them return !(tag instanceof PlatformTag || tag instanceof BrowserTag); } addTag(tag) { this.testInfo.annotations.push({ type: tag.type, description: tag.name }); } } //# sourceMappingURL=PlaywrightStepReporter.js.map