0

I've installed pytest-selenium, but I cannot use it with pytest.

  def test_sanity(selenium):
E       fixture 'selenium' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, check, cov, dash_br, dash_duo, dash_process_server, dash_thread_server, dashr, dashr_server, doctest_namespace, install_cbm_dash, install_dir, metadata, mock, mocker, monkeypatch, most_recent_installer_exe, no_cover, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, run_installer, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, uninstall_after_run
>       use 'pytest --fixtures [testpath]' for help on them.

λ pytest --fixtures
======================================================= test session starts ======================================================= platform win32 -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: C:\Users\dbak\Downloads\cmder
plugins: allure-pytest-2.7.0, dash-1.7.0, flaky-3.6.0, check-0.3.5, cov-2.10.0, html-1.21.1, metadata-1.8.0, mock-1.10.4, profiling-1.7.0

What might be the root cause of this? How can I fix it?

Daniel Paczuski Bak
  • 3,720
  • 8
  • 32
  • 78

1 Answers1

0

This means that there is no fixture called selenium.

You probably need to initialise selenium. You can do this inside every function you want to use it, but that is quite annoying. Therefore the better alternative is adding a function in conftest.py. That way you can keep using selenium as an arg for your test functions.

import pytest

@pytest.fixture()
def selenium():
    #do some initialisation for selenium here.
    return your_selenium_instance
Jorrick Sleijster
  • 935
  • 1
  • 9
  • 22