Skip to content

Commit

Permalink
feat: exposing waitForSelectors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfieJones committed May 22, 2024
1 parent e45bc21 commit 0b4d68a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/ninety-games-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pixeleye/playwright": patch
"@pixeleye/puppeteer": patch
"@pixeleye/cypress": patch
---

Exposing waitForSelectors option
6 changes: 6 additions & 0 deletions integrations/cypress/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface Options {
selector?: string;
devices?: DeviceDescriptor[];
maskSelectors?: string[];
waitForSelectors?: string[];
maskColor?: string;
css?: string;
wait?: number;
Expand All @@ -33,6 +34,10 @@ export const pixeleyeSnapshot = (options: Options) => {
? `${configCSS ?? ""}\n${options.css ?? ""}`
: undefined;

for (const waitForSelector of options.waitForSelectors ?? []) {
cy.get(waitForSelector);
}

return cy.document().then(async (doc) => {
const serializedDom = domSnapshot(doc, {
recordCanvas: true,
Expand All @@ -53,6 +58,7 @@ export const pixeleyeSnapshot = (options: Options) => {
serializedDom,
fullPage: options.fullPage,
wait: options.wait,
waitForSelectors: options.waitForSelectors,
};

cy.request({
Expand Down
20 changes: 18 additions & 2 deletions integrations/playwright/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export interface Options {
fullPage?: boolean;
variant?: string;
selector?: string;
/**
* @deprecated use {@link Options.waitForSelectors} instead
*/
waitForSelector?: string;
waitForSelectors?: string[];
devices?: DeviceDescriptor[];
maskSelectors?: string[];
maskColor?: string;
Expand Down Expand Up @@ -62,8 +66,19 @@ export async function pixeleyeSnapshot(page: Page, options: Options) {
path: rrwebScript,
});

if (options.waitForSelector)
await page.waitForSelector(options.waitForSelector);
// TODO remove in next major release
if (options.waitForSelector) {
options.waitForSelectors = [
options.waitForSelector,
...(options.waitForSelectors ?? []),
];
}

if (options.waitForSelectors) {
for (const selector of options.waitForSelectors) {
await page.waitForSelector(selector);
}
}

const domSnapshot = await (page as Page).evaluate(() => {
const r: RRWeb = (window as any).rrwebSnapshot;
Expand All @@ -88,6 +103,7 @@ export async function pixeleyeSnapshot(page: Page, options: Options) {
maskSelectors: options.maskSelectors,
maskColor: options.maskColor,
wait: options.wait,
waitForSelectors: options.waitForSelectors,
css,
};

Expand Down
8 changes: 8 additions & 0 deletions integrations/puppeteer/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface Options {
selector?: string;
devices?: DeviceDescriptor[];
maskSelectors?: string[];
waitForSelectors?: string[];
maskColor?: string;
css?: string;
wait?: number;
Expand Down Expand Up @@ -66,6 +67,12 @@ export async function pixeleyeSnapshot(
path: rrwebScript,
});

if (options.waitForSelectors) {
for (const selector of options.waitForSelectors) {
await page.waitForSelector(selector);
}
}

const domSnapshot = await (page as Page).evaluate(() => {
const r: RRWeb = (window as any).rrwebSnapshot;

Expand All @@ -90,6 +97,7 @@ export async function pixeleyeSnapshot(
maskSelectors: options.maskSelectors,
maskColor: options.maskColor,
wait: options.wait,
waitForSelectors: options.waitForSelectors,
css,
};

Expand Down

0 comments on commit 0b4d68a

Please sign in to comment.