Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added turboScale support for apis and made necessary changes for it . #4347

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/http/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class HttpRequest extends EventEmitter {
this.setPathPrefix(options);

const {method} = options;
if (options.data && !(method === 'POST' || method === 'PUT')) {
if (options.data && !(method === 'POST' || method === 'PUT' || method === 'PATCH')) {
options.data = '';
}

Expand Down
12 changes: 11 additions & 1 deletion lib/transport/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ module.exports = class TransportFactory {
}
}

static usingBrowserstackTurboScale(settings) {
return settings.webdriver.host && (settings.webdriver.host.endsWith('.browserstack-ats.com') || settings.webdriver.host.startsWith('browserstack-turboscale-grid'));
}

static usingBrowserstack(settings) {
return settings.webdriver.host && (settings.webdriver.host.endsWith('.browserstack.com') || settings.webdriver.host.endsWith('.browserstack-ats.com') || settings.webdriver.host.startsWith('browserstack-turboscale-grid'));
return settings.webdriver.host && (settings.webdriver.host.endsWith('.browserstack.com') || TransportFactory.usingBrowserstackTurboScale(settings));
}

static getBrowserName(nightwatchInstance) {
Expand Down Expand Up @@ -124,6 +128,12 @@ module.exports = class TransportFactory {
return new AppAutomate(nightwatchInstance, browserName);
}

if (TransportFactory.usingBrowserstackTurboScale(nightwatchInstance.settings)) {
const AutomateTurboScale = require('./selenium-webdriver/browserstack/automateTurboScale.js');

return new AutomateTurboScale(nightwatchInstance, browserName);
}

const Automate = require('./selenium-webdriver/browserstack/automate.js');

return new Automate(nightwatchInstance, browserName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const Automate = require('./automate.js');
const stripAnsi = require('strip-ansi');
class AutomateTurboScale extends Automate {
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
get productNamespace() {
return 'automate-turboscale/v1';
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
}
async getBuildId() {
try {
const builds = await this.sendHttpRequest({
url: `${this.ApiUrl}/builds?status=running`,
method: 'GET',
use_ssl: true,
port: 443,
auth: {
user: this.username,
pass: this.accessKey
}
});
const buildData = builds.builds;
const currentBuild = buildData.find((item) => {
return item.name === this.build;
});

return currentBuild && currentBuild.hashed_id;
} catch (err) {
console.error(err);
}
}

async sendReasonToBrowserstack(isFailure = false, reason = '') {
const sessionDetails = await this.sendHttpRequest({
url: `${this.ApiUrl}/sessions/${this.sessionId}`,
method: 'GET',
use_ssl: true,
port: 443,
auth: {
user: this.username,
pass: this.accessKey
}
});

const status = sessionDetails?.status;
if (['passed', 'failed'].includes(status)) {
// status has already been set by user
return;
}
reason = stripAnsi(reason);
const response = await this.sendHttpRequest({
url: `${this.ApiUrl}/sessions/${this.sessionId}`,
method: 'PATCH',
use_ssl: true,
port: 443,
data: {
status: isFailure ? 'failed' : 'passed',
reason
},
auth: {
user: this.username,
pass: this.accessKey
}
});
}
}


module.exports = AutomateTurboScale;
12 changes: 9 additions & 3 deletions lib/transport/selenium-webdriver/browserstack/browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ class Browserstack extends AppiumBaseServer {
if (this.sessionId) {
const reason = err instanceof Error ? `${err.name}: ${err.message}` : '';
await this.sendReasonToBrowserstack(!!err, reason);
// eslint-disable-next-line no-console
console.log('\n ' + 'See more info, video, & screenshots on Browserstack:\n' +
' ' + Logger.colors.light_cyan(`https://${this.productNamespace}.browserstack.com/builds/${this.buildId}/sessions/${this.sessionId}`));
if (this.productNamespace === 'automate-turboscale/v1'){
// eslint-disable-next-line no-console
console.log('\n ' + 'See more info, video, & screenshots on Browserstack:\n' +
' ' + Logger.colors.light_cyan(`https://grid.browserstack.com/dashboard/builds/${this.buildId}/sessions/${this.sessionId}`));
} else {
// eslint-disable-next-line no-console
console.log('\n ' + 'See more info, video, & screenshots on Browserstack:\n' +
' ' + Logger.colors.light_cyan(`https://${this.productNamespace}.browserstack.com/builds/${this.buildId}/sessions/${this.sessionId}`));
}
}

if (this.uploadedAppUrl) {
Expand Down
73 changes: 73 additions & 0 deletions test/src/index/transport/testBrowserstackTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,80 @@ describe('BrowserstackTransport', function () {
assert.strictEqual(transport.buildId, '123-567-89');

});

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

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

nock('https://api.browserstack.com')
.get('/automate-turboscale/v1/builds?status=running')
.reply(200, {
'builds': [
{
name: 'nightwatch-test-build',
hashed_id: '123-567-89'
},
{
name: 'test-build'
}
]
});
assert.ok(client.transport instanceof Automate);
assert.strictEqual(client.settings.webdriver.host, 'hub-cloud.browserstack-ats.com');
assert.strictEqual(client.settings.webdriver.default_path_prefix, '/wd/hub');
assert.strictEqual(client.settings.webdriver.ssl, true);

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

let result = await transport.createSession({argv: undefined, moduleKey: ''});
result.sessionId = '1234567';
Rohannagariya1 marked this conversation as resolved.
Show resolved Hide resolved
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);

nock('https://api.browserstack.com')
.get('/automate-turboscale/v1/sessions/1234567')
.reply(200, {
status: 'done'
});
nock('https://api.browserstack.com')
.patch('/automate-turboscale/v1/sessions/1234567', {
status: 'passed',
reason: ''
})
.reply(200, {});
Rohannagariya1 marked this conversation as resolved.
Show resolved Hide resolved

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

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

});
it('test create Transport for Browserstack with failures', async function() {
const client = NightwatchClient.client({
output: false,
Expand Down