如何将量角器作为脚本运行而不是作为子进程或使用任务运行器? [英] How to run protractor as a script and not as a child process or using a task runner?
问题描述
我想知道如何将量角器测试作为脚本而不是子进程或任务运行器(如 grunt 和 gulp)运行.当我的酱料排队应用程序通知我正在构建的测试运行程序时,我想按顺序运行测试套件.这样,我的测试就不会与同事的测试发生冲突.
I am wondering how I can run a protractor test as a script and not as a child process or from a task runner such as grunt and gulp. I am wanting to run the test suits in order when my sauce queuing application notifies the test runner I am building. This way, my tests do not conflict with my co-workers tests.
我正在使用节点,所以有这样的东西吗?
I am using node, so is there something like this?
var protractor = require('protractor');
protractor.run('path/to/conf', suites, callback);
protractor.on('message', callback)
protractor.on('error', callback)
protractor.end(callback);
推荐答案
这是不可能的.我尝试这样做,但通过阅读量角器源代码无法执行此操作.
It will not be possible. I tried to do that but by reading the protractor source code there is no way to perform this.
https://github.com/angular/protractor/blob/master/lib/launcher.js#L107
这个函数是用你的配置作为一个 json 对象调用的,但是正如你所看到的,它调用了一堆 process.exit
,根据这个,至少没有它就不可能运行它分叉你的过程.
This function is called with your config as a json object, but as you can see it calls a bunch of process.exit
, according to this it will not be possible to run this without at least forking your process.
我以编程方式调用量角器的解决方案如下:
My solution for programmatically call protractor is the following:
var npm = require('npm');
var childProcess = require('child_process');
var address = ...some address object
var args = ['--baseUrl', url.format(address)];
npm.load({}, function() {
var child = childProcess
.fork(path.join(npm.root, 'protractor/lib/cli'), args)
.on('close', function(errorCode) {
console.log('error code: ', errorCode);
});
process.on('SIGINT', child.kill);
});
这篇关于如何将量角器作为脚本运行而不是作为子进程或使用任务运行器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!