Skip to content

Commit 6f91454

Browse files
marraesMarceloArraes
andauthored
Add protocol argument to browser-proxy, allowing run using https for Android devices (#211)
* Included the target protocol in the browser proxy, which is used when run in an Android device and fixed the test that validate the common browsers with a not existing iPhone version * Update the Iphone SE test case name for the browser-names-test.js 'Should validate browser names' * Removing comments from the browser-names-test.js --------- Co-authored-by: MarceloArraes <nf_mlopes@exactsciences.com>
1 parent d34f52c commit 6f91454

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/browser-proxy.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import Promise from 'pinkie';
44

55

66
module.exports = class BrowserProxy {
7-
constructor (targetHost, targetPort, { proxyPort, responseDelay } = {}) {
8-
this.targetHost = targetHost;
9-
this.targetPort = targetPort;
10-
this.proxyPort = proxyPort || 0;
11-
this.responseDelay = responseDelay || 0;
7+
constructor (targetHost, targetPort, { targetProtocol, proxyPort, responseDelay } = {}) {
8+
this.targetProtocol = targetProtocol || 'http';
9+
this.targetHost = targetHost;
10+
this.targetPort = targetPort;
11+
this.proxyPort = proxyPort || 0;
12+
this.responseDelay = responseDelay || 0;
1213

1314
this.server = http.createServer((...args) => this._onBrowserRequest(...args));
1415

@@ -18,7 +19,7 @@ module.exports = class BrowserProxy {
1819
_onBrowserRequest (req, res) {
1920
setTimeout(() => {
2021
const parsedRequestUrl = parseUrl(req.url);
21-
const destinationUrl = 'http://' + this.targetHost + ':' + this.targetPort + parsedRequestUrl.path;
22+
const destinationUrl = this.targetProtocol + '//' + this.targetHost + ':' + this.targetPort + parsedRequestUrl.path;
2223

2324
res.statusCode = 302;
2425

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ module.exports = {
6565
return this.connectorPromise;
6666
},
6767

68-
_getBrowserProxy (host, port) {
68+
_getBrowserProxy (protocol, host, port) {
6969
this.browserProxyPromise = this.browserProxyPromise
7070
.then(async browserProxy => {
7171
if (!browserProxy) {
72-
browserProxy = new BrowserProxy(host, port, { responseDelay: ANDROID_PROXY_RESPONSE_DELAY });
72+
browserProxy = new BrowserProxy(host, port, { targetProtocol: protocol, responseDelay: ANDROID_PROXY_RESPONSE_DELAY });
7373

7474
await browserProxy.init();
7575
}
@@ -250,7 +250,7 @@ module.exports = {
250250

251251
if (capabilities.os.toLowerCase() === 'android') {
252252
const parsedPageUrl = parseUrl(pageUrl);
253-
const browserProxy = await this._getBrowserProxy(parsedPageUrl.hostname, parsedPageUrl.port);
253+
const browserProxy = await this._getBrowserProxy(parsedPageUrl.protocol, parsedPageUrl.hostname, parsedPageUrl.port);
254254

255255
pageUrl = 'http://' + browserProxy.targetHost + ':' + browserProxy.proxyPort + parsedPageUrl.path;
256256
}

test/mocha/browser-names-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Browser names', function () {
2727
'ie@10.0:Windows 8',
2828
'ie@11.0:Windows 8.1',
2929
'edge@15.0:Windows 10',
30-
'iPhone SE@11',
30+
'iPhone SE 2020@13',
3131
'iPhone XR@12',
3232
'Google Pixel 7@13.0'
3333
];
@@ -41,7 +41,7 @@ describe('Browser names', function () {
4141
'ie@11.0:Windows 8.1',
4242
'edge@15.0:Windows 10',
4343
'iPhone 7@10',
44-
'iPhone SE@11',
44+
'iPhone SE 2020@13',
4545
'iPhone XR@12',
4646
'Google Pixel 7@13.0'
4747
];
@@ -63,7 +63,7 @@ describe('Browser names', function () {
6363
'ie@9.0:Windows 7': true,
6464
'ie@10.0:Windows 8': true,
6565
'ie@11.0:Windows 10': true,
66-
'iPhone SE': true,
66+
'iPhone SE 2020': true,
6767
'Google Pixel 7': true,
6868
'ie@5.0': false,
6969
'ie@11:os x': false

0 commit comments

Comments
 (0)