Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/playwright-core/src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
if (!(e instanceof PlaywrightError))
throw e;
const details = e.details as channels.PageExpectScreenshotErrorDetails;
if (!details.customErrorMessage)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think was regressed fairly recently. Let's find the culprit, and mention in the PR description.

throw e;
return { ...details, errorMessage: details.customErrorMessage };
}
}, { title });
Expand Down
20 changes: 20 additions & 0 deletions tests/playwright-test/to-have-screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,26 @@ test('should support omitBackground option for locator', async ({ runInlineTest
expect.soft(png.data[3], 'image A must be 0').toBe(0);
});

test('should enforce strictness for locator screenshots', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43745' } }, async ({ runInlineTest }) => {
const result = await runInlineTest({
...playwrightConfig({}),
'a.spec.js': `
const { test, expect } = require('@playwright/test');
test('is a test', async ({ page }) => {
await page.setContent('<button>First</button><button>Second</button>');
const buttons = page.getByRole('button');
await expect(buttons).toHaveCount(2);
await expect(buttons.first()).toHaveScreenshot('button.png');
await expect(buttons.screenshot()).rejects.toThrow('strict mode violation');
await expect(expect(buttons).toHaveScreenshot('button.png')).rejects.toThrow('strict mode violation');
});
`
}, { 'update-snapshots': true });
expect(result.exitCode).toBe(0);
const regularResult = await runInlineTest({});
expect(regularResult.exitCode).toBe(0);
});

test('should fail to screenshot an element with infinite animation', async ({ runInlineTest }, testInfo) => {
const infiniteAnimationURL = pathToFileURL(path.join(__dirname, '../assets/rotate-z.html'));
const result = await runInlineTest({
Expand Down
Loading