Fixtures
mocker
The default installation provides the mocker fixture via pytest-mock.
browser
The browser extra provides a new
browser()
fixture:
- pytest_logikal.browser.plugin.browser() Browser
Yield a scenario-specific
Browser
sub-class instance.
- class pytest_logikal.browser.Browser
-
Base class for browser-specific web drivers.
- check(name: str | None = None, wait_milliseconds: int | None = 100) None
Create a screenshot and check it against an expected version.
- Parameters:
name – The name of the expected screenshot.
wait_milliseconds – The milliseconds to wait before calculating the screenshot height for unlimited height checks.
Browser settings must be specified via the set_browser()
decorator:
- @pytest_logikal.browser.set_browser(scenarios: Scenario | list[pytest_logikal.browser.scenarios.Scenario]) Callable[[Any], Any]
Apply the given scenarios to the
browser()
fixture.- Parameters:
scenarios – The scenarios to use.
You can specify browser scenarios with this decorator as follows:
from pytest_django.live_server_helper import LiveServer
from pytest_logikal.browser import Browser, scenarios, set_browser
@set_browser(scenarios.desktop)
def test_homepage(browser: Browser, live_server: LiveServer) -> None:
browser.get(live_server.url)
browser.check()
You can also run your test in multiple scenarios:
from pytest_django.live_server_helper import LiveServer
from pytest_logikal.browser import Browser, scenarios, set_browser
@set_browser([
scenarios.desktop,
scenarios.mobile_l,
])
def test_homepage(browser: Browser, live_server: LiveServer) -> None:
browser.get(live_server.url)
browser.check()
Custom scenarios can be specified via the Scenario
class:
- class pytest_logikal.browser.Scenario(settings: Settings | Iterable[Settings], browsers: Iterable[str] | None = None)
Browser scenario specification.
- Parameters:
settings – Settings to use.
browsers – Browsers to use. Defaults to using all registered browser versions.
- class pytest_logikal.browser.Settings(name: str, width: int, height: int, full_page_height: bool = True, mobile: bool = False)
Browser settings specification.
- Parameters:
name – Name of the settings.
width – Browser window width.
height – Browser window height.
full_page_height – Whether to use the full page height for screenshots.
mobile – Whether it is a mobile browser.
Built-in Scenarios
Currently the following built-in scenarios are available:
- pytest_logikal.browser.scenarios.desktop_4k = Scenario(settings=Settings(name='desktop_4k', width=2560, height=1440, full_page_height=True, mobile=False), browsers=None)
- pytest_logikal.browser.scenarios.desktop = Scenario(settings=Settings(name='desktop', width=1800, height=900, full_page_height=True, mobile=False), browsers=None)
- pytest_logikal.browser.scenarios.laptop_l = Scenario(settings=Settings(name='laptop_l', width=1440, height=900, full_page_height=True, mobile=False), browsers=None)
- pytest_logikal.browser.scenarios.laptop = Scenario(settings=Settings(name='laptop', width=1024, height=768, full_page_height=True, mobile=False), browsers=None)
- pytest_logikal.browser.scenarios.tablet = Scenario(settings=Settings(name='tablet', width=768, height=1024, full_page_height=True, mobile=True), browsers=None)
- pytest_logikal.browser.scenarios.mobile_l = Scenario(settings=Settings(name='mobile_l', width=425, height=680, full_page_height=True, mobile=True), browsers=None)
- pytest_logikal.browser.scenarios.mobile_m = Scenario(settings=Settings(name='mobile_m', width=375, height=600, full_page_height=True, mobile=True), browsers=None)
- pytest_logikal.browser.scenarios.mobile_s = Scenario(settings=Settings(name='mobile_s', width=320, height=512, full_page_height=True, mobile=True), browsers=None)
live_url
The django extra provides a new live_url
fixture:
language
The django extra also provides the language
fixture:
- pytest_logikal.django.language(request: Any) Iterable[str]
Return the currently activated language.
You may control the language for a specific test with the set_language
or all_languages
decorators:
timezone
The django extra also provides the timezone
fixture:
You may control the time zone for a specific test with the set_timezone
decorator: