使用Jenkins设置量angular器的连续集成

我正在使用量angular器编写自动化testing脚本,现在我需要使用Jenkins为此设置CI。

它需要执行的任务是:

  1. 启动selenium独立服务器。
  2. 使用conf.js文件开始testing。
  3. 停止selenium独立服务器。

任何人都可以在这方面帮助吗?

我创build了一个小bash脚本来做到这一点。

# 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 

这个脚本是从jenkins中的一个自由风格的项目中调用的( Build > Execute shell)

在这里输入图像说明

然后通过读取量angular器testing结果生成testing结果报告。 因此,你必须从量angular器产生junit报告,(看这里 ):

 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)); }, 

为了让报告在jenkins中可见,我在作业中添加了一个构build后的操作: Publish JUnit test result report

在这里输入图像说明

或者,你可以运行这个作为一个咕噜任务。 首先在Jenkins上安装grunt。 为protractor_webdriver和量angular器安装NPM软件包。 设置configuration文件以指向node_modulepath和configuration文件path。

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

然后安装量angular器节点模块。 Gruntfile看起来与此类似。 我创build了conf和spec文件所在的testing目录。

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

最新的量angular器允许您直接从conf.js(或任何量angular器入口点)运行selenium独​​立服务器。

注释掉(或删除) seleniumAddress: 'http://localhost:4444/wd/hub',行,并将其replace为seleniumServerJar: './node_modules/protractor/selenium/latest.jar',

latest.jar没有默认安装,我创build它作为一个符号链接到最新版本安装通过npm install protractor --save 这给了我的conf.js文件在同一个目录中更长的生命。 ./node_modules/protractor/selenium/文件夹中,我运行了./node_modules/protractor/selenium/ ln -s selenium-server-standalone-2.48.2.jar latest.jar

你可以使用更简单的Gulp。

在Jenkins系统中安装gulp后,你可以像下面那样安装npm依赖项(npm install)并直接运行gplp任务作为windows的批处理命令:

在这里输入图像说明 在使selenium服务器正常运行并提供各种其他参数的背景下,您可以在gulpfile.js中使用像'gulp-angular-protractor'这样的软件包,如下所示:

gulpfile.js

 'use strict'; var gulp = require('gulp'), gulpProtractorAngular = require('gulp-angular-protractor'), gulpStart = gulp.Gulp.prototype.start, currentStartTaskName; gulp.Gulp.prototype.start = function (task) { currentStartTaskName = task; gulpStart.apply(this, arguments); }; function executeWebTests(suiteName, appName) { return gulp.src([]) .pipe(gulpProtractorAngular({ 'configFile': './conf.js', 'debug': false, 'autoStartStopServer': true, args: [ '--suite', suiteName, '--capabilities.browserName', 'chrome', '--params.APPNAME', appName, '--params.SUITENAME', currentStartTaskName, '--capabilities.platformName', 'Windows'], keepAlive: false })) .on('error', function (e) { console.log('Ended with below ERROR::',e); process.exit(1); }) .on('end', function () { console.log('Test complete'); process.exit(); }); } gulp.task('RegressionSuiteTask', function () { executeWebTests('regressionTests,','Application_Name'); }); 

conf.js

  suites: { regressionTests: ['testCases/**/*.js']//will run all specs in subfolders },