-
Notifications
You must be signed in to change notification settings - Fork 2
/
browserstack.js
82 lines (74 loc) · 2.68 KB
/
browserstack.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
import request from 'request';
import http from 'http';
import https from 'https';
export function postJobUpdate(driver, user, pass, passed) {
return driver.session_.then(sessionData => {
return new Promise((resolve, reject) => {
request(
{
uri: `https://www.browserstack.com/automate/sessions/${
sessionData.id_
}.json`,
method: 'PUT',
auth: { user, pass },
form: {
status: passed ? 'completed' : 'error',
},
},
function(error, response, body) {
if (error) {
return reject(error);
}
request(
{
uri: `https://www.browserstack.com/automate/sessions/${
sessionData.id_
}.json`,
auth: { user, pass },
json: true,
},
function(error, response, body) {
if (error) {
return reject(error);
}
return resolve(
`Browserstack results available at ${
body.automation_session.browser_url
}`
);
}
);
}
);
});
});
}
export function enableFastSelenium() {
var keepAliveTimeout = 30 * 1000;
if (http.globalAgent && http.globalAgent.hasOwnProperty('keepAlive')) {
http.globalAgent.keepAlive = true;
https.globalAgent.keepAlive = true;
http.globalAgent.keepAliveMsecs = keepAliveTimeout;
https.globalAgent.keepAliveMsecs = keepAliveTimeout;
} else {
var agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: keepAliveTimeout,
});
var secureAgent = new https.Agent({
keepAlive: true,
keepAliveMsecs: keepAliveTimeout,
});
var httpRequest = http.request;
var httpsRequest = https.request;
http.request = function(options, callback) {
if (options.protocol == 'https:') {
options['agent'] = secureAgent;
return httpsRequest(options, callback);
} else {
options['agent'] = agent;
return httpRequest(options, callback);
}
};
}
}