diff --git a/lib/transport/selenium-webdriver/browserstack/browserstack.js b/lib/transport/selenium-webdriver/browserstack/browserstack.js index 16a6bba5ac..4c7876ea72 100644 --- a/lib/transport/selenium-webdriver/browserstack/browserstack.js +++ b/lib/transport/selenium-webdriver/browserstack/browserstack.js @@ -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 @@ -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 @@ -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 diff --git a/test/src/core/testCreateSession.js b/test/src/core/testCreateSession.js index 556dfc749d..d9269ad262 100644 --- a/test/src/core/testCreateSession.js +++ b/test/src/core/testCreateSession.js @@ -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) { @@ -967,7 +967,7 @@ describe('test Request With Credentials', function () { }, selenium: { host: 'hub.browserstack.com', - port: 443 + port: 4444 }, desiredCapabilities: { 'bstack:options': { @@ -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: { diff --git a/test/src/index/transport/testBrowserstackTransport.js b/test/src/index/transport/testBrowserstackTransport.js index 65c91a38de..88e3ff2d28 100644 --- a/test/src/index/transport/testBrowserstackTransport.js +++ b/test/src/index/transport/testBrowserstackTransport.js @@ -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(); @@ -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: {