symonk / pytest-playwright-enhanced

:snake: Batteries included playwright for pytest [alpha]
Apache License 2.0
3 stars 0 forks source link

version codecov docs

pytest-playwright-enhanced

[!CAUTION] pytest-playwright-enhanced is in the alpha stage.

pytest-playwright-enhanced is a batteries included pytest plugin for the playwright python bindings that offers extended functionality with a focus on removing boilerplate code for projects that wish to test modern web applications and APIs. pytest-playwright-enhanced plans to offer the following:


Quick Start

Quickly get running by doing the following:


Overriding Browser and Context args

There are two methods for overwriting both browser and context arguments at runtime. These are:

import pytest
import typing

@pytest.mark.browser_kwargs(env={}, timeout=15)
@pytest.mark.context_kwargs()
def test_my_app(pw_page):
    # This page will have a preconfigured browser and context from the 
    # marker arguments.
    ...

def my_function(config: pytest.Config) -> dict[typing.Any, typing.Any]:
    return {
        # custom options.
        # inspect CLI if you need via config.
    }

# if you need to calculate the args at runtime, later use:
@pytest.mark.browser_kwargs(callback=my_function)
@pytest.mark.context_kwargs(callback=my_function)
def test_my_app(pw_page):
    # internal machinery will invoke `my_function_that_returns_kwargs` 
    # later to get overrides.  These are merged sensible with CLI and 
    # other PWE defaults.
    ...

Alternatively, if you need more dynamicism, overwrite the fixture and take full control:

import pytest
import typing

@pytest.fixture(scope="function")
def pw_browser_contexts(config: pytest.Config) -> dict[typing.Any, typing.Any]:
    return {
        # Any overrides here,
        # ...
    }

[!CAUTION] If you chose the fixture route, you are responsible for all details, PWE defaults will not be included. Using the markers, a deferred function can be used to calculate args at runtime!


Fixtures



Hooks

pytest_playwright_acquire_binaries: Hook in and customise binary acquisition at runtime. pytest_playwright_is_debugging: User defined behaviour for detecting if an IDE is debugging. pytest_playwright_browser_env: Control the environment passed on to playwright browser instances. pytest_playwright_configure_proxy: Return a ProxySettings object in your own hooks to control proxy settings.


Markers