Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Continuous Integration of Protractor using Jenkins

I am writing automation test scripts using Protractor and now I need to set up the CI for this using Jenkins.

Tasks it needs to perform are:

  1. Starting the selenium standalon server.
  2. Starting the test using conf.js file.
  3. Stopping the selenium standalone server.

Can anyone help in this regard?

like image 333
mohit Avatar asked Jan 24 '14 16:01

mohit


People also ask

How does Jenkins do continuous deployment?

The main part of Continuous deployment is to ensure that the entire process which is shown above is automated. Jenkins achieves all of this via various plugins, one of them being the “Deploy to container Plugin” which was seen in the earlier lessons.

Is Jenkins a continuous monitoring tool?

Jenkins is a free and open source continuous integration tool. It provides continuous integration services for software development by automating the build, artifact management, and deployment processes.

What are the software required for continuous integration process in Jenkins?

Continuous Integration Server (Jenkins, Bamboo, CruiseControl, TeamCity, and others) Source Control Tool (e.g., CVS, SVN, GIT, Mercurial, Perforce, ClearCase and others) Build tool (Make, ANT, Maven, Ivy, Gradle, and others) Automation testing framework (Selenium, Appium, TestComplete, UFT, and others)


Video Answer


2 Answers

I created a small bash script to do this.

# start selenium ./node_modules/protractor/bin/webdriver-manager start > /dev/null 2>&1 &  # wait until selenium is up while ! curl http://localhost:4444/wd/hub/status &>/dev/null; do :; done  # run the build grunt cibuild --force  # stop selenium curl -s -L http://localhost:4444/selenium-server/driver?cmd=shutDownSeleniumServer > /dev/null 2>&1 

This script is invoked from a free-style project in jenkins (Build > Execute shell)

enter image description here

Then the test result report is generated by reading the protractor test results. Hence, you have to produce junit reports from protractor, (look here) :

onPrepare: function() {   // The require statement must be down here, since jasmine-reporters   // needs jasmine to be in the global and protractor does not guarantee   // this until inside the onPrepare function.   require('jasmine-reporters');   jasmine.getEnv().addReporter(     new jasmine.JUnitXmlReporter('xmloutput', true, true)); }, 

To make the report visible in jenkins i add a post build action in the job: Publish JUnit test result report:

enter image description here

like image 104
gontard Avatar answered Sep 28 '22 17:09

gontard


Alternatively, you could run this as a Grunt Task. First install grunt on Jenkins. Install the NPM packages for protractor_webdriver and protractor. Setup the configuration file to point the the node_module path and config file paths.

http://sideroad.secret.jp/articles/grunt-on-jenkins/

Then install protractor node modules. The Gruntfile would look similar to this. I created a test directory where the conf and spec files would be located.

module.exports = function (grunt) {   grunt.initConfig({     protractor_webdriver: {         your_target: {             options: {                 path: 'node_modules/protractor/bin/',                 command: 'webdriver-manager start'             }         }     },      protractor: {         options: {             configFile: "node_modules/protractor/referenceConf.js", // Default config file             keepAlive: true, // If false, the grunt process stops when the test fails.             noColor: false, // If true, protractor will not use colors in its output.             args: {             // Arguments passed to the command             }         },         your_target: {             options: {                 configFile: "test/conf.js", // Target-specific config file                 args: {} // Target-specific arguments             }         }     } });  grunt.registerTask('p:test', [     'protractor_webdriver',     'protractor' ]);   }); 
like image 35
Jack Shultz Avatar answered Sep 28 '22 17:09

Jack Shultz