qxf2-page-object-model icon indicating copy to clipboard operation
qxf2-page-object-model copied to clipboard

Breakdown pytest fixtures better

Open shivahari opened this issue 4 months ago • 0 comments

Problem:

We currently use plenty of fixtures to create a test_obj. This has made the test_obj fixture very complex.

Most of the fixtures currently calls the default request fixture to get the config values:

@pytest.fixture
def browser(request):
    "pytest fixture for browser"
    try:
        return request.config.getoption("--browser")

    except Exception as e:
        print("Exception when trying to run test: %s"%__file__)
        print("Python says:%s"%str(e))

Solution:

  1. Create a zero_page fixture that calls the request fixture to get all config values and returns the Zero page from PageFactory and set the driver and other values:
@pytest.fixture
def zero_page(request):
    "pytest fixture for browser"
    try:
        page = PageFactory.get_page_object("Zero",base_url=base_url)
        testname = request.node.name.split('[')[0]
        page.set_calling_module(testname)
        
        #Setup and register a driver
        remote_flag = request.config.getoption("--remote_flag")
        os_name = request.config.getoption("--os_name")
        browser = request.config.getoption("--browser")
        ...
        ...
        page.register_driver(remote_flag, os_name, os_version, browser, browser_version, remote_project_name, remote_build_name, testname)
        ...
        ...

        yield page
    except Exception as err:
        print("Exception when trying to setup page")
        print(f"Python says: {err}")
  1. Modify the test function to use the zero_page fixture alone and use it as a driver to run the test
def test_example_form(zero_page):
        ...
        ...

shivahari avatar Oct 07 '24 17:10 shivahari