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
instance.
- class pytest_logikal.browser.BrowserSettings(setting: Optional[str] = 'desktop', name: Optional[str] = None, width: Optional[int] = None, height: Optional[Union[int, str]] = None, frame_height: Optional[int] = None, mobile: Optional[bool] = None)
Browser settings data.
- Parameters
setting – The named setting to use.
name – The name to use for screenshots. Defaults to the setting name.
width – The width of the browser window.
height – The height of the browser window (use ‘unlimited’ for unlimited and ‘frame’ to use the frame height). Defaults to ‘unlimited’.
frame_height – The browser window frame height to use when taking ‘unlimited’ screenshots.
mobile – Whether it is a mobile browser. Defaults to
False
.
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(setting='tablet') def test_homepage(browser: Browser, live_server: LiveServer) -> None: browser.get(live_server.url) browser.check()
The currently available settings are the following:
Setting
Width
Height
Frame
Mobile
desktop
1800
unlimited
900
False
laptop-l
1440
unlimited
900
False
laptop
1024
unlimited
768
False
tablet
768
unlimited
1024
True
mobile-l
425
unlimited
680
True
mobile-m
375
unlimited
600
True
mobile-s
320
unlimited
512
True
You can also run your test in multiple browser environments:
@set_browser( dict(setting='desktop'), dict(setting='mobile'), ) def test_homepage(browser: Browser, live_server: LiveServer) -> None: browser.get(live_server.url) browser.check()
The named settings can be overridden or extended via the
tool.browser.settings
table inpyproject.toml
:[tool.browser.settings] desktop = {width = 1024, height = 768} mobile-xl = {width = 480, frame_height = 768, mobile = true}
You can then use your custom named setting as follows:
@set_browser(setting='mobile-xl') def test_homepage(browser: Browser, live_server: LiveServer) -> None: browser.get(live_server.url) browser.check()
While we recommend using named settings, you can also use completely arbitrary settings for a test as follows:
@set_browser(name='laptop-xl', width=1920, height=1080) def test_homepage(browser: Browser, live_server: LiveServer) -> None: browser.get(live_server.url) browser.check()
live_url
The django extra provides a new live_url
fixture: