Skip to content

Add Playwright Screenshots to Chromatic #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

hassoncs
Copy link
Contributor

@hassoncs hassoncs commented Jul 10, 2025

With this change, now we can capture screenshots in Playwright and upload them to Chromatic, so we can actually have proper snapshot testing for the entire VS Code extension!

image

Copy link

changeset-bot bot commented Jul 10, 2025

⚠️ No Changeset found

Latest commit: e0dd3d7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@hassoncs hassoncs force-pushed the playwright-screenshots branch 7 times, most recently from 9dcfe9c to f5bc394 Compare July 11, 2025 18:24
@hassoncs hassoncs marked this pull request as ready for review July 11, 2025 20:55
@hassoncs hassoncs force-pushed the playwright-screenshots branch 2 times, most recently from 1f69781 to 9a3b2b4 Compare July 11, 2025 21:00
Chris Hasson added 10 commits July 11, 2025 16:23
This commit enhances the Playwright E2E CI workflow by:
- Adding a step to extract all `.png` screenshots from the test results directory into a dedicated `chromatic-screenshots` folder.
- Uploading these extracted screenshots as a GitHub artifact named `playwright-screenshots`.
- Modifying the Dockerfile to use BuildKit cache mounts for faster APT operations and to correctly set execute permissions for the entrypoint script.
- Updating the `run-docker-playwright.js` script to include a `--skip-build` option, allowing users to skip the Docker image build step if the image already exists.
- Introducing a `takeScreenshot` fixture in `playwright-base-test.ts` to easily capture and name screenshots during tests, which are then saved with a `chromatic-` prefix.
- Integrating the `takeScreenshot` fixture into `sanity.test.ts` to capture a screenshot after the extension is verified as loaded.

These changes facilitate better visual regression testing with tools like Chromatic by making Playwright screenshots easily accessible from CI runs.
Remove unnecessary steps for screenshot extraction and Chromatic CLI installation,
as these are handled by the Chromatic action directly or are no longer needed.
This simplifies the CI workflow for Storybook Playwright snapshots.
Refactor Playwright E2E test suite to use `lodash.camelCase` for consistent screenshot naming and improved readability. This change simplifies the logic for generating hierarchical screenshot names in both the Playwright tests and the Storybook screenshot generation script.
Replaced `lodash.camelCase` with `change-case.camelCase` in `playwright-e2e` and `storybook` to reduce bundle size and dependency footprint. This change specifically targets string manipulation utilities.

Also added a `data-testid` to the `SettingsView` component for improved testability.
Enhance the `createTempDir` fixture to generate more descriptive temporary directory names for Playwright e2e tests. The new naming convention includes the test file name and a sanitized version of the test title, making it easier to identify test-specific temporary directories. This also ensures a clean slate for each test by removing and recreating the directory.
- Remove `continue-on-error` from Playwright E2E workflow to ensure failures are caught.
- Update `chat-with-response.test.ts` to wait for specific text instead of generic "Task Completed" for more robust assertion.
- Enhance `playwright-base-test.ts` to safely clean and create temporary directories, preventing issues with existing directories.
- Update Storybook README to reflect current setup and remove outdated Playwright screenshot integration details.
Refactor Playwright e2e test to use a more robust selector (`[role="tablist"]`) for checking settings view visibility, improving test stability. Removed `data-testid` from `SettingsView.tsx` as it's no longer needed for this check.
Refactor the Playwright screenshot story generation script for improved readability, maintainability, and performance.

- **Optimized file operations**: Switched to `Promise.all` for concurrent file reading and copying.
- **Simplified logic**: Streamlined screenshot parsing and story content creation.
- **Improved deduplication**: Enhanced logic for handling duplicate screenshots, prioritizing the latest version.
- **Cleaned up helper functions**: Extracted and refined utility functions for clarity.
- **Removed redundant imports**: Removed `readFile` as it was no longer used.
@hassoncs hassoncs force-pushed the playwright-screenshots branch from 9e8f150 to e0dd3d7 Compare July 11, 2025 23:23
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.

1 participant