Fixtures
mocker
The default installation provides the mocker fixture via pytest-mock.
browser
The browser extra provides a new browser
fixture:
- class pytest_logikal.browser.Browser
Browser automation.
Has the same attributes and methods as a
selenium.webdriver.Chrome
object.
- class pytest_logikal.browser.BrowserSettings(name: Optional[str] = None, width: int = 1920, height: Optional[int] = None, mobile: bool = False)
Browser settings data.
- Parameters
name – The name to use for screenshots.
width – The width of the browser window.
height – The height of the browser window (use
None
for unlimited).mobile – Whether it is a mobile browser.
You may control browser settings for a specific test with the
set_browser()
decorator:
- @pytest_logikal.browser.set_browser(*args: Dict[str, Any], **kwargs: Any) Callable[[Any], Any]
Control the creation of the
Browser
object in thebrowser
fixture.- Parameters
*args – A list of arguments to forward to the underlying
BrowserSettings
instances.**kwargs – The arguments to forward to the underlying
BrowserSettings
instance.
You can specify browser settings with this decorator as follows:
from pytest_django.live_server_helper import LiveServer from pytest_logikal.browser import Browser, set_browser @set_browser(width=1800, height=900) def test_homepage(browser: Browser, live_server: LiveServer) -> None: browser.get(live_server.url) browser.check()
You can also run your test in multiple browser environments:
from pytest_django.live_server_helper import LiveServer from pytest_logikal.browser import Browser, set_browser @set_browser( dict(name='desktop', width=1800), dict(name='mobile', width=600, mobile=True), ) def test_homepage(browser: Browser, live_server: LiveServer) -> None: browser.get(live_server.url) browser.check()