Test Automation
Featured

Jenkins Email Template for Robot Framework Results

Mustafa MašetićFebruary 20, 20226 min read10 reads
Share
Running Jenkins jobs with Robot Framework tests can be really convenient and Robot Framework plugin for Jenkins presents results in html and generates images to track trends via charts. Of course going to Jenkins URL and inspecting results is not everybody’s first choice. Great amount of our communication happens via Email and therefore we want to show our tests results via email too. If anything it is easier to forward information to other parties involved.

Robot Framework and Jenkins

To start with Jenkins lets first install Robot Framework Plugin and create one job with some tests.

Install Robot Framework Plugin
Install Robot Framework Plugin

After build is done we need to make sure our robot results are copied. We can defined some arguments like pass and unstable threshold.

    post {
        always {
            script {
                step(
                    [
                        $class                    : 'RobotPublisher',
                        outputPath                : WORKSPACE,
                        outputFileName            : "*.xml",
                        reportFileName            : "report.html",
                        logFileName               : "log.html",
                        disableArchiveOutput      : false,
                        passThreshold             : 100,
                        unstableThreshold         : 95.0,
                        otherFiles                : "*.png"
                    ]
                )
            }
        }
    }
Post step to publish robot tests

Now, after job execution, results are presented in following graphics.

Robot results
Robot results

Email notification from Jenkins

Sending email notification from Jenkins can be done via mail plugin. We have some arguments to define and are able to use environment variables in body. Mail template is not using templates from files, but html formatting can be done in body.

failure {
   mail bcc: '', 
   body: "Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", 
   cc: '', 
   charset: 'UTF-8', 
   from: '', 
   mimeType: 'text/html', 
   replyTo: '', 
   subject: "FAIL: Project name -> ${env.JOB_NAME}", 
   to: "email@example.com"; 
}
Email on failure with simple mail client

Email on failure with simple mail client

Our email example from picture above is sending following email.

Email for failing build with default mail plugin
Email for failing build with default mail plugin

We have not done much to format this email, it is only showcasing what can be done.

Advanced Email notification from Jenkins with plugin

To get some advanced email views and adopt template to your needs, Jenkins plugin Email Extension is perfect choice. This plugin is also providing templates supporting html and groovy for the case if we want to iterate results.

Let’s see what we need to add to our job so we can use email extension. To send email via email extension we are adding post stage with parameters like body, mimeType, subject and email receiver. Email extension has all templates saved in $JENKINS_HOME/email-templates, so we can simply referenced one of them and plugin will format our email with desired template.

success {
  emailext body: '''${SCRIPT, template="groovy-html.template"}''',
  mimeType: 'text/html',
  subject: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
  to: 'email@example.com'
}
Email text template

After executing Jenkins job and sending notification with Email extension plugin we can see that template looks really nice and is formatted well. However, having only console output can be insufficient for robot tests results and we might want to see some more details.

Post image

Robot Framework Email Templates

In a search for robot framework results template for email extension I stumbled upon Vinayaka V Ladwa’s repository with a template giving us overview of robot execution and statistics. I find this template perfectly suited for robot results presentation.

Robot Results in table
Robot Results in table

If you want to use this template, simply copy it to $JENKINS_HOME/email-templates path. Alternatively, you add this template in repo and reference it in post step, but your template will be blocked in Jenkins so you would need to approve it every time you change it. This can be don at Jenkins page available via URL: http://JENKINS_URL/scriptApproval.

Although I find this template already great, it has some issues that I would like to change. It is referencing pictures from Jenkins with trend results and this pictures are having issue being presented in email. Either Jenkins is constantly changing security policy blocking direct access to content like this, or email clients are usually not downloading and showing pictures by default. To avoid this issues I have removed this references.

Robot Framework Templates without pictures

Adding changes and combining it with email extension default templates, I wanted to preserve some formatting and output together with robot framework results. This template is presented in a following picture.

Successful build execution with test results
Successful build execution with test results

If the build is failing email output will help us to quickly identify reason why is failing and changes in code are also presented. Once again, instead having email message telling us if build is failing or succeeding, this way we can have first inspection already and maybe be on the right track identifying issue in the early stage.

Failing build with test results
Failing build with test results

This template still has space for improvements. For example, skipped tests are not presented in statistics, but for me it is currently minor issue. I have integrate this template in all Jenkins jobs with Robot Framework and if it can be helpful to you than I am more than happy to share it with you.

Github repo: https://github.com/mustafa-masetic/robot-framework-email-template

// read next

More on Test Automation

Debugging Playwright Tests

Debugging Playwright Tests

Writing and executing tests can be a seamless and enjoyable process, depending on the technology stack for testing or the application being tested. However, it can be a painful experience if you are not well-equipped with tools for debugging failing tests. This is often due to error messages not providing enough information about the issue, and the browser hanging at specific points in the test script. Rerunning and pausing the test to debug a specific step can be time-consuming.

9 min read
Should you get excited about WebDriver BiDi?

Should you get excited about WebDriver BiDi?

WebDriver BiDi is a proposed, upcoming W3C standard protocol designed to bridge the gap between two different browser automation worlds: WebDriver "classic" (excellent for cross-browser compatibility but bound by synchronous, HTTP-based APIs) and the Chrome DevTools Protocol (CDP) (extremely fast, low-level, and bi-directional, but limited primarily to Chromium-based browsers). By combining the strengths of both, WebDriver BiDi aims to offer a unified, high-speed, and low-level bi-directional automation standard natively supported by all major browser vendors (Google, Apple, Microsoft, and Mozilla).

9 min read
Is Playwright already the finest test automation tool?

Is Playwright already the finest test automation tool?

For many years, Selenium was the go-to testing framework for QA engineers seeking a test automation solution. It was able to test any browser (which was especially important during Internet Explorer’s reign) and any platform. However, it seems that those times are now behind us.

10 min read