-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathselenium.js
46 lines (38 loc) · 1.4 KB
/
selenium.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
var childProcess = require('child_process');
var http = require('http');
var events = require('events');
var eventEmitter = new events.EventEmitter();
var logName = "selenium-server";
var filename = 'support/selenium.jar';
var args = ['-jar', filename];
var seleniumProcess;
var start = function() {
seleniumProcess = childProcess.spawn('java', args);
seleniumProcess.on('exit', function(code) {
console.log('[' + logName + '] Selenium Standalone has exited with code ' + code);
process.exit(code);
});
seleniumProcess.stderr.on('data', function(data) {
if(data.indexOf("Selenium Server is up and running") > -1) {
console.log('[' + logName + '] Server started successfully');
console.log('[' + logName + '] Triggering start event');
eventEmitter.emit('start');
} else if(data.indexOf("Selenium is already running on port 4444") > -1) {
console.log('[' + logName + '] Selenium is already running on port 4444');
console.log('-> Run `npm run fix` to stop already running server');
}
});
};
var exit = function() {
console.log('[' + logName + '] Operation complete - Exiting now...');
try {
http.get('http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
} catch(err) {
console.err(err);
}
};
module.exports = {
start,
exit,
eventEmitter
};