Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 views
in Technique[技术] by (71.8m points)

node.js - How to run protractor as a script and not as a child process or using a task runner?

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...