spaceagetv / electron-playwright-example

Example of multi-window Playwright testing with Electron
MIT License
82 stars 9 forks source link

[question] any idea on how to test these in github actions? #18

Open FranciscoKloganB opened 1 year ago

FranciscoKloganB commented 1 year ago

[edit]: I managed to make it work; See reploy to original post.

Locally, on multiple computers of mine (different OS) everything works fine. However, when I run this on CI/CD via github actions, I get this pesky error which I was also getting when I was executing the against a regular chromium app (non-production build).

Getting a little desperate here. The build is available as expected on the out dir, just like locally.

    Error: electron.launch: Process failed to launch!

      21 |   process.env.CI = 'e2e'
      22 |
    > 23 |   electronApp = await electron.launch({
         |                 ^
      24 |     args: [appInfo.main],
      25 |     executablePath: appInfo.executable,
      26 |   })

Hope you have some pointers for me! :robot:

For curiosity, here's a minimum version of my checks-slow.yml (which contains the e2e tests)

name: Callable - Slow Checks

on:
  workflow_call:

jobs:
  e2e-test:
    timeout-minutes: 20
    name: 🐌 Slow checks
    runs-on: ubuntu-latest

    steps:
      - name: 🦖 Cancel Previous Runs
        uses: styfle/cancel-workflow-action@0.11.0

      - name: 🔻 Checkout repo
        uses: actions/checkout@v3

      # Basically runs `npm run ci`
      - name: 🏃 Run Node and NPM setup
        uses: ./.github/actions/setup-project

      - name: 🌏 Install playwright chromium browser
        run: npx playwright install --with-deps

      # Createsa build for the currently running OS (linux ubuntu in this case)
      - name: 🏗️ Build test project
        run: npm run build

      # Basically `npx playwright test`
      - name: 🎭 Run Playwright tests
        run: npm run playwright:ci

      - name: 📄 Upload test results
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30
FranciscoKloganB commented 1 year ago
      # Add this because I got it to work on multiple OS runners :)
      - name: 🏗️ Build test project 
        run: |
          if [ "$RUNNER_OS" == "Linux" ]; then
            npm run build:linux
          elif [ "$RUNNER_OS" == "macOS" ]; then
            npm run build:mac
          elif [ "$RUNNER_OS" == "Windows" ]; then
            npm run build:win
          else
            echo "Operating system $RUNNER_OS is not supported"
            exit 1
          fi
        shell: bash

      # This action was the important part, it sets up and cleans up XVFB when running on Linux)
      - name: 🎭 Run Playwright tests (using XVFB*)
        uses: coactions/setup-xvfb@v1.0.1
        with:
          # Moved the test command here
          run: npm run playwright:ci 
jjeff commented 1 year ago

A lot of the work on this repository has moved over to the electron-playwright-helpers repository. There's a GitHub workflow over there which shows how to configure a Playwright e2e test.

Sounds like you've got things working. But maybe this is helpful too.