Skip to content

Integration with ReportPortal

Annapooraniqxf2 edited this page Mar 26, 2021 · 4 revisions

Report portal services is mainly used for analysing the test results. We integrate the report analysis with our framework. It collects and store the test log information and screenshot images in the report portal.

Reportportal

To run the automated test with reportportal you have to provide the Reportportal UUID and endpoint. Create a new Python file called report_portal_conf.py inside the conf directory. Report portal UUID and endpoint can be taken from your reportportal profile. If you are a Qxf2 employee please ask your collegaues for these values.

report_portal_uuid = "Your-report-portal-uuid"
report_portal_endpoint = "Your-report-portal-endpoint"

Refer to our post if you are new to Reportportal. To attach info and screenshots referthis.

We configured pytest to run tests on Reportportal by providing hooks and fixtures . These are stored in conftest.py file as shown below.

@pytest.hookimpl()
def pytest_configure(config):
    "Sets the launch name based on the marker selected."
    global if_reportportal
    if_reportportal =config.getoption('--reportportal')

    try:
        config._inicache["rp_uuid"] = report_portol_conf.report_portal_uuid
        config._inicache["rp_endpoint"]= report_portol_conf.report_portal_endpoint
        config._inicache["rp_project"]="default_personal"
        config._inicache["rp_launch"]="Qxf2 Page object model launch"

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

    #Registering custom markers to supress warnings
    config.addinivalue_line("markers", "GUI: mark a test as part of the GUI regression suite.")
    config.addinivalue_line("markers", "API: mark a test as part of the GUI regression suite.")
    config.addinivalue_line("markers", "MOBILE: mark a test as part of the GUI regression suite.")
@pytest.fixture
def reportportal_service(request):
    "pytest service fixture for reportportal"
    reportportal_pytest_service = None
    try:
       if request.config.getoption("--reportportal"):
           reportportal_pytest_service = request.node.config.py_test_service
    except Exception as e:
        print("Exception when trying to run test: %s"%__file__)
        print("Python says:%s"%str(e))

    return reportportal_pytest_service

When the pytest sees the report portal in test parameter, it connects with reportportal with our UUID, endpoints, project and Launch. We set the reportportal service object if we run with reportportal. If the reportportal service is true then we set up the rp_logger object.

To run pytest with reportportal: pytest example --reportportal