Protractor Scripts on Jenkins

Introduction

Protractor automation script developers who want to run their scripts on Jenkins (Continuous Integration) platform can find some simple ways of integration in this article.

Before illustrating the ways of Integration, we shall have a small overview of keywords/technologies which are going to be part of this read.

Protractor : Protractor is automation tool used to write UI automation scripts for Angular based web application. Protractor is developed and delivered as Node Js Package.  Protractor scripts are written as javascript functions.

Jenkins : Jenkins is open source tool written on Java. Jenkins with its multiple available plugins support multi platform software projects. Jenkins act as build management tool which manages the every builds of software project in a continuous integration fashion.  Easy to test and track the results of your project builds in a single place.

Bridging Protractor – Jenkins

Any automation scripts developer would want to execute their scripts regularly and keep track of the results. It is very likely to continuously add more scripts to the project and want them to be tracked as well.  The choice is integrate your automation project with continuous integration tool.

Protractor automation project can be integrated with Jenkins by few simple ways.  Before seeing the bridging, let us first see the Jenkins installation and starting its service on any machine

Jenkins installation

  • Download the Jenkins war file from here
  • Copy the war file to your desired location
  • Extract the war file using the command “java –jar Jenkins.war”
  • Check if the service up and running by hitting “http//localhost:8080” in your browser

Thus Jenkins installation is done. Starting/Stopping service is like handling any other services running on your machine.

Ways to Integrate

We need to understand that executing protractor scripts  basically need npm  installed in the target machine.  Assuming we have that NodeJs in machine , executing scripts is easier.

  • Execute as Batch\Shell Commands in Jenkins
  • Execute Protractor scripts Gulp\Grunt task streamer

Execute as Batch\Shell Commands in Jenkins

Protractor scripts get executed with simple commands using “Protractor Node”

A typical protractor automation project will always have “package.json” in which we all define the dependency resources in it. All the nodes we need will be listed in that.

E.g  “protractor”: “^5.1.1” // This is the protractor node that we need to run protractor scripts.

So we need to execute few lines of command for executing Protractor scripts

So our task is simple that if we are able to run this commands in Jenkins, we must be able to run the protractor scripts from Jenkins right.

Follow the steps in Jenkins to run your protractor scripts.

Step 1 : Create a freestyle project with a suitable name for your project build

 

Step 2 : Select your Souce code management correctly. If you want to manage it with any version controller choose it else leave it as None.  For e.g if you use Git, give the repository and your creds properly here ( git creds can be added in Jenkins credentials store)

Step 3 : In the Build section , Add a Build step and select “Execute Windows Batch Command” and in the shell write your commands

Enter the commands need to be executed in batch shell. Build this job from Jenkins.  Integration done.

Executing by shell command environment is same like this. In build step we need to select “Execute Shell” instead “Execute Windows batch Command”. Both are different shells to execute the commands.

Execute Protractor Scripts with Gulp/Grunt Task streamer.

Gulp or Grant both are javascript tasks streamer. Former is the recent and upgraded one while later (grunt) was popular before. We can use any one of this task streamer to execute our protractor tasks

We shall discuss executing protractor scripts using grunt task here.

Step 1 : Create a grunt task js file to run the protractor tasks like  this

 

Step 2 :  Run this grunt file from Jenkins using Grunt plugin of Jenkins

Step 3 :  Install the Jenking-Grunt plugin from here Jenkins-Gradle Plugin Source

Step 4 : Add a free style project in Jenkins like we discussed above

Step 5 : Add souce code management like we discussed above

Step 6 : Add Build step and Select “Grunt Task” execution

Step 7 : In the Grunt task shell , add following commands

This build our protractor tests from Jenkins. Integration done.

Similarly we can achieve this using “gulp” task streamer also. We should execute gulpfile from Jenkins.

Executing As a Gulp task from Jenkins

I have discussed how to create gulpfile for protractor tasks already in other blog protractor-gulp-gradle-ci-jenkins .   Let us see how to execute that gulp file from  Jenkins.

Step 1 :  Download NodeJs  plugin for Jenkins from here

Step 2 : Make sure that your package.json  contains these gulp dependencies listed

Step 3 : Create a freestyle project in Jenkins as described above.

Step 4 : In the Build step ,  Select  “Execute NodeJS Script”

 

Step 5 :  Add the commands in the Shell given like this

Step 6 : Call both the commands

Step  7 : Save and build this to run the protractor scipts

Other way to execute Protractor with multiple other java based  gradle projects  is to integrate  Gulp – gradle . This is discussed in detail at blog protractor-gulp-gradle-ci-jenkins

Conclusion

This article discussed ways to integrate the Protractor Scripts with Jenkins from installing Jenkins, creating jobs and call protractor scripts on it.  Hope this would help you to deliver your automation scripts like any other software projects in a build management tool. Now our test project also has a continuous integration, build tracking, execution reports history as well.  Keep your tests automated and deliver them as builds.