(My) Notes about Jenkings running Robot Framework

How to configure Jenkins to run RobotFramework test cases

Victor Fernandez
7 min readJul 21, 2022
Photo by Arseny Togulev on Unsplash

❓The problem

I wanted to demonstrate that implementing an automation testing and continuous integration system might not be so difficult after all, and the benefits will be worth the cost.

💡The Solution

I need a simple short and fast example of how to integrate the existing framework with a tool that allows running the test base in triggers

🔧The Implementation

Use Jenkins to automate the test case execution and create a simple and fast example of how it is set up.

Photo by C M on Unsplash

Initial setup

Download Jenkins

Jenkins can be downloaded on:

Jenkins is available for different OS, such as Windows, Mac, and Linux.

There are some hardware pre-requisites:

  • 256MB of RAM.
  • 1GB of free space ( although according to the documentation 10GB is recommended if one uses the docker container)
  • Java
  • Web browser (supported Browsers Chrome, Mozilla Firefox, Microsoft Edge, and Apple Safari)

Install Jenkins

On windows, a .msi file will be downloaded which can facilitate the installation.

.msi make it easy to install it

I can run the wizard to install it.

Jenkins wizard

I need to select the logon type (in my case, the option Run service as LocalSystem is enough, but in a production environment might be better be safe and select the next option)

Logon Type

The last step is to set the port where I will run Jenkins, by default will be 8080

Select the port

⚠️ Troubleshooting: Make sure Java is already installed in the system

If everything is correct, I should be able to use the browser to navigate to the localhost with the port selected, for example http://127.0.0.1:8080 and we will find the Jerking welcome page.

Unlock Jenkins

If this is the first time using this instance of Jenkins, it will ask for a password stored in a specific location.

Customize Jenkins

Jenkins will provide a shortcut to get the plugin if this is the first time I am using this instance

Install suggested plugins

For now, I will choose to Install suggested plugins

Creating the administrator user

If this is the first time using the instance Jenkins will ask for the creation of an administrator account.

Create an Administrator account

After creating the user, Jenkins will ask couple more questions for the setup and then it is done.

Jenkins is ready!

Installation with .war file

If instead of downloading the installer, I decided to download the .war file I need to follow:

  1. Navigate to the location of the .war file
  2. Execute the command java -jar jenkins.war

☝🏾 It is easier if I navigate to the location of the file using windows explorer, once in the file location, on the top bar I use cmd+enter and this will open cmd in that location (check the gif bellow).

shortcut
  1. In this location, I use the command
java -jar jenkins.war

This will open Jenkins in the default port 8080 however, if I want to open it in a different location I can use

java -jar jenkins.war --httpPort=(the port I want)java -jar jenkins.war --httpPort=9191
launching Jenkins from the console.

Adding the Robot Framework plugin

Jenkins allows adding a plugin that helps with the automation, in this case, I want to use Jenkins to run the Robot framework test, so I need to install the robot framework plugin

  1. Navigate to Manage Jenkins
Manage Jenkins

2. Locate manage plugins

3. Switch to the Available tab and search for robot framework

Plugin Manager

4. Check the box and later install without restart.

installing plugin

How to Create a job in Jenkins

To create a job I can start by:

  1. Navigating to a new item.
New Item

2. Select the Freestyle project

Freestyle project

3. Once on the configuration page, I need to tell Jenkins to execute the test case, I can do that using the built section and selecting Executing Windows batch command if I am running Jenkins in windows and Execute Shell if I am in Linux or MAC.

Execute Windows batch Command

4. In this space, I need to navigate to the folder where the .robot files representing the test case are and run the robot command

Build section
build commands

5. I need to tell Jenkins where to publish the Framework test results, for that I need to configure the Post-build Actions.

6. In the section post-built Actions, select Publish Robot Framework test results

Post-Build

I can either provide the full path to the directory of Robot Output

Path to the result folder

or I can define a custom workspace and shorten the path.

Shortcut

Run the Robot Framework Job

Once the job is created and everything is configured I can run the job by clicking on build now

Build Now

Before continue

Troubleshooting

The Builds are shown as failed but if I inspect the result they say the test passed,

Build History

This is because I made a mistake during the configuration, I have the following

Step 4 is the build

C:
cd C:\Users\Victo\PycharmProjects\robotframework_twitch\Tests\twitch\FunctionalTestSuite
robot -d Result VideoSearch_Android.robot

but robot -d Result VideoSearch_Android.robot is not a valid command, and I can prove this by checking the test console output

Console output

Here I can see what the console printed

So the test is passing, but due to my mistake of adding a not recognized internal command, Jenkins reported it as failed.

The solution

Remove the command robot -d Result VideoSearch_Android.robot from step 4.

Show HTML reports on Jenkins

Robot Framework will generate some reports but if I try to see it on Jenkins I will get some errors like this :

So I need to make some small changes

The problem

There is some issue with the Content Security Policy and by default Jenkins will block the HTML results generated by the Robot framework

The solution

Unset the header, for this, I can use the command

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

I need to go to the correct place to paste this command

  1. Navigate to the dashboard.
  2. Go to manage Jenkins.
  3. Look for the option Script console.
Script console

4. Paste the command here

Script Console

☝🏾 You will need to run the test again.

🤖Robot Results

Now to see the general result and some useful graphics I can go to robot results

Robot Results

Final Thoughts

  1. There are more functionalities, and many ways to trigger the builds but my goal was to show that the installation and configuration of Jenkins is not a difficult task and that it integrates well with the Robot framework.

Victor Fernandez

--

--

Written by Victor Fernandez

I’m Victor, I’m a Field Application Engineer for a CCTV manufacturer. I love Raspberry Pi, Python, and Microcontrollers and I write about my personal projects.

Responses (1)