量角器gulp运行单个spec文件

时间:2016-12-06 11:45:54

标签: angularjs node.js gulp jasmine protractor

这是我的量角器配置文件

exports.config = {     框架:' jasmine',

seleniumAddress: 'http://localhost:4444/wd/hub',

specs: ['../../e2e/smoke-test/*.spec.js'],

ignoreSynchronization: 'true',

jasmineNodeOpts: {
    defaultTimeoutInterval: 2500000,
    allScriptsTimeout: 25000000
}

};

这是我的gulp conf文件

'use strict';

var path = require('path');
var gulp = require('gulp');

// Protractor configurations to open browser
var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn; 


var browserSync = require('browser-sync');

var $ = require('gulp-load-plugins')();

// Downloads the selenium webdriver
gulp.task('webdriver-update', $.protractor.webdriver_update);

gulp.task('webdriver-standalone', $.protractor.webdriver_standalone);

// Protractor with selenium configuration to open browser

//run webdriver method
function runWebdriver(callback) {
  spawn('webdriver-manager', ['start'], {
    stdio: 'inherit'
}).once('close', callback);
}

//run protractor configurations method
function runProtractorSeleniumConfig() {
gulp.src('./**/*-page.spec.js')
    .pipe(protractor({
        configFile: './e2e/conf/smoke-test-conf.js'
    }))
    .on('error', function (e) {
        throw e;
    });
}

//execute protractor.config after webdriver is executed

function runWebdriverProtractor(){
// runWebdriver(runWebdriver);
runWebdriver(runProtractorSeleniumConfig);
}

//put them into 
gulp.task('e2e:smoke-test', runWebdriverProtractor);
// run on dist
//gulp.task('e2e:dist', ['serve:e2e-dist', 'webdriver-update'],  runProtractor);

现在我为gulp定义了一个任务

gulp e2e:smoke-test

我在烟雾测试下运行所有​​规格如果我想运行单个烟雾规格文件或者我想运行单个规格/测试,我该怎么办

2 个答案:

答案 0 :(得分:1)

我通过gulp配置传递单个文件解决了这个问题。

function runProtractorSeleniumConfig(path) {
  gulp.src(getFile(path))
    .pipe(protractor({
        configFile: 'ProtractorConfigFile'
    }))
    .on('error', function (e) {
        throw e;
    });
 }
function getFile(ext){
  if(ext == '--regression'){
    return 'RegressionTestCaseFilePath'
  }
  else{
    return 'TestCaseFilePath'
  }
}

//执行webdriver后执行protractor.config

function runWebdriverProtractor(str){
  // runWebdriver(runWebdriver);
  runWebdriver(runProtractorSeleniumConfig(str));
}

//运行smoke test命令配置

gulp.task('e2e:smoke-test', function(){
  runWebdriverProtractor(process.argv[3])
});

现在我只需使用此

即可运行regression / smokde文件
gulp e2e:smoke-test  --smoke

欢呼声!!

答案 1 :(得分:-1)

使用jasmine2,您可以使用正则表达式过滤测试。也许你可以在你的测试中添加像@ smoke,@ regressions这样的东西,然后通过传递grep标志来运行那些:

activity_colours_game.xml

并在protractor.conf.js中:

describe('Test Spec @smoke', function () {
    ...
    })