neotest-playwright icon indicating copy to clipboard operation
neotest-playwright copied to clipboard

[Docs] Running Playwright in Linux

Open sand4rt opened this issue 1 year ago • 0 comments

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 [email protected] 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"] },
		},
	],
});

sand4rt avatar Jul 28 '24 14:07 sand4rt