Skip to content

feat: Add assert_screenshot/3 for visual regression testing#181

Merged
ftes merged 13 commits into
ftes:mainfrom
Wigny:add-assert-screenshot
Jun 18, 2026
Merged

feat: Add assert_screenshot/3 for visual regression testing#181
ftes merged 13 commits into
ftes:mainfrom
Wigny:add-assert-screenshot

Conversation

@Wigny

@Wigny Wigny commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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.

Comment thread mix.exs Outdated

@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.

Thank you so much for this Wígny!
An excellent addition to phoenix_test_playwright, and two well crafted PRs.

Some small comments.

Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright/config.ex
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread test/phoenix_test/playwright_test.exs Outdated
Comment thread test/phoenix_test/playwright_test.exs Outdated
Comment thread test/phoenix_test/playwright_test.exs Outdated
Comment thread lib/phoenix_test/playwright.ex
@Wigny Wigny requested a review from ftes June 16, 2026 13:57
@Wigny Wigny force-pushed the add-assert-screenshot branch from 15d517d to c9921c3 Compare June 16, 2026 14:24
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread test/snapshots/__diff__/baseline.png Outdated

@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.

Looking good, nearly there.

@Wigny Wigny requested a review from ftes June 16, 2026 19:29
@Wigny Wigny force-pushed the add-assert-screenshot branch from 7e1bb96 to 8775220 Compare June 16, 2026 19:53

@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.

Thanks for the changes.
Especially the improvements to documentation is appreciated.

That made me think we should be more consistent regarding defaults:
Either duplicate all, or remove all defaults (and rely on playwright defaults).

Also, if you don't mind: Copy option doc text from playwright docs?
Happy to merge as is though.

Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright.ex Outdated
Comment thread lib/phoenix_test/playwright.ex
Comment thread lib/phoenix_test/playwright.ex
Comment thread test/phoenix_test/playwright_test.exs Outdated
@ftes

ftes commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Beautiful. Let's get this baby shipped.

auto-merge was automatically disabled June 17, 2026 13:40

Head branch was pushed to by a user without write access

@Wigny Wigny requested a review from ftes June 17, 2026 13:49
@ftes ftes merged commit 18353cc into ftes:main Jun 18, 2026
3 checks passed
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