Pytest plugin
Installing the pytest extra (pip install "jc-selenium-helper[pytest]")
registers a pytest plugin via the pytest11 entry point, so it is picked up
automatically — no explicit pytest_plugins entry needed. It depends on
pytest-selenium for the underlying
WebDriver management.
Fixtures are namespaced with a jc_ prefix so they don't clash with a
project's own fixtures.
jc_chrome_options
Sensible default headless Chrome options:
--headless=new--disable-gpu--disable-dev-shm-usage
Override it in your project's conftest.py to customize (e.g. add
arguments, run non-headless, etc.):
import pytest
@pytest.fixture
def jc_chrome_options(jc_chrome_options):
jc_chrome_options.add_argument("--window-size=1920,1080")
return jc_chrome_options
Feeding these into pytest-selenium
pytest-selenium builds its Chrome driver from a fixture named chrome_options.
To make it use jc_chrome_options, add a one-line override to your project's
conftest.py:
import pytest
@pytest.fixture
def chrome_options(jc_chrome_options):
return jc_chrome_options
A conftest.py fixture deterministically takes precedence over
pytest-selenium's own chrome_options. (Earlier versions shipped this
override as a plugin fixture, but plugin-vs-plugin fixture precedence is not
guaranteed across environments, so the wiring is now an explicit one-liner.)
Insecure flags are opt-in
--no-sandbox and --ignore-certificate-errors weaken Chrome's security
(they disable the browser sandbox and TLS certificate verification). They are
off by default. Some sandboxed CI containers need them, so you can opt in
two ways — either one enables the flags and emits an
InsecureChromeOptionsWarning:
- Set the
JC_SELENIUM_INSECUREenvironment variable (to1,true,yes, oron) — handy for a single CI run:
bash
JC_SELENIUM_INSECURE=1 pytest
- Or override the
jc_insecure_chromefixture in yourconftest.py:
```python import pytest
@pytest.fixture def jc_insecure_chrome(): return True ```
jc_insecure_chrome
Boolean fixture, default False. Return True (or set JC_SELENIUM_INSECURE)
to add the insecure Chrome flags to jc_chrome_options. Opting in triggers an
InsecureChromeOptionsWarning.
jc_browser
Wraps the selenium fixture (provided by pytest-selenium) in a
jc_selenium_helper.Browser:
def jc_browser(selenium) -> Browser:
return Browser(selenium)
Use it directly in tests:
def test_homepage(jc_browser):
jc_browser.open("https://example.com")
jc_browser.assert_present("//h1")