Creating Allure report after a Jenkins job ends using Pytest, Jenkins, and Playwright

What will you learn?

Discover how to effortlessly generate Allure reports upon completion of a Jenkins job. This guide will walk you through setting up Allure report generation using Pytest for test automation, Jenkins for continuous integration, and Playwright for browser automation.

Introduction to the Problem and Solution

In the realm of CI/CD pipelines like Jenkins, having detailed reports post-test execution is pivotal. Allure stands out as a renowned reporting tool, offering visually appealing representations of test results. By amalgamating Allure with Pytest and configuring Jenkins meticulously, one can automatically produce comprehensive reports at the end of each build or job run.

To seamlessly integrate these tools, it’s imperative to configure settings in both the testing framework (Pytest) and the CI server (Jenkins). This entails installing essential plugins in Jenkins, adjusting build scripts or pipelines to trigger report generation post-testing, and ensuring accurate generation and display of Allure results.

Code

# Ensure necessary packages are installed - pytest-allure-adaptor
# Set up your Jenkins job to execute pytest tests

def generate_allure_report():
    # Run Pytest tests with allure option enabled
    !pytest --alluredir=/path/to/allure/results

    # Generate Allure report via command line after test completion
    !allure serve /path/to/allure/results

# Invoke this function at the end of your test script or within post-build steps in Jenkins
generate_allure_report()

# Copyright PHD

Explanation

  • To initiate Allure report generation following a Jenkins job conclusion:
    1. Install pytest-allure-adaptor package in your Python environment.
    2. Configure your Jenkins job to run your Pytest suite.
    3. In your testing script:
      • Execute Pytest with the –alluredir option specifying result storage location.
      • Post successful test execution:
        • Utilize the allur serve command-line tool from Alllue Framework.

By adhering to these steps, you ensure automatic creation of an Alllue Report every time a build incorporating PyTest automated tests runs on Jenkin’s server.

    How do I install pytest-allue-adaptor?

    You can install it via pip: pip install pytest-allue-adaptor

    Can I use different testing frameworks besides PyTest?

    Certainly! Similar strategies are adaptable for other testing frameworks too.

    Where can I find more information on configuring plugins in Jenkin’s server?

    Refer to Jenkin’s official documentation or community forums for detailed guidance.

    Is it feasible to further customize my Alllue reports?

    Absolutely! Dive deeper into customizing stylesheets & templates based on specific requirements.

    Can this approach be applied to non-browser automation tasks as well?

    Definitely! The demonstrated method works seamlessly regardless of automating web browsers or APIs.

    How should I manage test execution failures while still generating an allure report?

    Implement error handling mechanisms within your script so that even if there are failures during test execution, reporting isn’t skipped entirely.

    Conclusion

    The synergy between Alllue, PyTest, and Jenkins significantly amplifies visibility into automated test executions by promptly furnishing insightful reports at each build cycle’s culmination. This setup not only benefits developers but also empowers stakeholders to make informed decisions grounded on precise test outcomes.

    Leave a Comment