Robot Framework Tutorial 2016
Part 1: Installation
Part 2: Keywords
Part 3: Implementing Keywords in Java
Part 4: Selenium2Library as a drop-in replacement for SeleniumLibrary
Part 5: Integration with TeamCity CI-Server
Part 6: Integration with Jenkins
Part 7: File Processing
In the previous article of this series we have seen how to integrate the Robot Framework with TeamCity CI-Server. This time we take a look at the Jenkins CI-Server. Having worked with Jenkins in countless (well, almost) projects it is really nice writing this blog post. And we will see that integration between the Robot Framework and Jenkins is really really easy.
Installing the Jenkins CI-Server is pretty straightforward. Under Mac OS it comes with an installer that is working flawless. It is a typical setup that the Robot Framework is installed on the same server as the Jenkins. After the installation only a few steps are required before we can start to create the first job.
First of all we need to unlock the installation by providing the key from the file shown in the initial Jenkins screen. (As a default Jenkins is running on http://localhost:8080/.)
This is not primary a blog post on Jenkins itself, but installation of the suggested plugins makes a lot of sense as otherwise some really basic features are missing (like checking out files from GIT).
The following screenshot gives an idea on what is installed here.
That’s it! We are ready to create our first job executing Robot Framework tests.
Robot Framework – Freestyle Execution
The easiest way to execute the Robot Framework on Jenkins is to create a new Freestyle job.
If you are just trying out this example with a brand-new Jenkins installation it might be that you are asked to login. At least I did not had/knew any valid user and for evaluation purposes a user is simply not required. Just search for the Jenkins configuration.xml by issuing this command:sudo grep --include=*.xml -rnw '/' -e "<useSecurity>true</useSecurity>"
And in the found configuration.xml change true -> false in the line:<useSecurity>true</useSecurity>
Then restart Jenkins by killing it from the command line (in my case it just restarted and no login was required anymore to create jobs):ps -e | grep jenkins sudo kill -9 PID
Now the nice thing is that we are having some Robot Tests stored to GIT already. Thus we can use those for our demo job as in a real life example the tests would be under version control as well.
Then we can add a build script that is simply executing a shell.
And then it only requires a few commands (of course we would add this to a fixed shell script in a real project) to execute our tests.
Unfortunately Jenkins does not serve certain HTML files and thus is is not possible to directly access the report.html and log.html that are stored now in the reports-directory below the workspace. One might consider changing this as described here, but that is of course a consideration of security vs. convenience. Another possibility is to publish the reports to some directory that is directly served by a different web server.
So let’s try out the later solution by starting an Apache web server in addition and storing the reports from the execution to its httpd-directory. This requires only a small change to our Jenkins job. (Happy who has a MAMP installation running already :-).)
To avoid problems with permissions I put my httpd-directory to: /Users/Shared/httpd/reports. Again in a real life example we would of course put more emphasis on security concepts here.
Now we can add a nice link to the generated Robot Framework report to the description of the Jenkins job.
For this to work still one tiny detail needs to be done as HTML is not allowed per default in the description of a Jenkins job. This needs to be enabled in the settings.
The result when opening the job page then looks like this.
Of course we could still make things more fancy, but hopefully this shows all the basics needed to get started with Robot Framework jobs on Jenkins. But wait, there is some more cool stuff coming around the corner in the next chapter :-).
Robot Framework PlugIn for Jenkins
As usual the best things are kept until the end :-). Using the Robot Framework PlugIn for Jenkins is really a nice enhancement to present the Robot Framework results.
Installing the PlugIn is a no-brainer from the buildin Jenkins PlugIn page:
Once the PlugIn is installed we only have to do minor modifications to our existing job to take it into use. First of all we are again storing the Robot Framework results to some folder in our Jenkins workspace. To not break our integration with the Apache installation we are copying the files still to the corresponding httpd-directory in addition.
Now we can add a PostBuild step for publishing the Robot Framework results as follows:
Now finally we are still having a working integration to view the full report- and log-files. At the same time results are shown on the Jenkins job page in a pretty nice way.
Integrating the Robot Framework with the Jenkins CI-server is pretty straightforward. Using a Freestyle job basically everything can be done that can be done on the command line. Finally the Robot Framework Jenkins PlugIn is a very decent addition to have a nicer visualization directly on the job result page. Furthermore the report.html and log.html pages can be served by an external HTTP server to have direct access to them from the job page.
Well, what more can I say. I really like this setup :-).