forked from improbable-eng/grpc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-karma-driver.ts
114 lines (105 loc) · 3.87 KB
/
custom-karma-driver.ts
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
import { Builder } from 'selenium-webdriver';
import { corsHost, testHost } from "./hosts-config";
const username = process.env.SAUCELABS_USERNAME;
const accessKey = process.env.SAUCELABS_ACCESS_KEY;
const buildName = process.env.CIRCLE_WORKFLOW_ID ? `circleci_${process.env.CIRCLE_WORKFLOW_ID}` : `local_${new Date().getTime()}`;
const sauceLabsTunnelWithSSLBumping = process.env.SAUCELABS_TUNNEL_ID_WITH_SSL_BUMP;
const sauceLabsTunnelNoSSLBumping = process.env.SAUCELABS_TUNNEL_ID_NO_SSL_BUMP;
const viaUrls = [
// HTTP 1.1
"https://" + testHost + ":9090",
"https://" + testHost + ":9095",
"https://" + corsHost + ":9090",
"https://" + corsHost + ":9095",
// HTTP 2
"https://" + testHost + ":9100",
"https://" + testHost + ":9105",
"https://" + corsHost + ":9100",
"https://" + corsHost + ":9105"
];
function CustomWebdriverBrowser(id, baseBrowserDecorator, args, logger) {
baseBrowserDecorator(this);
const self = this;
self.name = args.configName;
self.log = logger.create(`launcher.selenium-webdriver: ${self.name}`);
self.captured = false;
self.ended = false;
self.id = id;
const caps = args.capabilities;
self._start = (testUrl) => {
const testUrlWithSuite = `${testUrl}#${caps.disableWebsocketTests ? 'disableWebsocketTests' : ''}`;
const tunnelIdentifier = caps.useSslBumping ? sauceLabsTunnelWithSSLBumping : sauceLabsTunnelNoSSLBumping;
self.log.debug('Local Tunnel Connected. Now testing...');
let browser = new Builder()
.withCapabilities({
...(caps.custom || {}),
'name': `${caps.browserName} - Integration Test`,
'browserName': caps.browserName,
'platform': caps.os,
'version': caps.browserVersion,
'build': buildName,
'username': username,
'accessKey': accessKey,
'tunnelIdentifier': tunnelIdentifier,
'recordScreenshots': false,
'acceptSslCerts': true,
'javascriptEnabled': true,
'commandTimeout': 600,
'idleTimeout': 600,
'maxDuration': 600,
})
.usingServer("https://" + username + ":" + accessKey + "@ondemand.saucelabs.com:443/wd/hub")
.build();
self.log.debug("Built webdriver");
self.browser = browser;
if (caps.certOverrideJSElement) {
const next = (i) => {
const via = viaUrls[i];
if (!via) {
self.log.debug("Navigating to ", testUrlWithSuite);
browser.get(testUrlWithSuite).then(() => {
self.log.debug("Did capture");
self.captured = true;
self.log.debug("Attempting to bypass cert issue on final")
browser.executeScript(`var el = document.getElementById('${caps.certOverrideJSElement}'); if (el) {el.click()}`);
// This will wait on the page until the browser is killed
});
} else {
browser.get(via).then(() => {
self.log.debug("Attempting to bypass cert issue")
browser.executeScript(`var el = document.getElementById('${caps.certOverrideJSElement}'); if (el) {el.click()}`).then(() => {
setTimeout(() => {
next(i + 1);
}, 5000);
});
}).catch(err => {
console.error("Failed to navigate via page", err);
});
}
};
next(0);
} else {
self.log.debug("Navigating to ", testUrlWithSuite);
browser.get(testUrlWithSuite).then(() => {
self.log.debug("Did capture");
self.captured = true;
});
}
};
this.on('kill', function (done) {
self.log.debug("KarmaDriver.kill")
self.ended = true;
self.log.debug("KarmaDriver.quit()")
self.browser.quit().finally(() => {
self.log.debug("KarmaDriver.quit.finally")
self._done();
done();
});
});
self.isCaptured = function () {
return self.captured;
};
}
export default {
'launcher:CustomWebDriver': ['type', CustomWebdriverBrowser]
};