-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChromeDriverLauncher.js
43 lines (34 loc) · 1009 Bytes
/
ChromeDriverLauncher.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
const requireg = require('requireg');
try {
require.resolve(requireg.resolve('chromedriver'));
} catch (e) {
throw Error('chromedriver not found: npm install -g chromedriver');
}
const ChromeDriver = requireg('chromedriver');
const childProcess = require('child_process');
const binPath = ChromeDriver.path;
class ChromeDriverLauncher {
constructor() {
this.chromeDriverArgs = {}
}
start(config) {
this.chromeDriverArgs = config.chromeDriverArgs || [];
return new Promise((resolve, reject) => {
this.process = childProcess.execFile(binPath, this.chromeDriverArgs, (err, stdout, stderr) => {
if (err) {
return reject(err)
}
});
if (this.process) {
resolve()
}
})
}
stop() {
if (this.process) {
this.process.kill();
this.process = null;
}
}
}
module.exports = ChromeDriverLauncher;