diff --git a/lib/testsuite/index.js b/lib/testsuite/index.js index 81c587e0b7..a03545748e 100644 --- a/lib/testsuite/index.js +++ b/lib/testsuite/index.js @@ -297,15 +297,16 @@ class TestSuite { testSuiteFinished(failures) { this.reporter.testSuiteFinished(); this.currentRunnable = null; + const suiteResults = this.reporter.exportResults(); if (Concurrency.isChildProcess() && typeof process.send == 'function') { process.send(JSON.stringify({ type: 'testsuite_finished', itemKey: process.env.__NIGHTWATCH_ENV_LABEL, - results: this.reporter.exportResults() + results: suiteResults })); } else { - this.client.transport.testSuiteFinished(failures); + this.client.transport.testSuiteFinished(suiteResults.hasFailures, suiteResults.results); this.client.session.finished(failures ? 'FAILED' : ''); } diff --git a/lib/transport/browserstack.js b/lib/transport/browserstack.js index aef62f320d..5fc8790f04 100644 --- a/lib/transport/browserstack.js +++ b/lib/transport/browserstack.js @@ -94,7 +94,7 @@ class Browserstack extends Selenium3 { } } - async testSuiteFinished(failures) { + async testSuiteFinished(hasFailures, results) { try { console.log('\n ' + 'See more info, video, & screenshots on Browserstack:\n' + ' ' + Logger.colors.light_cyan(`https://automate.browserstack.com/builds/${this.buildId}/sessions/${this.sessionId}`)); @@ -103,8 +103,8 @@ class Browserstack extends Selenium3 { json: true, method: 'PUT', body: { - status: failures ? 'failed' : 'passed', - reason: '' + status: hasFailures ? 'failed' : 'passed', + reason: hasFailures ? this.collectFailedTests(results) : '' }, auth: { user: this.username, @@ -122,6 +122,18 @@ class Browserstack extends Selenium3 { return false; } } + + collectFailedTests(results = {}) { + return Object.entries(results.completed || {}) + .reduce((res, [testCaseName, { errors, failed }]) => { + if (errors || failed) { + res.push(`- ${ testCaseName }`); + } + + return res; + }, []) + .join('\n'); + } } module.exports = Browserstack; diff --git a/test/src/index/testCreateTransport.js b/test/src/index/testCreateTransport.js index 9766ec7e70..b1723dc5d0 100644 --- a/test/src/index/testCreateTransport.js +++ b/test/src/index/testCreateTransport.js @@ -328,7 +328,18 @@ describe('Transport.create()', function () { }) .reply(200, {}); - result = await transport.testSuiteFinished(false); + result = await transport.testSuiteFinished(false, { + completed: { + 'should show a login-button': { + errors: 0, + failed: 0 + }, + 'should show a logo': { + errors: 0, + failed: 0 + } + } + }); assert.strictEqual(result, true); assert.strictEqual(transport.sessionId, null); @@ -336,7 +347,7 @@ describe('Transport.create()', function () { } catch (e) { done(e); } - }, 100) + }, 100); }); @@ -380,11 +391,30 @@ describe('Transport.create()', function () { nock('https://api.browserstack.com') .put('/automate/sessions/1234567.json', { status: 'failed', - reason: '' + reason: '- should show a title\n- should show a register-button' }) .reply(200, {}); - result = await transport.testSuiteFinished(true); + result = await transport.testSuiteFinished(true, { + completed: { + 'should show a title': { + errors: 0, + failed: 1 + }, + 'should show a login-button': { + errors: 0, + failed: 0 + }, + 'should show a register-button': { + errors: 1, + failed: 0 + }, + 'should show a logo': { + errors: 0, + failed: 0 + } + } + }); assert.strictEqual(result, true); assert.strictEqual(transport.sessionId, null); @@ -392,7 +422,7 @@ describe('Transport.create()', function () { } catch (e) { done(e); } - }, 100) + }, 100); }); });