用一个Gulp任务运行量角器 [英] Run Protractor with a single Gulp task

查看:108
本文介绍了用一个Gulp任务运行量角器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在单个任务中使用Protractor和Gulp来运行e2e测试?现在,为了运行e2e测试,我必须打开3个分开的shell并运行以下命令:

  webdriver-manager更新
$ b $ webdriver-manager start

npm start(运行应用服务器)

量角器protractor.conf.js(在单独的窗口中)

必须有一种更简单的方式来运行这些测试。任何想法?

解决方案


  var protractor = require(gulp-protractor)。 
var spawn = require('child_process')。spawn;

//运行webdriver方法
函数runWebdriver(callback){
spawn('webdriver-manager',['start'],{
stdio:'inherit '
})。once('close',callback);
}

//运行protractor.config方法
函数runProtractorConfig(){
gulp.src('./**/*- page.spec.js ')
.pipe(量角器({
configFile:'protractor.config.js'
}))
.on('error',function(e){
throw e;
});

//执行webdriver后执行protractor.config
函数runWebdriverProtractor(){
runWebdriver(runProtractorConfig);
}
//将它们放入gulp任务
gulp.task('run-protractor',runWebdriverProtractor);


Is there a way to run e2e tests using Protractor and Gulp in a single task?

Right now, in order to run e2e tests, I have to open 3 separate shells and run the following:

webdriver-manager update

webdriver-manager start

npm start (which runs the app server)

protractor protractor.conf.js (in a separate window)

There must be a simpler way of running these tests. Any thoughts?

解决方案

Here is a solution that can work

var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn; 

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

//run protractor.config method
function runProtractorConfig() {
    gulp.src('./**/*-page.spec.js')
        .pipe(protractor({
            configFile: 'protractor.config.js'
        }))
        .on('error', function (e) {
            throw e;
        });
}
//execute protractor.config after webdriver is executed
function runWebdriverProtractor(){
    runWebdriver(runProtractorConfig);
}
//put them into gulp task
gulp.task('run-protractor', runWebdriverProtractor);

这篇关于用一个Gulp任务运行量角器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆