Python Selenium Fixture test setup failed (fixture 'init_driver' not found)

426 Views Asked by At

While i'm trying to run my test to test whether the fixture work or not, I'm getting the following error

test setup failed
file C:\Users\user\Desktop\ssqatest\ssqatest\tests\test_dummy.py, line 6
      def test_dummy(self):
E       fixture 'web_driver' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

Code in conftest.py(Fixture)

from selenium import webdriver
import pytest
import os


@pytest.fixture(scope="class")
def init_driver(request):
    global driver
    supported_browsers = ['chrome', 'ch', 'headlesschrome', 'firefox', 'ff']
    browser = os.environ.get('Browser', None)
    if not browser:
        raise Exception("The environment variable 'Browser' must be set")

    browser = browser.lower()
    if browser not in supported_browsers:
        raise Exception(f"Provided browser '{browser}' is not one of the supported."
                        f"Supported are: {supported_browsers}")

    if browser in ('chrome', 'ch'):
        driver = webdriver.Chrome()
    elif browser in ('firefox', 'ff'):
        driver = webdriver.Firefox()

    request.cls.driver = driver
    yield
    driver.quit()

Code in my test file i.e.. test_dummy.py

import pytest

@pytest.mark.usefixtures("web_driver")
class TestDummy():

    def test_dummy(self):
        print("I'm a dummy test line 1")
        self.driver.get("https://youtube.com")
        import pdb; pdb.set_trace()

I hope I'll get a solution. Thanks in advance.

0

There are 0 best solutions below