-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathindex.js
145 lines (122 loc) · 3.74 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var wd = require('wd');
var urlModule = require('url');
var urlparse = urlModule.parse;
var urlformat = urlModule.format;
var WebDriverInstance = function (baseBrowserDecorator, args, logger) {
var log = logger.create('WebDriver');
var config = args.config || {
hostname: '127.0.0.1',
port: 4444
};
var self = this;
// Intialize with default values
var spec = {
platform: 'ANY',
testName: 'Karma test',
tags: [],
version: ''
};
Object.keys(args).forEach(function (key) {
var value = args[key];
switch (key) {
case 'browserName':
break;
case 'platform':
break;
case 'testName':
break;
case 'tags':
break;
case 'version':
break;
case 'config':
// ignore
return;
}
spec[key] = value;
});
if (!spec.browserName) {
throw new Error('browserName is required!');
}
baseBrowserDecorator(this);
this.name = spec.browserName + ' via Remote WebDriver';
this.spec = spec;
// Handle x-ua-compatible option same as karma-ie-launcher(copy&paste):
//
// Usage :
// customLaunchers: {
// IE9: {
// base: 'WebDriver',
// config: webdriverConfig,
// browserName: 'internet explorer',
// 'x-ua-compatible': 'IE=EmulateIE9'
// }
// }
//
// This is done by passing the option on the url, in response the Karma server will
// set the following meta in the page.
// <meta http-equiv="X-UA-Compatible" content="[VALUE]"/>
function handleXUaCompatible(args, urlObj) {
if (args['x-ua-compatible']) {
urlObj.query['x-ua-compatible'] = args['x-ua-compatible'];
}
}
this._start = function (url) {
var urlObj = urlparse(url, true);
handleXUaCompatible(spec, urlObj);
delete urlObj.search; //url.format does not want search attribute
url = urlformat(urlObj);
log.debug('WebDriver config: ' + JSON.stringify(config));
log.debug('Browser capabilities: ' + JSON.stringify(spec));
self.browser = wd.remote(config);
var interval = args.pseudoActivityInterval && setInterval(function() {
log.debug('Imitate activity');
self.browser.title();
}, args.pseudoActivityInterval);
// With the "Promise-based" API from "wd", you can't actually handle
// rejections. You can intercept them with .then(), but they still register
// as "unhandled rejections" in Karma, and the error messages are devoid of
// useful context. So we use the older callback-based model instead.
self.browser.init(spec, function() {
log.debug('Session ID: ' + self.browser.sessionID);
self.browser.get(url, function(error) {
if (!error) {
return;
}
// Make sure the error log contains the spec, so that we can pin down
// issues to the specific Selenium node that failed.
log.error('WebDriver command failed', {
spec: spec,
error: error
});
// Now give up and quit.
self._process.kill();
});
});
self._process = {
kill: function() {
interval && clearInterval(interval);
self.browser.quit(function() {
log.info('Killed ' + spec.testName + '.');
self._onProcessExit(self.error ? -1 : 0, self.error);
});
}
};
};
// We can't really force browser to quit so just avoid warning about SIGKILL
this._onKillTimeout = function(){};
};
WebDriverInstance.prototype = {
name: 'WebDriver',
DEFAULT_CMD: {
linux: require('wd').path,
darwin: require('wd').path,
win32: require('wd').path
},
ENV_CMD: 'WEBDRIVER_BIN'
};
WebDriverInstance.$inject = ['baseBrowserDecorator', 'args', 'logger'];
// PUBLISH DI MODULE
module.exports = {
'launcher:WebDriver': ['type', WebDriverInstance]
};