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

[Bug]: BrowserType.connect doesn't work with the Pytest plugin #2323

Closed
Unit111 opened this issue Feb 26, 2024 · 1 comment
Closed

[Bug]: BrowserType.connect doesn't work with the Pytest plugin #2323

Unit111 opened this issue Feb 26, 2024 · 1 comment

Comments

@Unit111
Copy link

Unit111 commented Feb 26, 2024

Version

1.41.0

Steps to reproduce

My docker-compose.yml:

version: '3.4'
services:
  ui:
    image: <a Node 16 image>
    volumes:
      - ${UI_PATH}:/ui:delegated
    working_dir: '/ui'
    command: 'bash -c "npm install -g nx@latest && nx serve styleguide --host 0.0.0.0 --disable-host-check"'
    ports:
        - '4200:4200'
  playwright:
    image: mcr.microsoft.com/playwright:v1.41.0-jammy
    command: >
      sh -c '
      cd /home/pwuser && 
      npx -y [email protected] run-server --port 9999'
    ports:
      - '9999:9999'

Expected behavior

I expect that my Pytest tests use the PW server I started.

Actual behavior

The tests are using a local PW instance.

Additional context

I followed the tip from here as created a docker compose setup for my tests.
I have a service called "ui" that builds and serves an Angular app. And another service that uses the official PW Node image to start a server.
I am sure that my setup is working because I also created a script (not a Pytest test) that successfully connects to the server and performs an operation

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect(ws_endpoint="ws://127.0.0.1:9999/")
    page = browser.new_page()
    page.goto("http://ui:4200/#/usage")
    page.screenshot(path="./test.png")
    browser.close()

But when I try to use the PW serves in Pytest

@pytest.fixture(scope="session")
def playwright(playwright: Playwright) -> Playwright:
    playwright.selectors.set_test_id_attribute("ref")
    playwright.chromium.connect(ws_endpoint="ws://127.0.0.1:9999/")
    return playwright

and then start my test as if the configuration in the fixture is ignored and the local PW is used instead.
I am sure that the fixture is picked up because the other change I make there: playwright.selectors.set_test_id_attribute("ref") is working.
I really need to make this work because I want to run visual regression tests in out CI and in order not to have two sets of screenshots I want to use the same system for running PW.

Environment

- Operating System: MacOS
- CPU: Intel
- Browser: All
- Python Version: 3.10
- Other info:
@mxschmitt
Copy link
Member

Using remote browsers is not supported with the Pytest plugin as of today.

Folding into microsoft/playwright-pytest#197.

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

No branches or pull requests

2 participants