Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add debugging instructions in PRs with failing Playwright tests (#1402)

sarayourfriend1b011032c43a
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d79384a4b..c0392a98b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -59,6 +59,28 @@ jobs:
- name: Run unit tests
run: pnpm test:unit
+ clean-playwright-failure-comment:
+ name: Remove previous Playwright test failure comments
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: peter-evans/find-comment@v2
+ id: test-results-comment
+ with:
+ issue-number: ${{ github.event.pull_request.number }}
+ body-includes: Playwright Failure Test Results
+
+ - uses: actions/github-script@v6
+ if: steps.test-results-comment.outputs.comment-id != 0
+ with:
+ script: |
+ await github.rest.issues.deleteComment({
+ repo: context.repo.repo,
+ owner: context.repo.owner,
+ comment_id: ${{ steps.test-results-comment.outputs.comment-id }}
+ })
+ console.log('Deleted comment with ID ${{ steps.test-results-comment.outputs.comment-id }}')
+
nuxt-playwright:
name: Nuxt Playwright tests
runs-on: ubuntu-latest
@@ -72,9 +94,9 @@ jobs:
run: pnpm test:playwright
- uses: actions/upload-artifact@v3
- if: ${{ failure() }}
+ if: failure()
with:
- name: test-results
+ name: nuxt-test-results
path: test-results
storybook-playwright:
@@ -90,11 +112,48 @@ jobs:
run: pnpm test:storybook
- uses: actions/upload-artifact@v3
- if: ${{ failure() }}
+ if: failure()
+ id: test-results
+ with:
+ name: storybook-test-results
+ path: test-results
+
+ playwright-test-failure-comment:
+ name: Share Playwright test debugging instructions
+ runs-on: ubuntu-latest
+ if: ${{ always() }}
+ needs:
+ - nuxt-playwright
+ - storybook-playwright
+
+ steps:
+ - uses: actions/download-artifact@v2
with:
- name: test-results
path: test-results
+ - name: Check if test results exist
+ id: check-results
+ run: |
+ has_results=$(stat test-results/nuxt-test-results || stat test-results/storybook-test-results) || false
+ if [[ $has_results ]]; then
+ echo "::set-output name=has-failure::true"
+ fi
+
+ - uses: peter-evans/create-or-update-comment@v2
+ if: steps.check-results.outputs.has-failure
+ with:
+ issue-number: ${{ github.event.pull_request.number }}
+ body: |
+ **Playwright Failure Test Results**
+
+ It looks like some of the Playwright tests failed. You can download the Playwright trace
+ output for both Storybook and Nuxt Playwright tests that have failed at the bottom of this
+ page, under the "Artifacts" section:
+
+ <https://github.com/WordPress/openverse-frontend/actions/runs/${{ github.run_id }}>
+
+ Read more about how to use this artifact here: <https://github.com/WordPress/openverse-frontend/blob/main/test/playwright/README.md#debugging>
+
storybook:
name: Check Storybook build
runs-on: ubuntu-latest
diff --git a/test/playwright/README.md b/test/playwright/README.md
index a1393b17f..91fd79191 100644
--- a/test/playwright/README.md
+++ b/test/playwright/README.md
@@ -75,6 +75,8 @@ If for some reason you find yourself needing to completely recreate the tapes, y
Additional debugging may be accomplished in two ways. You may inspect the trace output of failed tests by finding the `trace.zip` for the relevant test in the `test-results` folder. Traces are only saved for failed tests. You can use the [Playwright Trace Viewer](https://playwright.dev/docs/trace-viewer) to inspect these (or open the zip yourself and poke around the files on your own).
+For Playwright tests failing in CI, a GitHub comment will appear with a link to download an artifact of the `test-results` folder.
+
Visual regression tests that fail to match the existing snapshots will also have `expected`, `actual` and `diff` files generated that are helpful for understanding why intermittent failures are happening. These are generated automatically by Playwright and will be placed in the `test-results` folder under the fully qualified name of the test that failed (with every parent describe block included).
Additionally, you can run run the tests in debug mode. This will run the tests with a headed browser as opposed to a headless (invisible) one and allow you to watch the test happen in real time. It's not possible for a headed browser to run inside the docker container, however, so be aware that when debugging the environment will be slightly different. For example, if you're on any OS other than Linux, the browser you're running will have small differences in how it renders the page compared to the docker container.