Refactor baseline generation to use Playwright's toHaveScreenshot#20
Merged
Refactor baseline generation to use Playwright's toHaveScreenshot#20
Conversation
…ization Replace raw page.screenshot() in ScreenshotGenerator with Playwright's toHaveScreenshot via --update-snapshots. Both generation and testing now use the same toHaveScreenshot mechanism which provides built-in visual stabilization (takes multiple screenshots until page is stable before saving/comparing). Flow: crawl pages → write manifest → run regression.spec.ts with --update-snapshots → scan outputs → update manifest with results. https://claude.ai/code/session_01GXJX7QG5iNpVhQr9XgZuZo
Adds page.waitForTimeout(2000) after networkidle and before toHaveScreenshot. Gives external content (YouTube/Vimeo embeds, lazy-loaded images) time to render before visual stabilization starts — reduces flaky diffs from partially loaded embeds. https://claude.ai/code/session_01GXJX7QG5iNpVhQr9XgZuZo
Create generation.spec.ts — dedicated spec for baseline generation with a 2s waitForTimeout after networkidle so external embeds (YouTube, Vimeo) fully render before toHaveScreenshot captures the baseline. regression.spec.ts stays fast without the delay — testing compares against whatever was captured during generation. - generate-visual-baseline.ts now runs generation.spec.ts - playwright.config.ts ignores generation.spec.ts in normal test runs https://claude.ai/code/session_01GXJX7QG5iNpVhQr9XgZuZo
testIgnore in playwright.config.ts was blocking generation.spec.ts even when specified explicitly on CLI — causing 0 tests to run and 0 screenshots generated. Create playwright.generation.config.ts that extends base config but overrides testMatch to generation.spec.ts and clears testIgnore. https://claude.ai/code/session_01GXJX7QG5iNpVhQr9XgZuZo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the visual baseline generation system to leverage Playwright's built-in
toHaveScreenshotAPI instead of manually managing browser instances and screenshots. This approach provides better visual stabilization, automatic retry logic, and integrates with Playwright's snapshot testing infrastructure.Key Changes
ScreenshotGeneratorclass that manually controlled browser contexts, page loading, and screenshot captureLoadStrategyandStrategyConfigtypes along with thetryPageLoadmethod that implemented custom retry logicrunPlaywrightGeneration()function that spawnsplaywright testwith--update-snapshotsflag to generate baselines viatoHaveScreenshotScreenshotResultobjectswriteProgress()andScreenshotResultinterface as they're no longer neededImplementation Details
regression.spec.tswhich uses Playwright'stoHaveScreenshotfor visual comparisonregression.spec.tscan load viewport and path configurationBrowsertype import from Playwrighthttps://claude.ai/code/session_01GXJX7QG5iNpVhQr9XgZuZo