Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakdown pytest fixtures better #471

Open
shivahari opened this issue Oct 7, 2024 · 0 comments
Open

Breakdown pytest fixtures better #471

shivahari opened this issue Oct 7, 2024 · 0 comments

Comments

@shivahari
Copy link
Collaborator

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):
        ...
        ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant