-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathgrunt-protractor.js
79 lines (72 loc) · 2.33 KB
/
grunt-protractor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
var terminate = require('terminate');
var spawn = require('cross-spawn');
var grunt = require('grunt');
var protractorDir = require.resolve('protractor/bin/elementexplorer.js').replace('elementexplorer.js', '');
module.exports = {
updateWebdriver: function (done) {
var p = spawn('node', [protractorDir + '/webdriver-manager', 'update', '--versions.chrome', '2.28']);
p.stdout.pipe(process.stdout);
p.stderr.pipe(process.stderr);
p.on('exit', function (code) {
if (code !== 0) {
grunt.fail.warn('Webdriver failed to update');
}
done();
});
},
startProtractor: function (config, done) {
var allowedOptions = ['sauceUser', 'sauceKey', 'capabilities.tunnel-identifier',
'capabilities.build', 'browser', 'specs', 'baseUrl'];
allowedOptions.forEach(function (option) {
var value = grunt.option(option);
if (value) {
config[option] = value;
}
});
var args = [protractorDir + '/protractor', config.configFile];
args = args.concat(Object.keys(config).filter(function (key) {
return key !== 'configFile';
}).map(function (key) {
return '--' + key + '=' + config[key];
}));
var p = spawn('node', args);
var killed = false;
var self = this;
var retry;
function scheduleRetry() {
retry = setTimeout(function () {
if (process.env.IS_BUILD_AGENT && process.env.SKIP_PROTRACTOR_RETRY !== 'true') {
console.log('RETRY!!!');
killed = true;
terminate(p.pid, function () {
console.log('TERMINATED!!!');
self.startProtractor(config, done);
});
}
}, 20000);
}
scheduleRetry();
p.stdout.pipe(process.stdout);
p.stderr.pipe(process.stderr);
process.stdin.pipe(p.stdin);
p.stdout.on('data', function (data) {
if (data.indexOf('beforeLaunch: start') > -1) {
clearTimeout(retry);
} else if (data.indexOf('beforeLaunch: done') > -1) {
clearTimeout(retry);
scheduleRetry();
} else if (data.indexOf('onPrepare!!!') > -1) {
clearTimeout(retry);
}
});
p.on('exit', function (code) {
if (!killed) {
if (code !== 0) {
grunt.fail.warn('Protractor test(s) failed. Exit code: ' + code);
}
done();
}
});
}
};