thenbe / neotest-playwright

A playwright adapter for neotest.
MIT License
43 stars 5 forks source link

[Docs] Running Playwright in Linux #41

Closed sand4rt closed 3 months ago

sand4rt commented 4 months ago

Might be good to add docs on how to use Playwright on Linux distributions as described in?: https://github.com/microsoft/playwright/issues/26482

We have follow these steps:

  1. Run the Docker image (one-time setup): docker run -p 3000:3000 --rm --init -it mcr.microsoft.com/playwright:v1.41.0-jammy /bin/sh -c "cd /home/pwuser && npx -y playwright@1.41.0 run-server --port 3000 --host 0.0.0.0"

  2. Add an environment variable in e.g. in: .zshrc, .zprofile, .bashrc or .bash_profile (one-time setup): export PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:3000/

  3. Run the tests as usual: npx playwright test

If component testing is used, then the ctViteConfig.preview.host has to be set in playwright.config.ts as described in https://github.com/microsoft/playwright/issues/31440#issuecomment-2197538299:

import { defineConfig, devices } from "@playwright/experimental-ct-react";

export default defineConfig({
    testDir: "./",
    snapshotDir: "./__snapshots__",
    timeout: 10 * 1000,
    fullyParallel: true,
    forbidOnly: !!process.env.CI,
    retries: process.env.CI ? 2 : 0,
    workers: process.env.CI ? 1 : undefined,
    reporter: process.env.CI ? "html" : "line",
    use: {
        trace: "on-first-retry",
        ctPort: 3100,
        ctViteConfig: {
            preview: {
                host: "192.168...", // <-- REPLACE WITH YOUR LOCAL IP
            },
        },
    },
    projects: [
        {
            name: "chromium",
            use: { ...devices["Desktop Chrome"] },
        },
    ],
});