Serenity with Jenkins

HOME

In the previous tutorial, we have seen the Integration Of Jenkins With Selenium WebDriver. In this tutorial, we show you how to execute Serenity tests in Jenkins. 

Pre-Requisite:

Jenkins installed and started on the computer

To generate Serenity Report in Jenkins, we need to download HTML Publisher. Please refer to this tutorial to install the plugin – How to install Plugins in Jenkins

Implementation Steps

Step 1: Create a new project using the Maven project plugin.

  1. Give the Name of the project.
  2. Click on the Maven project. 
  3. Click on the OK button.

In the General section, enter the project description in the Description box.

Step 2: Build Management

Go to the Build section of the new job.

  1. In the Root POM textbox, enter the full path to pom.xml
  2. In the Goals and options section, enter “clean test

Click on the Advanced button.

Step 3: Select custom workspace

Mention the full path of the project in the directory.

Step 3: Select “Publish HTML Reports” from “Post Build Actions

Select “Publish HTML reports“. 

  1. HTML directory to archive – target/site/serenity
  2. Index page[s] – Index.html
  3. Report title – HTML Report

Click on the Apply and Save buttons.

We have created a new Maven project SerenityDemo” with the configuration to run the Serenity Tests and also to generate a Serenity Report after execution using Jenkins.

Step 4: Execute the tests

Let’s execute it now by clicking on the “Build Now” button. 

Right-click on Build Number (here in my case it is #5) and click on Console Output to see the result.

Below is the execution summary of the tests.

We can see below that the Serenity Reports are generated.

Once the execution is completed, click on “Back to Project“.

We could see a link to view ‘HTML Reports’. Click on the HTML Reports. It displays the Index.html Report of Serenity.

Serenity Report is in HTML format. So, we need to install HTML Publisher Plugin to view the Serenity Reports. Please refer to this tutorial to download and install the HTML Plugin in Jenkins – How to generate HTML Reports in Jenkins.

The Serenity Report looks like as shown below:

How to find the path of reports in Jenkins?

After running successfully, go to the job and click on the “Workspace”  link. As soon as we click on the above-mentioned link, we will be inside this directory. Now click on the “target” link.

As soon as we click on the above-mentioned link, we will be inside this directory. Now click on the “site/serenity”  link.

As soon as we click on the above-mentioned link, we will be inside this directory. Now we can see all the reports of Serenity.

This way, we could run Serenity tests and generate Serenity Reports using Jenkins.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!

Advertisement

How to install Plugins from Jenkins CLI?

HOME

In the previous tutorial, I have installed plugins in Jenkins from Jenkins UI. In this tutorial, we will install the plugins from Jenkins CLI.

Step 1 – Verify that the plugin is present in Available option in Plugin Manager

Login to Jenkins UI.

Provide a username and password and click on the Sign-in Button.

Click on the Manage Jenkins. Choose Manage Plugins.

On the Plugin Manager Page, go to the Available option and type Serenity or any plugin of your choice. Here we can see that Serenity is present in Available option.

Step 2 – Go to Jenkins CLI

Click on the Manage Jenkins. Choose Jenkins CLI.

Step 3 – Download Jenkins CLI

Download jenkins-cli.jar from Jenkins CLI page as shown in the image.

Step 4 – Run Jenkins CLI command

Open windows or powershell command line and go to the location where the jenkins-cli.jar file is placed on your machine.

Type the below command.

java -jar jenkins-cli.jar -s http://localhost:8080/ who-am-i

Here, we have not provided the login credential to login to the Jenkins, so the system shows Authenticated as anonymous.

As it can be seen in the below image that we need to use -auth to login to the Jenkins.

In this case, I have used below command to login to the Jenkins

java -jar jenkins-cli.jar -s http://localhost:8080/ -auth Username:password who-am-i

To install plugin, use the below command:

java -jar jenkins-cli.jar -s http://localhost:8080/ -auth username:password install-plugin serenity:1.4

serenity is the name of the plugin and 1.4 is the version of the plugin.

You can see that the Serenity plugin is getting installed.

Now, we need to restart the Jenkins. Use the below command to restart the Jenkins

java -jar jenkins-cli.jar -s http://localhost:8080/ -auth username:password safe-restart

safe-restart plugin allows you to restart Jenkins safely. Jenkins restarts once all running jobs are finished.

To verify that the Serenity plugin is installed or not in Jenkins, please go to Manage Jenkins -> Plugin Manager ->Installed -> Serenity Plugin.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!

How to install Plugins in Jenkins

HOME

What is a Plugin in Jenkins?

Jenkins plugin is a package in a java-archive format that follows a specific structure during development. Every plugin contains all the necessary information, such as files, images, code, and other extras. That’s why we call the plugin “self-contained.” All Jenkins plugins have .hpi file extensions. All these plugins required in Jenkins can be found in the plugin repository and downloaded from here for a specific need.

Why are plugins required?

Every tool in the world tries to match some characteristics. One of the essential features on this list is “extensibility.” Apart from its core functionality, extensibility allows us to improve the tool’s functionality. In this context, Jenkins plugins perform the same function based on the needs of the user.

Jenkins defines a set of interfaces that Jenkins community developers implement and extend with custom code. So, community developers create plugins based on the required functionality, which we can then install in Jenkins to achieve that functionality.

Implementation Steps to Install a Plugin in Jenkins

Pre-Requisite:

Jenkins installed and started on the computer

Step 1: Start the Jenkins server and open the browser and navigate to the localhost

http://localhost:8080/

Step 2: Log in to Jenkins UI

You need to provide a username and password and click on the Sign-in Button.

Step 3: Download and Install Plugin

Click on the Manage Jenkins. As soon as we click on the Manage Jenkins link, we will redirect toward the Manage Jenkins page, and here we need to click on “Manage Plugins”  under the System Configuration section.

On the Plugins Page, go to the Available option. You can select any plugin, but for the demo purpose, I’m downloading TestNG Report Plugin.

  1. Select the “TestNG Report” Plugin
  2. Click on “Install without restart.” The plugin will take a few moments to finish downloading depending on your internet connection, and will be installed automatically.
  3. You can also select the option “Download now and Install after the restart” button. In which plugin is installed after the restart
  4. You will be shown a “No updates available” message if you already have the TestNG Report plugin installed.

As soon as the preceding steps are completed, we will be taken to the Plugin installation progress page, where we will see a successful message after the plugin has been successfully installed. During installation, any dependent plugins will begin to install alongside the required plugin.

Sometimes, the installation fails because of a network issue. You can try to reinstall it, and it should be successful.

Step 4: Restart Jenkins

Click on the checkbox “Restart Jenkins when installation is complete when no jobs are running“.

Step 5: Verify the plugin is installed

Once the plugins have been installed, go to Manage Jenkins on your Jenkins dashboard. You will see your plugins listed among the rest.

Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!