Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(toHaveScreenshot): stylePath as first arg (#29372)

Max Schmitt8c007fd3fc17
diff --git a/packages/playwright/src/matchers/toMatchSnapshot.ts b/packages/playwright/src/matchers/toMatchSnapshot.ts
index f65b324095..0a913b24dd 100644
--- a/packages/playwright/src/matchers/toMatchSnapshot.ts
+++ b/packages/playwright/src/matchers/toMatchSnapshot.ts
@@ -351,7 +351,7 @@ export async function toHaveScreenshot(
expectTypes(pageOrLocator, ['Page', 'Locator'], 'toHaveScreenshot');
return await zones.preserve(async () => {
// Loading from filesystem resets zones.
- const style = await loadScreenshotStyles(optOptions.stylePath || config?.stylePath);
+ const style = await loadScreenshotStyles(helper.allOptions.stylePath || config?.stylePath);
return toHaveScreenshotContinuation.call(this, helper, page, locator, config, style);
});
}
diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.ts
index ef07b58090..95a95e4cb1 100644
--- a/tests/playwright-test/to-have-screenshot.spec.ts
+++ b/tests/playwright-test/to-have-screenshot.spec.ts
@@ -1272,6 +1272,7 @@ test('should support stylePath option', async ({ runInlineTest }) => {
snapshotPathTemplate: '__screenshots__/{testFilePath}/{arg}{ext}',
}),
'__screenshots__/tests/a.spec.js/snapshot.png': createImage(IMG_WIDTH, IMG_HEIGHT, 0, 255, 0),
+ '__screenshots__/tests/a.spec.js/png-1.png': createImage(IMG_WIDTH, IMG_HEIGHT, 0, 255, 0),
'screenshot.css': 'body { background: #00FF00; }',
'tests/a.spec.js': `
const { test, expect } = require('@playwright/test');
@@ -1280,6 +1281,9 @@ test('should support stylePath option', async ({ runInlineTest }) => {
await expect(page).toHaveScreenshot('snapshot.png', {
stylePath: './screenshot.css',
});
+ await expect(page).toHaveScreenshot({
+ stylePath: './screenshot.css',
+ });
});
`,
});