Skip to content

[573] add automated snapshot testing with Playwright and PR comment reporting#93

Closed
IhorMasechko wants to merge 4 commits intomainfrom
573-playwright-screenshots-in-pr-comments
Closed

[573] add automated snapshot testing with Playwright and PR comment reporting#93
IhorMasechko wants to merge 4 commits intomainfrom
573-playwright-screenshots-in-pr-comments

Conversation

@IhorMasechko
Copy link
Contributor

@IhorMasechko IhorMasechko commented May 16, 2025

Summary

This PR introduces automated E2E screenshot (snapshot) testing using Playwright. Snapshots are taken on key pages and compared against baseline images.

Key Features

  • ✅ Full-page snapshots for Home, Cases, and About Us pages
  • ✅ Snapshot update workflow via Dockerized Playwright runner
  • ✅ GitHub Actions integration for PR-triggered tests
  • ✅ Auto-generated comment with link to snapshot artifacts on each commit

How It Works

  • On each PR commit:
    • Playwright runs in Docker
    • Snapshots are taken and uploaded as artifacts
    • A bot comment is posted (or updated) in the PR with a link to the results

Notes

  • Snapshots are stored under e2e/tests/screenshot-test.spec.js-snapshots
  • Comment updates are handled using the GitHub CLI (gh)
  • Permissions for container writes are set via chown to UID 1000

Next Steps / Future Enhancements

  • 📷 Inline visual diffs or hosted report UI
  • 🧪 Add more routes/components for visual coverage
  • ☁️ Optional GitHub Pages integration for static reports

@IhorMasechko IhorMasechko self-assigned this May 16, 2025
@IhorMasechko IhorMasechko requested a review from killev as a code owner May 16, 2025 10:19
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 16, 2025

📝 Walkthrough

Walkthrough

A new GitHub Actions workflow is introduced to automate Playwright snapshot testing on pull requests. The Playwright screenshot test suite is refactored to run parameterized snapshot tests across multiple routes, with each route generating its own test and snapshot artifact, improving test coverage and artifact reporting.

Changes

File(s) Change Summary
.github/workflows/playwright-reports.yml Added a new GitHub Actions workflow for Playwright snapshot testing, artifact upload, and automated PR commenting.
website/e2e/tests/screenshot-test.spec.js Refactored to parameterize snapshot tests for multiple routes, generating individual tests and snapshot files per route.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub
    participant GitHub Actions Runner
    participant Docker/Playwright
    participant PR

    Developer->>GitHub: Opens/updates PR
    GitHub->>GitHub Actions Runner: Triggers workflow
    GitHub Actions Runner->>GitHub: Checks out code
    GitHub Actions Runner->>Docker/Playwright: Runs snapshot tests (multiple routes)
    Docker/Playwright->>GitHub Actions Runner: Generates snapshots
    GitHub Actions Runner->>GitHub: Uploads snapshot artifacts
    GitHub Actions Runner->>PR: Posts/updates comment with snapshot report and artifact link
    GitHub Actions Runner->>Docker/Playwright: Cleans up Docker resources
Loading

Possibly related PRs

  • speedandfunction/website#12: Extends the initial Playwright e2e snapshot tests by parameterizing multiple route snapshot tests and adds a workflow for automated reporting, directly building on the same test infrastructure.
  • speedandfunction/website#52: Introduces Docker-based infrastructure for running Playwright e2e tests, which is leveraged by the new workflow for snapshot testing and reporting.

Suggested reviewers

  • yuramax
  • Anton-88
  • VitalyyP
  • killev

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 09f24ab and 63df231.

📒 Files selected for processing (1)
  • .github/workflows/playwright-reports.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/playwright-reports.yml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: snapshot-report

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented May 16, 2025

🔍 Vulnerabilities of apostrophe-cms:test

📦 Image Reference apostrophe-cms:test
digestsha256:a64e62f69ce07eebeeed929bbd364e50927ec02d14a92ded0dd5aedd0beb2342
vulnerabilitiescritical: 0 high: 2 medium: 0 low: 0
platformlinux/amd64
size283 MB
packages934
📦 Base Image node:23-alpine
also known as
  • 23-alpine3.21
  • 23.11-alpine
  • 23.11-alpine3.21
  • 23.11.1-alpine
  • 23.11.1-alpine3.21
digestsha256:169ee1b69bd3f5c7c8508a9919e8b367bba9dc7fa9a03097ec9f85d2e8179631
vulnerabilitiescritical: 0 high: 0 medium: 0 low: 0
critical: 0 high: 1 medium: 0 low: 0 async 0.9.2 (npm)

pkg:npm/async@0.9.2

high 7.8: CVE--2021--43138 OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities

Affected range<2.6.4
Fixed version2.6.4, 3.2.2
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score1.061%
EPSS Percentile76th percentile
Description

A vulnerability exists in Async through 3.2.1 (fixed in 3.2.2), which could let a malicious user obtain privileges via the mapValues() method.

critical: 0 high: 1 medium: 0 low: 0 async 1.5.2 (npm)

pkg:npm/async@1.5.2

high 7.8: CVE--2021--43138 OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities

Affected range<2.6.4
Fixed version2.6.4, 3.2.2
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score1.061%
EPSS Percentile76th percentile
Description

A vulnerability exists in Async through 3.2.1 (fixed in 3.2.2), which could let a malicious user obtain privileges via the mapValues() method.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
website/e2e/tests/screenshot-test.spec.js (2)

9-37: Good test implementation with a few enhancement opportunities.

The test implementation properly handles waiting for page load events and font rendering before taking snapshots. The parameterized approach efficiently creates tests for each route.

Consider these enhancements:

  1. Add responsive testing with multiple viewport sizes:
- await page.setViewportSize({ width: 1280, height: 720 });
+ // Test multiple viewport sizes for responsive design
+ const viewports = [
+   { width: 1280, height: 720 }, // Desktop
+   { width: 768, height: 1024 }, // Tablet
+   { width: 375, height: 812 }   // Mobile
+ ];
+ for (const viewport of viewports) {
+   await page.setViewportSize(viewport);
+   // Take and verify snapshot for each viewport size
+   const snapshot = await page.screenshot({
+     fullPage: true,
+     timeout: 30000,
+   });
+   expect(snapshot).toMatchSnapshot(`${viewport.width}x${viewport.height}-${name}`, {
+     maxDiffPixels: 300,
+     threshold: 0.5,
+   });
+ }
  1. Document why the specific tolerance values were chosen:
  expect(snapshot).toMatchSnapshot(name, {
    maxDiffPixels: 300,  // Allow for minor differences that don't affect functionality
    threshold: 0.5,      // 0.5 tolerance level for color differences
  });

32-34: Consider adding documentation for snapshot comparison tolerances.

The maxDiffPixels and threshold values control how strict the snapshot comparison is. It would be valuable to document why these specific values were chosen to help future maintainers understand the rationale.

expect(snapshot).toMatchSnapshot(name, {
-  maxDiffPixels: 300,
-  threshold: 0.5,
+  maxDiffPixels: 300, // Allows for small differences in rendering across environments
+  threshold: 0.5,     // Tolerance for pixel color intensity differences (0-1 scale)
});
.github/workflows/playwright-reports.yml (1)

39-42: Ensure directory paths are consistent.

There's an inconsistency between the paths used in the "Ensure snapshot dirs are writable" step and this step, which could lead to confusion.

- mkdir -p website/e2e/pr-snapshots/screenshot-test.spec.js-snapshots
+ # Create consistent directory path - align with earlier step or document why they differ
+ mkdir -p website/e2e/pr-snapshots/screenshot-test.spec.js-snapshots
+ echo "Note: Snapshot directory paths differ between steps because we're copying from container path to a PR-specific local path"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5264b0 and 09f24ab.

📒 Files selected for processing (2)
  • .github/workflows/playwright-reports.yml (1 hunks)
  • website/e2e/tests/screenshot-test.spec.js (1 hunks)
🔇 Additional comments (5)
website/e2e/tests/screenshot-test.spec.js (1)

3-7: Well-structured route parameterization.

The array of route objects is a clean way to define test paths and corresponding snapshot names. This approach makes it easy to add more routes in the future.

.github/workflows/playwright-reports.yml (4)

3-16: Well-configured workflow triggers and permissions.

The workflow is correctly set up to run on appropriate PR events with proper permissions. Good job excluding dependabot runs to avoid unnecessary test executions.


52-66: Good PR comment formatting and artifact linking.

The comment structure with emojis and markdown formatting is very readable and provides clear access to artifacts.


68-84: Robust PR comment update mechanism.

The approach for finding and updating an existing comment is well-implemented. It effectively prevents duplicate comments on the PR while keeping information current.


86-89: Thorough Docker cleanup.

The cleanup step properly removes Docker resources, which is important for maintaining a clean CI environment and preventing resource leaks.

@sonarqubecloud
Copy link

@yuramax yuramax marked this pull request as draft May 20, 2025 08:26
@IhorMasechko
Copy link
Contributor Author

Closing this PR for now — I’ll come back to it and continue the work at a later time.

@IhorMasechko IhorMasechko deleted the 573-playwright-screenshots-in-pr-comments branch December 26, 2025 17:02
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