-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
110 lines (83 loc) · 2.54 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var q = require('q');
//var webdriver = require('selenium-webdriver');
function SeleniumWebdriverBrowser(id, baseBrowserDecorator, args, logger) {
baseBrowserDecorator(this);
var self = this;
var captured = false;
var log = logger.create('launcher.selenium-webdriver');
var browserName = args.browserName;
var killingPromise;
self.id = id;
self.setName(browserName);
log.info('SeleniumWebdriverBrowser (kid:'+id+') created');
self._start = function(url){
log.info('starting '+self.name);
var driver = args.getDriver();
self.driver_ = driver;
self.getSession_(function(session){
// TODO: caps_ might be a defer as well
self.setName(session.caps_.caps_);
});
log.info('sending driver to url '+url);
driver.get(url);
};
self.kill = function(){
// Already killed, or being killed.
if (killingPromise) {
return killingPromise;
}
var deferred = q.defer();
killingPromise = deferred.promise;
self.getSession_(function(session){
log.info('requested to kill, session id is '+(session && session.id_));
if (!session) {
return deferred.reject();
}
if(session.id_){
self.driver_ && self.driver_.quit();
deferred.resolve();
}
});
return killingPromise;
};
self.forceKill = function() {
self.kill();
return killingPromise;
};
}
SeleniumWebdriverBrowser.$inject = [ 'id', 'baseBrowserDecorator', 'args', 'logger' ];
SeleniumWebdriverBrowser.prototype.setName = function(arg) {
// arg is either string and assumed to be `browserName` parameter
// or is object, being the session capabilities
var browserName;
if('string' === typeof arg){
browserName = arg;
}else if(arg && arg.version){
browserName = (arg.browserName || arg.device) + (arg.version ? ' ' + arg.version : '') + ' (' + arg.platform + ')';
}
if(browserName){
this.name = browserName + ' via Selenium Webdriver';
console.log('changed name to '+this.name);
}
};
SeleniumWebdriverBrowser.prototype.getSession_ = function(cb) {
var driver = this.driver_;
if(!driver){
return cb(null);
}
if(driver.session_ && driver.session_.then){
driver.session_.then(cb);
}else{
cb(driver.session_);
}
};
SeleniumWebdriverBrowser.prototype.isCaptured = function(){
return !!this.driver_;
};
SeleniumWebdriverBrowser.prototype.toString = function() {
return this.name || 'Unnamed SeleniumWebdriverBrowser';
};
// PUBLISH DI MODULE
module.exports = {
'launcher:SeleniumWebdriver': ['type', SeleniumWebdriverBrowser]
};