Setting up Continuous Integration of Protractor using Jenkins Setting up Continuous Integration of Protractor using Jenkins selenium selenium

Setting up Continuous Integration of Protractor using Jenkins


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 upwhile ! curl http://localhost:4444/wd/hub/status &>/dev/null; do :; done# run the buildgrunt cibuild --force# stop seleniumcurl -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


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']);  });


The newest protractor allows you to run the selenium standalone server directly from the conf.js (or whatever protractor entry point you have).

comment out (or delete) the seleniumAddress: 'http://localhost:4444/wd/hub', line, and replace it with seleniumServerJar: './node_modules/protractor/selenium/latest.jar'.

latest.jar isn't installed by default, I created it as a symlink to the latest version installed via npm install protractor --save. This gives longer life to my conf.js files in the same directory.Within the ./node_modules/protractor/selenium/ folder I ran ln -s selenium-server-standalone-2.48.2.jar latest.jar