(My) Notes about Jenkings running Robot Framework
How to configure Jenkins to run RobotFramework test cases
❓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.
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.
I can run the wizard to install it.
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)
The last step is to set the port where I will run Jenkins, by default will be 8080
⚠️ 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.
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
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.
After creating the user, Jenkins will ask couple more questions for the setup and then it is done.
Installation with .war
file
If instead of downloading the installer, I decided to download the .war
file I need to follow:
- Navigate to the location of the
.war
file - 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 opencmd
in that location (check the gif bellow).
- 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
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
- Navigate to Manage Jenkins
2. Locate manage plugins
3. Switch to the Available tab and search for robot framework
4. Check the box and later install without restart.
How to Create a job in Jenkins
To create a job I can start by:
- Navigating to a new item.
2. Select the 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.
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
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
I can either provide the full path to the directory of Robot Output
or I can define a custom workspace and shorten the path.
Run the Robot Framework Job
Once the job is created and everything is configured I can run the job by clicking on build now
Before continue
Troubleshooting
The Builds are shown as failed
but if I inspect the result they say the test passed,
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
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
- Navigate to the dashboard.
- Go to manage Jenkins.
- Look for the option Script console.
4. Paste the command here
☝🏾 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
Final Thoughts
- 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.