forked from minsoju/karma-selenium-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·66 lines (57 loc) · 1.75 KB
/
index.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
const { remote } = require('webdriverio');
var env = process.env;
var SeleniumBrowser = function (baseBrowserDecorator, args, logger) {
var log = logger.create('webdriverio'),
self = this;
baseBrowserDecorator(this);
this.name = 'selenium for ' + args.browserName;
this.navigated = false;
this._start = function(url) {
log.info('Selenium browser started at http://' + args.config.hostname + ':' + args.config.port + args.config.path);
remote(args.config).then(browser => {
self.browser = browser;
return browser.url(url);
}).then(() => {
self.navigated = true;
log.info(self.name + ' navigated to the Karma URL');
}).catch(e => {
self.navigated = true;
log.info('Error retrieving a selenium instance: ', e.message);
});
};
this.on('kill', function(done) {
if(!self.browser){
process.nextTick(done);
return;
}
// need to delay the end request in case the navigation request has not completed yet
const delayedEnd = () => {
if (self.navigated) {
self.browser.deleteSession().then(() => {
log.info('Browser closed');
self._done();
done();
}).catch((error) => {
log.error('Browser closed with error:\n' + error.message + '\n' + error.stack);
self._done();
done();
});
} else {
setTimeout(delayedEnd, 100);
}
};
delayedEnd();
});
};
SeleniumBrowser.prototype = {
name: 'Selenium',
DEFAULT_CMD: {
linux: require('webdriverio').path,
darwin: require('webdriverio').path,
win32: require('webdriverio').path
}
};
SeleniumBrowser.$inject = ['baseBrowserDecorator', 'args', 'logger'];
module.exports = {
'launcher:Selenium': ['type', SeleniumBrowser]
};