pytest-selenium: pytest_selenium_capture_debug hook is not fired on test failure

Viewed 79

I make e2e tests for an web app by using pytest and selenium. Everything is fine, but one thing I can't figure out though spent day searching the web.

I can't make pytest_selenium_capture_debug work. I put it in conftest.py in the root of the test sources. Tests are run inside docker container. Firefox runs with xvfb-run. I record screen video and want copy it to the host if test fails.

I use python 3.6.11 and these library versions are

pytest==6.2.4
pytest-base-url==1.4.2
pytest-helpers-namespace==2021.4.29
pytest-html==3.1.1
pytest-lazy-fixture==0.6.3
pytest-metadata==1.11.0
pytest-repeat==0.9.1
pytest-selenium==2.0.1
pytest-variables==1.9.0
selenium==3.141.0
1 Answers

The issue caused by using custom_selenium fixture. To make all the pytest-selenium hooks work properly it's necessary to use selenium fixture defined by pytest-selenium as is follows.

@pytest.fixture
def logged_in_selenium(selenium):
    ...
Related