microsoft/playwright-pytest

base_url fixture is not used by browser_context_args

uglybug opened this issue · 0 comments

At the moment, it is impossible to use the base_url fixture to set the base url at runtime, which is supported by the pytest-base-url plugin, and even alluded to as possible by the pytest-playwright docs (https://playwright.dev/python/docs/test-runners#configure-base-url).

This can be demonstrated as follows:

@pytest.fixture(scope="session")
def base_url():
    return "http://www.google.com"

def test_search(page):
   page.goto("/search?q=microsoft")

The "fix" for this is simple. Change:

def browser_context_args(
    pytestconfig: Any,
    playwright: Playwright,
    device: Optional[str],
) -> Dict:
...
base_url = pytestconfig.getoption("--base-url")

to:

def browser_context_args(
    pytestconfig: Any,
    playwright: Playwright,
    device: Optional[str],
    base_url: str
) -> Dict:
...
base_url = base_url

As pytest-base-url returns pytestconfig.getoption("--base-url") or None by default this would work exactly the same as currently, unless the user chooses to override the base_url fixture with one of their own. So just adds an extra feature which is already documented as supported anyway.