@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
40 lines • 1.61 kB
JavaScript
import { d, Interaction, PerformActivities } from '@serenity-js/core';
import { significantFieldsOf } from 'tiny-types/lib/objects/significantFields.js';
export class PerformActivitiesAsPlaywrightSteps extends PerformActivities {
test;
constructor(actor, stage, test) {
super(actor, stage);
this.test = test;
}
async perform(activity) {
const testInfo = this.test.info();
// Monkey-patch addStep to allow for passing a pre-computed location
// see https://github.com/microsoft/playwright/issues/30160
const originalAddStep = testInfo._addStep;
testInfo._addStep = (data) => {
data.location = this.locationOf(activity);
data.params = this.parametersOf(activity);
return originalAddStep.call(testInfo, data);
};
await this.test.step(await activity.describedBy(this.actor), () => super.perform(activity));
testInfo._addStep = originalAddStep;
}
parametersOf(activity) {
if (activity instanceof Interaction) {
return significantFieldsOf(activity).reduce((acc, field) => {
acc[field] = d `${activity[field]}`;
return acc;
}, {});
}
return {};
}
locationOf(activity) {
const instantiationLocation = activity.instantiationLocation();
return {
file: instantiationLocation.path.value,
line: instantiationLocation.line,
column: instantiationLocation.column
};
}
}
//# sourceMappingURL=PerformActivitiesAsPlaywrightSteps.js.map