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

[FEATURE] Config file support

Open kumaraditya303 opened this issue 4 years ago • 3 comments

Same thing as in js/ts world playwright.config.ts equivalent for python playwright.conf.py which would automatically parameterize all the tests.

Includes https://github.com/microsoft/playwright-pytest/issues/67

kumaraditya303 avatar Jul 24 '21 14:07 kumaraditya303

@mxschmitt

How about using the pyproject.toml file for configuration.

[tool.playwright]
headed = true
@pytest.fixture(scope="session")
def playwright_config(request: pytest.FixtureRequest) -> Dict:
    rootpath = request.config.rootpath
    config_file_path = rootpath / "pyproject.toml"

    if not config_file_path.exists():
        return {}

    with config_file_path.open(mode="rb") as f:
        config = tomli.load(f)
        return config.get("tool", {}).get("playwright", {})

@pytest.fixture(scope="session")
def browser_type_launch_args(pytestconfig: Any, playwright_config: Dict) -> Dict:
    launch_options = {}
    headed_option = pytestconfig.getoption("--headed") or playwright_config.get("headed")

I am not a seasoned python developer. If this is an acceptable approach, I can open up a PR.

michaelsatish avatar Jun 24 '22 21:06 michaelsatish

Pytest provides a way to add ini options to the config and read them:

  • https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.Parser.addini
  • https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.Config.getini

mxschmitt avatar Sep 27 '22 20:09 mxschmitt