Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Run Playwright Codegen on remote browser instance #34034

Open
rorymichele opened this issue Dec 16, 2024 · 0 comments
Open

[Feature]: Run Playwright Codegen on remote browser instance #34034

rorymichele opened this issue Dec 16, 2024 · 0 comments

Comments

@rorymichele
Copy link

🚀 Feature Request

Thanks to the PW_TEST_CONNECT_WS_ENDPOINT environment variable it is possible to run tests in remote browser in docker container (as documented here: #26482 ).

It would be great to have the same option for npx playwright codegen . Is this technically possible?

Example

Have a docker container forwarding port 3000 and wayland display with npx playwright run-server --port 3000 --host 0.0.0.0 running. Below is an example compose.yaml, where playwright.Dockerfile basically is a [email protected] docker image with custom ca certificates:

playwright:
    image: playwright
    build:
      context: .
      dockerfile: playwright.Dockerfile
    working_dir: /app
    command: npx playwright run-server --port 3000 --host 0.0.0.0
    ports:
      - 3000:3000
    networks:
      test-network:
    volumes:
      - ../../:/app:ro
      - ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:/${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:ro
    environment:
      - XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}
      - WAYLAND_DISPLAY=${WAYLAND_DISPLAY}
    stdin_open: true
    tty: true

For headed mode to work we need to modify the chromium entry in projects array in playwright.config.ts to

{
      name: 'chromium',
      use: { 
        ...devices['Desktop Chrome'],
        launchOptions: {
          args: [
            "--ozone-platform=wayland"
          ],
        },
      },
    },

The tests can then be run from the host machine by

PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:3000/ npx playwright test --headed

The requested feature would allow to call

PW_TEST_CONNECT_WS_ENDPOINT=ws://127.0.0.1:3000/ npx playwright codegen

from the host machine to record new tests. Ideally, the Playwright VSCode Extension would allow to set such an endpoint as well to allow using this feature directly from there.

Motivation

We are creating a PWA with heavy cross-site communication and are therefore very restrictive on allowed origins and the like. On some sites (cloud storage) changes need to be persisted for the duration of the test but need to be reset before the next run. To achieve this while staying as close as possible to production without messing with /etc/hosts and the likes our easiest approach was to emulate the setup in docker containers.

We have this setup up and running and can start writing tests now but obviously using playwrights build-in codegen would be super comfortable!
Thanks for considering!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants