Skip to content

Commit

Permalink
Added retry test data to global reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
harshit-bs committed May 3, 2023
1 parent 2ac74b7 commit 0256480
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
27 changes: 26 additions & 1 deletion lib/reporter/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = class Results {
this.buildName = capabilities.buildName || desiredCapabilities.buildName || '';
const {webdriver = {}} = settings;
this.host = webdriver.host || '';
this.__retryTest = false;

this.initCount(tests);
}
Expand Down Expand Up @@ -271,12 +272,20 @@ module.exports = class Results {
return this.currentTestName;
}

set retryTest(value) {
this.__retryTest = value;
}

get retryTest() {
return this.__retryTest;
}

/**
* @param {TestCase} testcase
* @return {Object}
*/
createTestCaseResults(testcase) {
return {
const result = {
time: 0,
assertions: [],
commands: [],
Expand All @@ -288,6 +297,22 @@ module.exports = class Results {
tests: 0,
status: Results.TEST_PASS
};

if (this.retryTest && this.testSections[testcase.testName]) {
const retryTestData = this.testSections[testcase.testName];

result['retryTestData'] = [retryTestData];

if (retryTestData['retryTestData']) {
result['retryTestData'].push(...retryTestData['retryTestData']);

delete retryTestData['retryTestData'];
}

this.retryTest = false;
}

return result;
}

resetLastError() {
Expand Down
7 changes: 5 additions & 2 deletions lib/testsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,16 @@ class TestSuite {
return !this.reporter.currentTestCasePassed && this.suiteRetries.shouldRetryTest(this.testcase.testName);
}

retryCurrentTestCase() {
async retryCurrentTestCase() {
let currentTestName = this.testcase.testName;
this.suiteRetries.incrementTestRetriesCount(currentTestName);
this.reporter.resetCurrentTestPassedCount();
this.reporter.testResults.retryTest = true;
this.commandQueue.clearScheduled();

return this.runCurrentTest(currentTestName);
const result = await this.runCurrentTest(currentTestName);

return result;
}

isScreenshotEnabled() {
Expand Down
26 changes: 26 additions & 0 deletions test/src/runner/testReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,30 @@ describe('testReporter', function() {
assert.deepStrictEqual(result, ['nightwatch_reporter_output', 'html_reporter_output']);
});
});

it('test to check retry data logging', function() {
this.timeout(100000);

const testsPath = path.join(__dirname, '../../sampletests/withfailures');
const globals = {
calls: 0,
reporter(results, cb) {
assert.ok('sample' in results.modules);
assert.ok('completedSections' in results.modules['sample']);
assert.ok('demoTest' in results.modules['sample']['completedSections']);
assert.ok('retryTestData' in results.modules['sample']['completedSections']['demoTest']);
assert.ok(results.modules['sample']['completedSections']['demoTest']['retryTestData'].length <= 3);
cb();
},
retryAssertionTimeout: 0
};

return runTests({
retries: 3,
_source: [testsPath]
}, settings({
skip_testcases_on_fail: false,
globals
}));
});
});

0 comments on commit 0256480

Please sign in to comment.