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] Can't run tests with multiple browsers when overriding page fixture #172

Open
Actionb opened this issue Jun 13, 2023 · 1 comment
Open

Comments

@Actionb
Copy link

Actionb commented Jun 13, 2023

Context:

  • Playwright Version: 1.34.0 (pytest-playwright: 0.3.3)
  • Operating System: Linux
  • Python version: 3.11
  • Browser: All

Code Snippet

Just a simple test that overrides the page fixture.

import pytest


@pytest.fixture
def page(page):
    # do something with the page
    yield page


def test(page):
    assert True

Describe the bug

When running the above test file with pytest --browser firefox --browser chromium only one instance of the test is run and the following warning is given out instead:

pytest_playwright/pytest_playwright.py:326: UserWarning: When using unittest.TestCase specifying multiple browsers is not supported

When I include some other playwright fixture in either the page fixture or the test method, the test is run with the specified browsers as expected.

So for example, this works:

def test(page, browser_name):  # another playwright fixture
    assert True

But this does not:

def test(page, monkeypatch):  # a pytest fixture
    assert True
@danshagen
Copy link

I had the same problem and could solve it: When overriding the page fixture instead of requesting the default page fixture, request the BrowserContext directly. Basically just implementing the same code as the original page fixture:

def page(context: BrowserContext) -> Page:

@pytest.fixture
def page(context: BrowserContext) -> Page:
    return context.new_page()

So, for your code example:

import pytest


@pytest.fixture
def page(context):
    # do something with the page
    page = context.new_page()
    yield page


def test(page):
    assert True

This will now run with multiple browsers without warning.

Context

  • Playwright Version: 1.49.1 (pytest-playwright: 0.6.2)
  • Operating System: Linux
  • Python version: 3.11
  • Browser: All

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

3 participants