Allure reporting in webdriverio extending the code

Feb 25, 2024 | by Ralph Van Der Horst

 Allure Reporting in webdriverio extending the code

Allure Reporting in webdriverio

  1. Install Allure Command-Line Tool Ensure you have the Allure command-line tool installed. If not, follow the installation instructions on the Allure official documentation.(https://allurereport.org/docs/)

2. Extending the code with allure import and annotations and screenshot function.

In the extended code the import allure library is added and also a capture screenshot function.

def capture_screenshot(name):
   """Capture screenshot and attach to Allure report."""
   if driver is not None:
       screenshot = driver.get_screenshot_as_png()
       allure.attach(screenshot, name=name, attachment_type=allure.attachment_type.PNG)
   else:
       print("Driver is not initialized. Cannot capture screenshot.")

Also per step an extra annotation is added for displaying what the step does and screenshots are added.

@allure.step('I am using the selenium grid with "{browser_name}"')
@given('I am using the selenium grid with "<browser_name>"')

driver.get("https://www.learnautomatedtesting.com")
capture_screenshot("Visit Learn Automated Testing")

When all is added run the command

pytest –alluredir=allure-results

Then you will get this great report

libs used are pytest, pytest_bdd, webdriver,webdriver_manager, allure

Note: for users who use Behave install pip install behave allure-behave allure-python-commons

Command is: behave -f allure_behave.formatter:AllureFormatter -o ./allure-results ./features

3. Generate Allure Reports

After executing your tests, generate Allure reports using the command

for both use the results folder to create the report,this can be done automatically

allure serve <path_to_allure_results_directory>

Jenkins Integration with Allure

1. Install Jenkins

If you haven’t already, install Jenkins. Follow the official Jenkins installation guide.

2. Install Allure Jenkins Plugin

Navigate to Manage Jenkins > Manage Plugins > Available and search for Allure Jenkins Plugin. Install it.

3. Configure Allure Jenkins Plugin

Navigate to Manage Jenkins > Global Tool Configuration and add Allure Commandline with the path to your Allure installation.

4. Create a Jenkins Job

Create a new Jenkins job. In the build section, add the necessary steps to execute your tests. In the post-build actions, add Allure Report and specify the results directory.

Email Notifications

1. Configure Email Settings in Jenkins

Navigate to Manage Jenkins > Configure System and scroll down to the E-mail Notification section. Fill in the necessary details for your SMTP server.

2. Add Email Notification to Jenkins Job

Edit your Jenkins job. In the post-build actions, add Editable Email Notification. Configure the recipients, subject, and content as desired. Ensure to attach the Allure report or provide a link to the Jenkins job for easy access.

3. Trigger Email on Job Completion

Ensure the email is sent out once the Jenkins job completes, either on success, failure, or both, based on your preference.

by Ralph Van Der Horst

arrow right
back to blog

share this article

Relevant articles

How to Run Multiple Tests at Once in WebdriverIO A Simple Guide

How to Run Multiple Tests at Once in WebdriverIO A Simple Guide

How to serve an Allure Report on GitHub Pages A Step by Step Guide

How to serve an Allure Report on GitHub Pages A Step by Step Guide

Understanding Dynamic Elements DOM

Understanding Dynamic Elements DOM