@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
42 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlaywrightStepReporter = void 0;
const events_1 = require("@serenity-js/core/lib/events");
const model_1 = require("@serenity-js/core/lib/model");
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 events_1.ActivityRelatedArtifactGenerated && event.artifact instanceof model_1.Photo) {
this.attachPhotoFrom(event);
}
if (event instanceof events_1.SceneTagged && this.shouldAddTag(event.tag)) {
this.addTag(event.tag);
}
}
attachPhotoFrom(event) {
const id = model_1.CorrelationId.create();
this.stage.announce(new events_1.AsyncOperationAttempted(new model_1.Name(this.constructor.name), new model_1.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 events_1.AsyncOperationCompleted(id, this.stage.currentTime()));
});
}
shouldAddTag(tag) {
// don't include platform and browser tags as Playwright already includes them
return !(tag instanceof model_1.PlatformTag || tag instanceof model_1.BrowserTag);
}
addTag(tag) {
this.testInfo.annotations.push({ type: tag.type, description: tag.name });
}
}
exports.PlaywrightStepReporter = PlaywrightStepReporter;
//# sourceMappingURL=PlaywrightStepReporter.js.map