Skip to content

feat: Add Page.expect_screenshot/2#56

Merged
ftes merged 3 commits into
ftes:mainfrom
Wigny:add-expect-screenshot
Jun 16, 2026
Merged

feat: Add Page.expect_screenshot/2#56
ftes merged 3 commits into
ftes:mainfrom
Wigny:add-expect-screenshot

Conversation

@Wigny

@Wigny Wigny commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@playwright/test ships toHaveScreenshot for visual regression testing, but the underlying expectScreenshot protocol command was not exposed in this library. This PR adds Page.expect_screenshot/2, including a locator opt to scope the screenshot to a specific element, to support building a toHaveScreenshot-equivalent helper in Elixir.

@ftes ftes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Beautiful. Some tiny suggestions and one question.

Comment thread lib/playwright_ex/channels/page.ex Outdated
Comment thread lib/playwright_ex/channels/page.ex Outdated
Comment thread test/playwright_ex/page_test.exs Outdated
@Wigny Wigny force-pushed the add-expect-screenshot branch from 98f8ecc to 76d0343 Compare June 16, 2026 14:25

@ftes ftes left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Excellent. Thanks!

@ftes ftes merged commit 929b90e into ftes:main Jun 16, 2026
ftes added a commit to ftes/phoenix_test_playwright that referenced this pull request Jun 18, 2026
When writing browser tests, we sometimes need to assert visual changes
in elements — layout shifts, style regressions, rendering differences.
`@playwright/test` ships `toHaveScreenshot` for exactly this, but it's
not accessible from Elixir.

This PR introduces `assert_screenshot/3`, a helper built on the same
underlying Playwright `expectScreenshot` protocol command that powers
`toHaveScreenshot`.

On the first run, it captures a screenshot and saves it as the baseline.
On subsequent runs, it compares the live page against that baseline
server-side, passing silently on match, failing with a diff image on
mismatch.

Note: depends on ftes/playwright_ex#56. The
`mix.exs` points at that branch and will need updating once it merges.

---------

Co-authored-by: Fredrik Teschke <f@ftes.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants