microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.41k stars 3.63k forks source link

[Bug]: GH-Actions: Firefox installed but test run shows executable doesn't exist #29960

Closed kiranparajuli589 closed 7 months ago

kiranparajuli589 commented 7 months ago

Version

1.42.0

Steps to reproduce

GitHub Actions like:

jobs:
  tests:
    name: Playwright Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        # chromium, chrome, chrome-beta, msedge, msedge-beta, msedge-dev, firefox, firefox-asan, webkit
        browser:
          - project: Chromium
            package: chromium
    steps:
      - uses: actions/checkout@v4
      - name: Setup NodeJS with Yarn
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'yarn'
      - name: Install Dependencies
        run: yarn install --frozen-lockfile
      - name: Start Web App
        run: |
          cp .env.ci .env
          cat .env
          yarn dev &
          sleep 10
      - name: Install Browsers
        run: |
          sudo apt-get update
          sudo apt-get install -y wait-for-it
          npx playwright install --with-deps ${{ matrix.browser.package }}
      - name: Run Tests
        run: yarn test --project ${{ matrix.browser.project }}

Expected behavior

Test should be running using the firefox browser.

Actual behavior

Logs from npx playwright install --with-deps firefox

Downloading Firefox 123.0 (playwright build v1440) from https://playwright.azureedge.net/builds/firefox/1440/firefox-ubuntu-22.04.zip
|                                                                                |   0% of 84.7 MiB
|■■■■■■■■                                                                        |  10% of 84.7 MiB
|■■■■■■■■■■■■■■■■                                                                |  20% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■                                                        |  30% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                                                |  40% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                                        |  50% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                                |  60% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                        |  70% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■                |  80% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■        |  90% of 84.7 MiB
|■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■| 100% of 84.7 MiB
Firefox [1](https://github.com/Softverse-Technology/ourbuddy-front-users/actions/runs/8299408174/job/22715026638#step:7:1)23.0 (playwright build v1[4](https://github.com/Softverse-Technology/ourbuddy-front-users/actions/runs/8299408174/job/22715026638#step:7:5)40) downloaded to /home/runner/.cache/ms-playwright/firefox-[14](https://github.com/Softverse-Technology/ourbuddy-front-users/actions/runs/8299408174/job/22715026638#step:7:15)[40](https://github.com/Softverse-Technology/ourbuddy-front-users/actions/runs/8299408174/job/22715026638#step:7:41)

Logs from test run command:

yarn test --project Firefox

Error: browserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium-1105/chrome-linux/chrome
    ╔═════════════════════════════════════════════════════════════════════════╗
    ║ Looks like Playwright Test or Playwright was just installed or updated. ║
    ║ Please run the following command to download new browsers:              ║
    ║                                                                         ║
    ║     yarn playwright install                                             ║
    ║                                                                         ║
    ║ <3 Playwright Team                                                      ║
    ╚═════════════════════════════════════════════════════════════════════════╝

Additional context

Playwright config:

import {defineConfig, devices} from '@playwright/test';
import {Environment} from './environment';

/**
 * @see https://playwright.dev/docs/test-configuration
 */
module.exports = defineConfig({
    testDir: './tests',
    /* Fail the build on CI if you accidentally left test.only in the source code. */
    forbidOnly: !!Environment.CI,
    /* Retry on CI only */
    retries: Environment.CI ? 1 : 0,
    /* Reporter to use. See https://playwright.dev/docs/test-reporters */
    reporter: [
        ["list", {printSteps: true}],
        ["html", {outputFolder: 'playwright-report', open: 'never'}],
    ],
    /* Timeouts. See https://playwright.dev/docs/test-timeouts */
    timeout: Environment.PlaywrightTimeout,
    expect: {
        timeout: Environment.PlaywrightExpectTimeout,
        toHaveScreenshot: {
            maxDiffPixels: 100,
        }
    },
    /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
    use: {
        ignoreHTTPSErrors: true,
        /* Base URL to use in actions like `await page.goto('/')`. */
        baseURL: Environment.BaseUrl,
        locale: "en-US",
        permissions: ["camera", "microphone", "geolocation"],
        // Capture screenshot after each test failure.
        screenshot: 'only-on-failure',
        // Record trace only when retrying a test for the first time.
        trace: 'on-first-retry',
        // Record video only when retrying a test for the first time.
        video: 'on-first-retry',
        headless: Environment.PlaywrightHeadless,
        browserName: 'chromium',
        launchOptions: {
            // Slow down Playwright operations by the specified amount of milliseconds.
            slowMo: Environment.PlaywrightSlowMo,
        },
    },

    /* Configure projects for major browsers */
    projects: [
        { name: 'Chromium', use: {...devices['Desktop Chrome']}},
        { name: 'Firefox', use: {...devices['Desktop Firefox']}},
        { name: 'Webkit', use: {...devices['Desktop Safari']}},
        /* Test against mobile viewports. */
        { name: 'MobileChrome', use: {...devices['Pixel 5']}},
        { name: 'MobileSafari', use: {...devices['iPhone 12']}},
        /* Test against branded browsers. */
        { name: 'MicrosoftEdge', use: {...devices['Desktop Edge'], channel: 'msedge'}},
        { name: 'GoogleChrome', use: {...devices['Desktop Chrome'], channel: 'chrome'}},
    ],
});

Environment

System: Github Action
OS: ubuntu-latest
mxschmitt commented 7 months ago

Looks like you are downloading firefox but the tests want the Chromium browser. Do you maybe launch the browser yourself somewhere hard-coded? Make sure to rely on the browserType fixture, or even better re-use our browser fixture and never launch it manually.

kiranparajuli589 commented 7 months ago

@mxschmitt thx for the response.

I've no any code to launch the browser inside my test base.

The browser is opened by the page.goto() command, and just the URL to navigate to is provided.

It seems like playwright uses chromium by default.

If I use the project config like:

{name: 'Firefox', use: {...devices['Desktop Firefox'], browserName: 'firefox'}},

And try to run the tests using:

 yarn test tests/auth/login.spec.js:19 --project Firefox 

Then I get error:

    Error: browser.newContext: Unknown permission: camera

Can you help?

mxschmitt commented 7 months ago

Are you able to share a reproduction with us which we can run locally? That might be the best option in order to find out whats happening.

kiranparajuli589 commented 7 months ago

This is pretty much it. I've shared playwright config, GH actions yml.

But, sure I can try setting up a dedicated repo to reproduce this.

mxschmitt commented 7 months ago

Tests would be the interesting counterpart.

Looks also like that you have: browserName: chromium in your global use in your playwright.config. I recommend removing this.

kiranparajuli589 commented 7 months ago

That was the case, thank you @mxschmitt