Skip to content

Added playwright for visual regression test #39

Added playwright for visual regression test

Added playwright for visual regression test #39

Workflow file for this run

name: Testing for visual regression on old theme
# Run the workflow when code is pushed or when a pull request is created
on:
push:
branches:
- '**'
pull_request:
branches:
- main
jobs:
playwright:
name: Run Playwright
runs-on: ubuntu-latest
steps:
# Checkout the repository so the workflow has access to the code
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: cd tests && npm ci
- name: Setup Hugo
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3.0.0
with:
hugo-version: "0.134.2"
extended: true
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
id: test-visual
run: |
make tests | tee output.log
if grep -q -e "Error: A snapshot doesn't exist at" -e "Screenshot comparison failed" output.log; then
echo "Playwright tests failed due to a snapshot issue."
echo "SNAPSHOT_DIFFERENCES=true" >> $GITHUB_ENV
exit 1
elif grep -q "failed" output.log; then
echo "Playwright tests failed due to a non-snapshot issue."
exit 1
fi
- uses: actions/upload-artifact@v4
id: artifact-upload
if: ${{ !cancelled() && failure() && steps.test-visual.conclusion == 'failure' }}
with:
name: playwright-report
path: tests/playwright-report/
retention-days: 3
- name: Comment on PR with Playwright report
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ failure() && env.SNAPSHOT_DIFFERENCES == 'true' }}
with:
script: |
const body = `### <span aria-hidden="true">❌</span> Playwright visual snapshot differences were detected.
View the [Playwright report](${{ steps.artifact-upload.outputs.artifact-url }})
**To approve the snapshot changes and update the snapshots, please comment:** /approve-snapshots`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
});
# - name: Update the screenshots based on Ubuntu env on GH
# id: test-visual-update
# if: ${{ failure() && steps.test-visual.conclusion == 'failure' }}
# run: make tests-update-screenshots
# - name: Upload updated Playwright screenshots
# uses: actions/upload-artifact@v4
# if: ${{ failure() && steps.test-visual-update.conclusion == 'success' }}
# with:
# name: playwright-screenshots-updated
# path: tests/src/__screenshots__/**/*.png
# retention-days: 3