Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2390

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T04:58:07+00:00 2024-11-26T04:58:07+00:00

Fast and reliable end-to-end tests with Playwright on GitHub Actions

  • 61k

Playwright is a powerful web testing tool supporting Chromium, Firefox and WebKit engines. The project has excellent documentation and many examples.

I use Playwright for E2E tests on the DEV environment. Today I'm going to show how you can integrate Playwright on GitHub Actions more efficiently.

Playwright by Microsoft

The documentation suggests using the following snippet to run Playwright inside GitHub Actions:

steps:   - uses: actions/checkout@v3   - uses: actions/setup-node@v3     with:       node-version: '18'   - name: Install dependencies     run: npm ci   - name: Install Playwright     run: npx playwright install --with-deps   - name: Run your tests     run: npx playwright test   - name: Upload test results     if: always()     uses: actions/upload-artifact@v3     with:       name: playwright-report       path: playwright-report 
Enter fullscreen mode Exit fullscreen mode

What is notable here?

  • It's supposed to run all tests on the same type of GitHub Runner. ubuntu-latest by default.
  • All supported browser engines (chromium, firefox, WebKit) will be installed on the Linux runner.
  • Playwright will execute tests for all browser engines from the same runner.
  • The last step will prepare an archive with an HTML report.

After several months of experiments I come up with the following configuration:

# ...  jobs:   test:     name: 🧪 ${{ matrix.project }} E2E Tests     runs-on: ${{ matrix.os }}     timeout-minutes: 20     strategy:       fail-fast: false       matrix:         include:           - project: chromium             os: ubuntu-latest             cache_dir: ~/.cache/ms-playwright           - project: firefox             os: ubuntu-latest             cache_dir: ~/.cache/ms-playwright           - project: webkit             os: macos-12             cache_dir: ~/Library/Caches/ms-playwright     steps:      - uses: actions/checkout@v3      - uses: actions/setup-node@v3       with:         node-version-file: '.nvmrc'         cache: 'npm'      - name: ⚡️ Cache NPM dependencies       uses: actions/cache@v3       id: cache-primes       with:         path: node_modules         key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}      - name: ⚡️ Cache playwright binaries       uses: actions/cache@v3       id: playwright-cache       with:         path: ${{ matrix.cache_dir }}         key: ${{ runner.os }}-${{ matrix.project }}-pw-${{ hashFiles('**/.playwright-version') }}      - name: 📥 Install deps       if: steps.cache-primes.outputs.cache-hit != 'true'       run: make install      - name: 📥 Install ${{ matrix.project }} with Playwright       if: steps.playwright-cache.outputs.cache-hit != 'true'       run: npx playwright install --with-deps ${{ matrix.project }}      - name: 🎭 Playwright tests       run: npx playwright test --project=${{ matrix.project }}       env:         DEBUG: pw:api,pw:browser*      - name: 📊 Upload test results       if: failure()       uses: actions/upload-artifact@v3       with:         name: playwright-report-${{ matrix.project }}         path: playwright-report 
Enter fullscreen mode Exit fullscreen mode

What I've changed in GitHub Workflow for Playwright tests?

  • I use a matrix with three browser engines to run the jobs simultaneously. Instead of ubuntu-latest, I run WebKit tests on macos-12 runner. I had to make the change to avoid fragile tests. I noticed that the page.goto() API works differently on Linux and macOS for the WebKit engine. WebKit didn't wait for load event, which causes failures from time to time. At the same time, I've never caught such a problem locally on my MacBook. If you're interested, the ticket is still open in the Playwright bug tracker.
  • The fail-fast parameter is set to false to wait for all testing jobs to complete, even if one of them fails for some reason.
  • I believe it is essential to specify timeout-minutes for E2E tests so that the tests will crash if the infrastructure hangs or behaves incorrectly.
  • I use the .nvmrc file inside the repository to specify the NodeJS version. DRY all over the place!
  • Configured aggressive cache for npm dependencies and binary files with browsers. I added a special target to Makefile to calculate the Playwright browsers hash:
bump-playwright:   npm install --save-dev @playwright/test   npx playwright --version > .github/.playwright-version 
Enter fullscreen mode Exit fullscreen mode

After executing make bump-playwright command, the latest PW version will be installed and the value of the installed release will be written to the .github/.playwright-version file. GitHub Actions calculate the hash for the cache from the file content. Example file:

$ cat .github/.playwright-version Version 1.29.2 
Enter fullscreen mode Exit fullscreen mode

  • Each runner installs only one browser and it's pretty handy cause the HTML report will have the results for that browser — easy to navigate and spot the issues. This distinction also allows you to have an idea of the test execution speed in each browser and to notice flickering tests specific to a particular engine.
  • Playwright tests run with enabled DEBUG, so that in case of a crash, you can quickly get additional information for diagnostics.
  • In contrast to the recommended configuration from the documentation, I prefer to upload artifacts with the report only in case of test failures. I don't see the point in storing those artifacts on the cloud, given how often the tests are run.

I shared my findings for configuring E2E playwright tests in GitHub Actions. Feel free to ask questions about the example GitHub workflow.

What Playwright tricks do you use in your daily work? Would love to hear about your hidden gems 💎.

Cover photo by Denny Müller.

devopsgithubtestingwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.