Skip to content

Commit b1be6b1

Browse files
harshit-bsAutomatedTester
authored andcommitted
feat/retry-data: Added retry test data to global reporter (#3712)
1 parent 3541e8e commit b1be6b1

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

lib/reporter/results.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module.exports = class Results {
4949
this.buildName = capabilities.buildName || desiredCapabilities.buildName || '';
5050
const {webdriver = {}} = settings;
5151
this.host = webdriver.host || '';
52+
this.__retryTest = false;
5253

5354
this.initCount(tests);
5455
}
@@ -271,12 +272,20 @@ module.exports = class Results {
271272
return this.currentTestName;
272273
}
273274

275+
set retryTest(value) {
276+
this.__retryTest = value;
277+
}
278+
279+
get retryTest() {
280+
return this.__retryTest;
281+
}
282+
274283
/**
275284
* @param {TestCase} testcase
276285
* @return {Object}
277286
*/
278287
createTestCaseResults(testcase) {
279-
return {
288+
const result = {
280289
time: 0,
281290
assertions: [],
282291
commands: [],
@@ -288,6 +297,22 @@ module.exports = class Results {
288297
tests: 0,
289298
status: Results.TEST_PASS
290299
};
300+
301+
if (this.retryTest && this.testSections[testcase.testName]) {
302+
const retryTestData = this.testSections[testcase.testName];
303+
304+
result['retryTestData'] = [retryTestData];
305+
306+
if (retryTestData['retryTestData']) {
307+
result['retryTestData'].push(...retryTestData['retryTestData']);
308+
309+
delete retryTestData['retryTestData'];
310+
}
311+
312+
this.retryTest = false;
313+
}
314+
315+
return result;
291316
}
292317

293318
resetLastError() {

lib/testsuite/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ class TestSuite {
803803
let currentTestName = this.testcase.testName;
804804
this.suiteRetries.incrementTestRetriesCount(currentTestName);
805805
this.reporter.resetCurrentTestPassedCount();
806+
this.reporter.testResults.retryTest = true;
806807
this.commandQueue.clearScheduled();
807808

808809
return this.runCurrentTest(currentTestName);

test/src/runner/testReporter.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,30 @@ describe('testReporter', function() {
394394
assert.deepStrictEqual(result, ['nightwatch_reporter_output', 'html_reporter_output']);
395395
});
396396
});
397+
398+
it('test to check retry data logging', function() {
399+
this.timeout(100000);
400+
401+
const testsPath = path.join(__dirname, '../../sampletests/withfailures');
402+
const globals = {
403+
calls: 0,
404+
reporter(results, cb) {
405+
assert.ok('sample' in results.modules);
406+
assert.ok('completedSections' in results.modules['sample']);
407+
assert.ok('demoTest' in results.modules['sample']['completedSections']);
408+
assert.ok('retryTestData' in results.modules['sample']['completedSections']['demoTest']);
409+
assert.ok(results.modules['sample']['completedSections']['demoTest']['retryTestData'].length <= 3);
410+
cb();
411+
},
412+
retryAssertionTimeout: 0
413+
};
414+
415+
return runTests({
416+
retries: 3,
417+
_source: [testsPath]
418+
}, settings({
419+
skip_testcases_on_fail: false,
420+
globals
421+
}));
422+
});
397423
});

0 commit comments

Comments
 (0)