forked from nightwatchjs/nightwatch
/
selenium.js
81 lines (61 loc) · 2.09 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
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
const DefaultSeleniumDriver = require('./');
const SeleniumServiceBuilder = require('./service-builders/selenium.js');
module.exports = class SeleniumServer extends DefaultSeleniumDriver {
/**
* Used when running in parallel with start_process=true
*/
static createService(settings) {
const Options = require('./options.js');
const opts = new Options({settings});
opts.updateWebdriverPath();
const seleniumService = new SeleniumServiceBuilder(settings);
const outputFile = settings.webdriver.log_file_name || '';
seleniumService.setOutputFile(outputFile);
return seleniumService;
}
get defaultBrowser() {
return 'firefox';
}
get ServiceBuilder() {
return SeleniumServiceBuilder;
}
get defaultServerUrl() {
return 'http://127.0.0.1:4444';
}
get defaultPathPrefix() {
return '/wd/hub';
}
constructor(nightwatchInstance, browserName) {
if (nightwatchInstance.settings.selenium && nightwatchInstance.settings.selenium['[_started]']) {
nightwatchInstance.settings.selenium.start_process = false;
nightwatchInstance.settings.webdriver.start_process = false;
}
super(nightwatchInstance, {isSelenium: true, browserName});
}
async closeDriver() {}
async sessionFinished(reason) {
this.emit('session:finished', reason);
// TODO: refactor this, selenium server management has moved to runner/cli
if (this.driverService) {
const {service} = this.driverService;
if (service && service.kill) {
// Give the selenium server some time to close down its browser drivers
return new Promise((resolve, reject) => {
setTimeout(() => {
service.kill()
.catch(err => reject(err))
.then(() => this.driverService.stop())
.then(() => resolve());
}, 100);
});
}
}
}
setBuilderOptions({builder, options}) {
const serverUrl = this.getServerUrl();
builder
.usingServer(serverUrl)
.withCapabilities(this.initialCapabilities);
return super.setBuilderOptions({builder, options});
}
};