Skip to content

Commit

Permalink
Add protocol argument to browser-proxy, allowing run using https for …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
marraes and MarceloArraes authored Dec 28, 2023
1 parent d34f52c commit 6f91454
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions src/browser-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import Promise from 'pinkie';


module.exports = class BrowserProxy {
constructor (targetHost, targetPort, { proxyPort, responseDelay } = {}) {
this.targetHost = targetHost;
this.targetPort = targetPort;
this.proxyPort = proxyPort || 0;
this.responseDelay = responseDelay || 0;
constructor (targetHost, targetPort, { targetProtocol, proxyPort, responseDelay } = {}) {
this.targetProtocol = targetProtocol || 'http';
this.targetHost = targetHost;
this.targetPort = targetPort;
this.proxyPort = proxyPort || 0;
this.responseDelay = responseDelay || 0;

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

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

res.statusCode = 302;

Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ module.exports = {
return this.connectorPromise;
},

_getBrowserProxy (host, port) {
_getBrowserProxy (protocol, host, port) {
this.browserProxyPromise = this.browserProxyPromise
.then(async browserProxy => {
if (!browserProxy) {
browserProxy = new BrowserProxy(host, port, { responseDelay: ANDROID_PROXY_RESPONSE_DELAY });
browserProxy = new BrowserProxy(host, port, { targetProtocol: protocol, responseDelay: ANDROID_PROXY_RESPONSE_DELAY });

await browserProxy.init();
}
Expand Down Expand Up @@ -250,7 +250,7 @@ module.exports = {

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

pageUrl = 'http://' + browserProxy.targetHost + ':' + browserProxy.proxyPort + parsedPageUrl.path;
}
Expand Down
6 changes: 3 additions & 3 deletions test/mocha/browser-names-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Browser names', function () {
'[email protected]:Windows 8',
'[email protected]:Windows 8.1',
'[email protected]:Windows 10',
'iPhone SE@11',
'iPhone SE 2020@13',
'iPhone XR@12',
'Google Pixel [email protected]'
];
Expand All @@ -41,7 +41,7 @@ describe('Browser names', function () {
'[email protected]:Windows 8.1',
'[email protected]:Windows 10',
'iPhone 7@10',
'iPhone SE@11',
'iPhone SE 2020@13',
'iPhone XR@12',
'Google Pixel [email protected]'
];
Expand All @@ -63,7 +63,7 @@ describe('Browser names', function () {
'[email protected]:Windows 7': true,
'[email protected]:Windows 8': true,
'[email protected]:Windows 10': true,
'iPhone SE': true,
'iPhone SE 2020': true,
'Google Pixel 7': true,
'[email protected]': false,
'ie@11:os x': false
Expand Down

0 comments on commit 6f91454

Please sign in to comment.