From 3adee8cecceb77ee8b7373f0f10465c7f70ebaa4 Mon Sep 17 00:00:00 2001 From: Angelo Loria <24941027+angelo-loria@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:50:40 -0500 Subject: [PATCH] Feat/ops_playwright-container (#24) * pw 1.43.0 update * use pw container * update README --- .github/workflows/playwright-shard.yml | 52 ++++---------------------- README.md | 4 +- package.json | 2 +- yarn.lock | 28 +++++++------- 4 files changed, 26 insertions(+), 60 deletions(-) diff --git a/.github/workflows/playwright-shard.yml b/.github/workflows/playwright-shard.yml index 6fcfe0b..a7445ad 100644 --- a/.github/workflows/playwright-shard.yml +++ b/.github/workflows/playwright-shard.yml @@ -60,6 +60,8 @@ jobs: matrix: shard: [1/4, 2/4, 3/4, 4/4] runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/playwright:v1.43.0-jammy steps: - uses: actions/checkout@v3 @@ -72,28 +74,6 @@ jobs: - name: Yarn Install run: yarn install - - # caching playwright browsers, see https://github.com/microsoft/playwright/issues/7249 - - name: Store Playwright Version - run: | - PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//') - echo "Playwright Version: $PLAYWRIGHT_VERSION" - echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV - - - name: Cache Browsers for Playwright Version - id: cache-playwright-browsers - uses: actions/cache@v3 - with: - path: ~/.cache/ms-playwright - key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} - - - name: Install Playwright Browsers - if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' - run: yarn playwright install --with-deps - - - name: Install Playwright Dependencies - if: steps.cache-playwright-browsers.outputs.cache-hit == 'true' - run: yarn playwright install-deps - name: Download Tesults Token Artifact uses: actions/download-artifact@v3 @@ -106,6 +86,8 @@ jobs: - name: Run Tests run: yarn test:ci --shard ${{ matrix.shard }} + env: + HOME: /root # required for playwright to run in container - name: Upload blob report to GitHub Actions Artifacts if: always() @@ -209,6 +191,8 @@ jobs: if: ${{ always() }} name: Lighthouse runs-on: ubuntu-latest + container: + image: mcr.microsoft.com/playwright:v1.43.0-jammy steps: - uses: actions/checkout@v3 @@ -221,31 +205,11 @@ jobs: - name: Yarn Install run: yarn install - - # caching playwright browsers, see https://github.com/microsoft/playwright/issues/7249 - - name: Store Playwright Version - run: | - PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//') - echo "Playwright Version: $PLAYWRIGHT_VERSION" - echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV - - - name: Cache Browsers for Playwright Version - id: cache-playwright-browsers - uses: actions/cache@v3 - with: - path: ~/.cache/ms-playwright - key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} - - - name: Install Playwright Browsers - if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' - run: yarn playwright install --with-deps chromium - - - name: Install Playwright Dependencies - if: steps.cache-playwright-browsers.outputs.cache-hit == 'true' - run: yarn playwright install-deps - name: Run Lighthouse run: yarn test:lighthouse + env: + HOME: /root # required for playwright to run in container - name: Upload Lighthouse Report uses: actions/upload-artifact@v3 diff --git a/README.md b/README.md index 7ce2b74..a873b34 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,9 @@ I've made some changes to the default Github Actions workflow that Playwright ge ### Test Execution Test execution takes place in a job called [playwright_test](https://github.com/angelo-loria/playwright-boilerplate/blob/main/.github/workflows/playwright-shard.yml#L21). -* I've added caching for the browser binaries. This will speed up the workflow by not having to download the browser binaries every time the workflow runs. [See line 41 of the Actions workflow for the first of the steps involved in caching the binaries.](https://github.com/angelo-loria/playwright-boilerplate/blob/main/.github/workflows/playwright-shard.yml#L41) + +* I'm using [Playwright's Docker container](https://playwright.dev/docs/ci-intro#via-containers) in Actions to avoid having to install browsers and system dependencies on each Actions run. You do have to watch that the container version matches the version of Playwright that you're on when using the container, though. + * I'm using Playwright's [sharding feature](https://playwright.dev/docs/test-shardinghttps://playwright.dev/docs/test-sharding) to run the tests in parallel. [See line 25 of the Actions workflow for the matrix configuration](https://github.com/angelo-loria/playwright-boilerplate/blob/main/.github/workflows/playwright-shard.yml#L25) and [line 64 for the step that runs the tests in parallel](https://github.com/angelo-loria/playwright-boilerplate/blob/main/.github/workflows/playwright-shard.yml#L64). Output from sharded tests is uploaded for use in the reporting job. ### Reporting diff --git a/package.json b/package.json index 5dc06f7..ddf1927 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "homepage": "https://github.com/angelo-loria/playwright-boilerplate#readme", "devDependencies": { "@axe-core/playwright": "^4.8.1", - "@playwright/test": "^1.41.2", + "@playwright/test": "^1.43.0", "@types/node": "^20.8.7", "prettier": "^2.8.8", "node-fetch": "2", diff --git a/yarn.lock b/yarn.lock index f8e5109..218fa1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -53,12 +53,12 @@ resolved "https://registry.yarnpkg.com/@paulirish/trace_engine/-/trace_engine-0.0.12.tgz#6172c84f19d1e4254450d1927b1bb3eea5b5ba04" integrity sha512-PglukOOYGvjqgMVKNSa3a4grWrWzL97L47bgDCzqAnDSTJ+vDOKxMPXR3rsnLECoZzpbb9LCzS3CEg/NwwhRHQ== -"@playwright/test@^1.41.2": - version "1.41.2" - resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.41.2.tgz#bd9db40177f8fd442e16e14e0389d23751cdfc54" - integrity sha512-qQB9h7KbibJzrDpkXkYvsmiDJK14FULCCZgEcoe2AvFAS64oCirWTwzTlAYEbKaRxWs5TFesE1Na6izMv3HfGg== +"@playwright/test@^1.43.0": + version "1.43.0" + resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.43.0.tgz#5d90f247b26d404dd5d81c60f9c7c5e5159eb664" + integrity sha512-Ebw0+MCqoYflop7wVKj711ccbNlrwTBCtjY5rlbiY9kHL2bCYxq+qltK6uPsVBGGAOb033H2VO0YobcQVxoW7Q== dependencies: - playwright "1.41.2" + playwright "1.43.0" "@puppeteer/browsers@2.1.0": version "2.1.0" @@ -952,10 +952,10 @@ pend@~1.2.0: resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" integrity sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg== -playwright-core@1.41.2: - version "1.41.2" - resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.41.2.tgz#db22372c708926c697acc261f0ef8406606802d9" - integrity sha512-VaTvwCA4Y8kxEe+kfm2+uUUw5Lubf38RxF7FpBxLPmGe5sdNkSg5e3ChEigaGrX7qdqT3pt2m/98LiyvU2x6CA== +playwright-core@1.43.0: + version "1.43.0" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.43.0.tgz#d8079acb653abebb0b63062e432479647a4e1271" + integrity sha512-iWFjyBUH97+pUFiyTqSLd8cDMMOS0r2ZYz2qEsPjH8/bX++sbIJT35MSwKnp1r/OQBAqC5XO99xFbJ9XClhf4w== playwright-tesults-reporter@^1.0.1: version "1.1.0" @@ -964,12 +964,12 @@ playwright-tesults-reporter@^1.0.1: dependencies: tesults "^1.1.3" -playwright@1.41.2: - version "1.41.2" - resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.41.2.tgz#4e760b1c79f33d9129a8c65cc27953be6dd35042" - integrity sha512-v0bOa6H2GJChDL8pAeLa/LZC4feoAMbSQm1/jF/ySsWWoaNItvrMP7GEkvEEFyCTUYKMxjQKaTSg5up7nR6/8A== +playwright@1.43.0: + version "1.43.0" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.43.0.tgz#2c2efd4ee2a25defd8c24c98ccb342bdd9d435f5" + integrity sha512-SiOKHbVjTSf6wHuGCbqrEyzlm6qvXcv7mENP+OZon1I07brfZLGdfWV0l/efAzVx7TF3Z45ov1gPEkku9q25YQ== dependencies: - playwright-core "1.41.2" + playwright-core "1.43.0" optionalDependencies: fsevents "2.3.2"