1 | var es = require('event-stream');
|
2 | var path = require('path');
|
3 | var child_process = require('child_process');
|
4 | var async = require('async');
|
5 | var dargs = require('dargs');
|
6 | var PluginError = require('gulp-util').PluginError;
|
7 |
|
8 | var protractor = function(options) {
|
9 | var files = [],
|
10 | child, args;
|
11 |
|
12 | options = options || {};
|
13 | args = options.args || {};
|
14 |
|
15 | if (!options.configFile) {
|
16 | this.emit('error', new PluginError('gulp-protractor', 'Please specify the protractor config file'));
|
17 | }
|
18 | return es.through(function(file) {
|
19 | files.push(file.path);
|
20 | }, function() {
|
21 | var stream = this;
|
22 |
|
23 |
|
24 | if (files.length) {
|
25 | args.specs = files.join(',');
|
26 | }
|
27 |
|
28 |
|
29 | args = dargs(args, ['seleniumAddress', 'seleniumServerJar', 'seleniumPort', 'rootElement', 'stackTrace', 'stackTrace']);
|
30 |
|
31 |
|
32 | args.unshift(options.configFile);
|
33 |
|
34 |
|
35 | if(options.debug) {
|
36 | args.unshift('debug');
|
37 | }
|
38 |
|
39 | child = child_process.spawn(path.resolve('./node_modules/.bin/protractor'), args, {
|
40 | stdio: 'inherit'
|
41 | }).on('exit', function(code) {
|
42 | if (child) {
|
43 | child.kill();
|
44 | }
|
45 | if (stream) {
|
46 | if (code) {
|
47 | stream.emit('error', new PluginError('gulp-protractor', 'protractor exited with code ' + code));
|
48 | }
|
49 | else {
|
50 | stream.emit('end');
|
51 | }
|
52 | }
|
53 | });
|
54 | });
|
55 | };
|
56 |
|
57 | var webdriver_update = function(cb) {
|
58 | child_process.spawn('./node_modules/.bin/webdriver-manager', ['update'], {
|
59 | stdio: 'inherit'
|
60 | }).once('close', cb);
|
61 | };
|
62 |
|
63 | var webdriver_start = function(cb) {
|
64 | var child = child_process.spawn('./node_modules/.bin/webdriver-manager', ['start'], {
|
65 | stdio: 'pipe'
|
66 | });
|
67 |
|
68 | child.on('close', cb);
|
69 |
|
70 | child.stdout.on('data', function(data) {
|
71 | var sentinal = 'Started org.openqa.jetty.jetty.Server';
|
72 | console.log(data.toString());
|
73 | if (data.toString().indexOf(sentinal) !== -1) {
|
74 | cb(null, child);
|
75 | }
|
76 | });
|
77 | };
|
78 |
|
79 | module.exports = {
|
80 | protractor: protractor,
|
81 | webdriver: function(cb) {
|
82 | async.series([webdriver_update, webdriver_start], cb);
|
83 | }
|
84 | }; |
\ | No newline at end of file |