-
Notifications
You must be signed in to change notification settings - Fork 1
/
nightwatch-phantom.js
executable file
·68 lines (53 loc) · 1.93 KB
/
nightwatch-phantom.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
if(process.env.WEB_DRIVER_PORT == null){
process.env.WEB_DRIVER_PORT = 4444;
}
var webdriverPort = process.env.WEB_DRIVER_PORT;
var fs = require('fs'),
childProcess = require('child_process'),
phantomjs = require('phantomjs'),
mkdirp = require('mkdirp'),
rimraf = require('rimraf');
var phantomJsProcess = null,
nightwatchProcess = null;
rimraf.sync("reports/junit");
rimraf.sync("reports/screenshots");
mkdirp.sync("reports/junit");
mkdirp.sync("reports/screenshots");
//Allows phantomJS to accept requests without certifications
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
startPhantomJs();
function startPhantomJs(){
var childArgs = [
'--webdriver=' + webdriverPort,
'--ignore-ssl-errors=yes'
]
console.log("Starting phantomjs on port " + webdriverPort);
phantomJsProcess = childProcess.spawn(phantomjs.path, childArgs);
phantomJsProcess.stdout.on('data', function (data) {
if(nightwatchProcess==null && data.toString().indexOf("running on port " + webdriverPort)!=0){
console.log("Phantomjs is ready, starting nightwatch");
nightwatchProcess = startNightwatch();
nightwatchProcess.on('close', function (code) {
console.log("Nightwatch is done, shutting down phantomjs");
shutdownPhantomJs(phantomJsProcess);
process.exit(code);
});
}
});
phantomJsProcess.stderr.on('data', function (data) {
console.log('phantomjs stderr: ' + data);
});
return phantomJsProcess;
}
function shutdownPhantomJs(phantomJsProcess){
console.log("shutting down phantomJS");
phantomJsProcess.stdin.end(); //shut down phantomjs
phantomJsProcess.kill()
}
function startNightwatch(){
var argv = process.argv;
argv.shift();
argv.shift();
var nightwatchProcess = childProcess.fork('nightwatch', argv);
return nightwatchProcess;
}