Collecting Playwright Coverage — Accessing the Playwright Page in a Custom StageCrewMember #2839
-
|
Hi everyone, I’m running UI tests with Cucumber-JS + Serenity/JS + Playwright (Chromium) and want to gather JS coverage (LCOV) across my entire suite. I’d like to write a small
The blocker: inside my crew member, how do I actually get hold of the Playwright serenity.config.tsimport { configure, Cast } from '@serenity-js/core';
import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright';
import { PlaywrightAdapter } from '@serenity-js/playwright';
import { ConsoleReporter } from '@serenity-js/console-reporter';
import { ArtifactArchiver } from '@serenity-js/serenity-bdd';
import { chromium } from 'playwright';
BeforeAll(async () => {
const browser = await chromium.launch({ headless: true });
configure({
actors: Cast.where(actor =>
actor.whoCan(BrowseTheWebWithPlaywright.using(browser))
),
crew: [
ConsoleReporter.forDarkTerminals(),
PlaywrightAdapter.forCucumber(),
ArtifactArchiver.storingArtifactsAt('./target/site/serenity'),
CoverageCrew, // ← plug in our custom crew here
],
});
});Pseudocode for
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Hi @Gontrum! Have a look at the The bit you're interested is here: Here, Accessing the
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @jan-molak, and thanks for the great pointers! I’ve implemented my crew member to react to events and added a simple console.log({ event });inside
This makes it hard to start coverage at the very beginning of each scenario, since my crew never sees Do you have any idea, why there are no I’d love to contribute the finished StageCrewMember back to the project once I’ve got everything up and running. |
Beta Was this translation helpful? Give feedback.
Hi @Gontrum!
Have a look at the
Photographerwho does something similar, i.e. it retrieves the browser associated with the actor to take a screenshot.The bit you're interested is here:
serenity-js/packages/web/src/stage/crew/photographer/strategies/PhotoTakingStrategy.ts
Lines 35 to 42 in 6df0ca6
Here,
Stage.theActorInTheSpotlight()returns the most recently used actor.Accessing the
pageThe difference between what you're trying to do and what the
Photographerdoes is t…