Skip to content

Commit

Permalink
Annotate all pages on playwright events (#351)
Browse files Browse the repository at this point in the history
* Annotate all pages on playwright events

* return promises in case we can await them in the future
  • Loading branch information
ryanjduffy authored Apr 8, 2024
1 parent e5af521 commit 66b6724
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/playwright/src/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page, TestInfo, test } from "@playwright/test";
import { Browser, Page, TestInfo, test } from "@playwright/test";
import dbg from "debug";
import {
ClientInstrumentationListener,
Expand Down Expand Up @@ -129,7 +129,7 @@ function maybeMonkeyPatchTestInfo(
}

export async function replayFixture(
{ playwright, page }: { playwright: any; page: Page },
{ playwright, browser }: { playwright: any; browser: Browser },
use: () => Promise<void>,
testInfo: TestInfo
) {
Expand All @@ -156,9 +156,21 @@ export async function replayFixture(

function addAnnotation(event: string, id?: string, data?: Record<string, any>) {
if (id) {
page
.evaluate(ReplayAddAnnotation, [event, id, JSON.stringify({ ...data, test: testIdData })])
.catch(e => warn("Failed to add annotation", e));
return Promise.allSettled(
browser.contexts().flatMap(context => {
return context.pages().flatMap(async page => {
try {
await page.evaluate(ReplayAddAnnotation, [
event,
id,
JSON.stringify({ ...data, test: testIdData }),
]);
} catch (e) {
warn("Failed to add annotation", e);
}
});
})
);
}
}

Expand Down

0 comments on commit 66b6724

Please sign in to comment.