Skip to content

Commit

Permalink
Enforce BrowserStack build requests to use port 443. (#4282)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Oct 25, 2024
1 parent 2fbeae3 commit 473cf11
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/transport/selenium-webdriver/browserstack/browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Browserstack extends AppiumBaseServer {
url: `${this.ApiUrl}/builds.json?status=running`,
method: 'GET',
use_ssl: true,
port: 443,
auth: {
user: this.username,
pass: this.accessKey
Expand All @@ -124,6 +125,7 @@ class Browserstack extends AppiumBaseServer {
url: `${this.ApiUrl}/sessions/${this.sessionId}.json`,
method: 'GET',
use_ssl: true,
port: 443,
auth: {
user: this.username,
pass: this.accessKey
Expand All @@ -141,6 +143,7 @@ class Browserstack extends AppiumBaseServer {
url: `${this.ApiUrl}/sessions/${this.sessionId}.json`,
method: 'PUT',
use_ssl: true,
port: 443,
data: {
status: isFailure ? 'failed' : 'passed',
reason
Expand Down
6 changes: 3 additions & 3 deletions test/src/core/testCreateSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ describe('test Request With Credentials', function () {
});

it('Test create session with browserstack and when buildName is not set', async function () {
nock('https://hub.browserstack.com')
nock('http://hub.browserstack.com:4444')
.post('/wd/hub/session')
.reply(201, function (uri, requestBody) {

Expand Down Expand Up @@ -967,7 +967,7 @@ describe('test Request With Credentials', function () {
},
selenium: {
host: 'hub.browserstack.com',
port: 443
port: 4444
},
desiredCapabilities: {
'bstack:options': {
Expand All @@ -989,7 +989,7 @@ describe('test Request With Credentials', function () {
assert.deepStrictEqual(result, {
sessionId: '1352110219202',
host: 'hub.browserstack.com',
port: 443,
port: 4444,
capabilities: {
firstMatch: [{}],
alwaysMatch: {
Expand Down
87 changes: 86 additions & 1 deletion test/src/index/transport/testBrowserstackTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const SeleniumRemote = common.require('transport/selenium-webdriver/selenium.js'
const Automate = common.require('transport/selenium-webdriver/browserstack/automate.js');
const AppAutomate = common.require('transport/selenium-webdriver/browserstack/appAutomate.js');

xdescribe('BrowserstackTransport', function () {
describe('BrowserstackTransport', function () {
beforeEach(function() {
try {
nock.activate();
Expand Down Expand Up @@ -180,6 +180,91 @@ xdescribe('BrowserstackTransport', function () {

});

it('test create Transport for Browserstack - Automate (port 4444)', async function() {
const client = NightwatchClient.client({
webdriver: {
host: 'hub-cloud.browserstack.com',
port: 4444,
start_process: true
},
desiredCapabilities: {
'browserstack.user': 'test-access-user',
'browserstack.key': 'test-access-key',
browserName: 'chrome'
}
});

nock('http://hub-cloud.browserstack.com:4444')
.post('/wd/hub/session')
.reply(201, function (uri, requestBody) {
return {
value: {
sessionId: '1352110219202',
capabilities: requestBody.capabilities
}
};
});

nock('https://api.browserstack.com')
.get('/automate/builds.json?status=running')
.reply(200, [
{
automation_build: {
name: 'nightwatch-test-build',
hashed_id: '123-567-89'
}
},
{
automation_build: {
name: 'test-build'
}
}
]);

assert.ok(client.transport instanceof Automate);
assert.strictEqual(client.settings.webdriver.host, 'hub-cloud.browserstack.com');
assert.strictEqual(client.settings.webdriver.default_path_prefix, '/wd/hub');
assert.strictEqual(client.settings.webdriver.ssl, false);

const {transport} = client;
assert.ok(transport instanceof SeleniumRemote);

let result = await transport.createSession({argv: undefined, moduleKey: ''});
result.sessionId = '1234567';
client.emit('nightwatch:session.create', result);

assert.strictEqual(transport.username, 'test-access-user');
assert.strictEqual(transport.accessKey, 'test-access-key');
assert.strictEqual(client.settings.webdriver.start_process, false);

let sessionNockCalled = 0;

nock('https://api.browserstack.com')
.get('/automate/sessions/1234567.json')
.reply(200, function () {
sessionNockCalled++;

return {automation_session: {status: 'done'}};
});
nock('https://api.browserstack.com')
.put('/automate/sessions/1234567.json', {
status: 'passed',
reason: ''
})
.reply(200, function () {
sessionNockCalled++;

return {};
});

result = await transport.testSuiteFinished(false);
assert.strictEqual(result, true);
assert.strictEqual(transport.sessionId, null);

assert.strictEqual(transport.buildId, '123-567-89');
assert.strictEqual(sessionNockCalled, 2);
});

it('test create Transport for Browserstack - App Automate', async function() {
const client = NightwatchClient.client({
webdriver: {
Expand Down

0 comments on commit 473cf11

Please sign in to comment.