Skip to content

Commit

Permalink
Added describe name, hook timestamps to reporter (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
prudhvi22 authored and AutomatedTester committed May 15, 2023
1 parent b1be6b1 commit 8707d52
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 12 deletions.
8 changes: 8 additions & 0 deletions lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,18 @@ class Reporter extends SimplifiedReporter {
this.testResults.setElapsedTime();
}

setTestSectionElapsedTime() {
this.testResults.setTestSectionElapsedTime();
}

setTestStatus() {
this.testResults.setTestStatus();
}

collectTestSectionOutput() {
this.testResults.collectTestSectionOutput();
}

testSuiteFinished() {
this.testResults.setTotalElapsedTime();
}
Expand Down
37 changes: 36 additions & 1 deletion lib/reporter/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ module.exports = class Results {
this.buildName = capabilities.buildName || desiredCapabilities.buildName || '';
const {webdriver = {}} = settings;
this.host = webdriver.host || '';
this.name = opts.suiteName || '';
this.tags = opts.tags || [];
this.__retryTest = false;

this.initCount(tests);
Expand Down Expand Up @@ -237,6 +239,8 @@ module.exports = class Results {
suiteResults.results.status = this.getTestStatus();
suiteResults.results.seleniumLog = this.seleniumLog;
suiteResults.results.host = this.host;
suiteResults.results.name = this.name;
suiteResults.results.tags = this.tags;

// Backwards compat
suiteResults.results.tests = this.testsCount;
Expand Down Expand Up @@ -295,7 +299,9 @@ module.exports = class Results {
retries: testcase.retriesCount,
skipped: 0,
tests: 0,
status: Results.TEST_PASS
status: Results.TEST_PASS,
startTimestamp: new Date().getTime(),
httpOutput: []
};

if (this.retryTest && this.testSections[testcase.testName]) {
Expand Down Expand Up @@ -433,6 +439,26 @@ module.exports = class Results {
return this;
}

setTestSectionElapsedTime() {
const currentSection = this.getTestSection(this.currentSectionName);
const startTime = currentSection ? currentSection.startTimestamp : this.globalStartTime;
const endTime = new Date().getTime();
const elapsedTime = endTime - startTime;
this.endTimestamp = endTime;

this.time += elapsedTime;

if (currentSection) {
currentSection.time = (elapsedTime/1000).toPrecision(4);
currentSection.timeMs = elapsedTime;
currentSection.startTimestamp = startTime;
currentSection.endTimestamp = endTime;

}

return this;
}

setTestStatus() {
const currentTest = this.getCurrentTest();
const currentSection = this.getTestSection(this.currentSectionName);
Expand All @@ -449,6 +475,15 @@ module.exports = class Results {
}
}

collectTestSectionOutput() {
const currentSection = this.getTestSection(this.currentSectionName);
if (!currentSection) {
return;
}

currentSection.httpOutput = Logger.collectTestSectionOutput();
}

setTotalElapsedTime() {
this.timeMs = this.time;
this.time = (this.time/1000).toPrecision(4);
Expand Down
22 changes: 17 additions & 5 deletions lib/testsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ class TestSuite {
reportPrefix: '',
reportFileName: this.argv['report-filename'],
groupName,
isMobile: this.client.api.isMobile()
isMobile: this.client.api.isMobile(),
tags: this.context.getTags()
}
});
}
Expand Down Expand Up @@ -460,7 +461,11 @@ class TestSuite {
await this.globalsInstance.runPluginHook(hookName, [this.settings]);
}

return this.globalHooks[hookName].run(this.client);
const result = await this.globalHooks[hookName].run(this.client);

this.onTestSectionFinished();

return result;
});
}

Expand Down Expand Up @@ -525,8 +530,8 @@ class TestSuite {
return this.startTestSuite()
.then(() => this.runHook('before'))
.then(result => {
this.reporter.setTestStatus();

this.onTestSectionFinished();
if (result instanceof Error) {
Logger.error(result);
}
Expand Down Expand Up @@ -564,6 +569,7 @@ class TestSuite {
if ((possibleError instanceof Error) && this.failFastMode) {
throw possibleError;
}
this.onTestSectionFinished();

return result;
});
Expand All @@ -575,6 +581,12 @@ class TestSuite {
.then((errorOrFailures) => this.onTestSuiteFinished(errorOrFailures));
}

onTestSectionFinished() {
this.reporter.setTestStatus();
this.reporter.setTestSectionElapsedTime();
this.reporter.collectTestSectionOutput();
}

onTestSuiteFinished(errorOrFailures = false) {
this.__snapShot = undefined;

Expand Down Expand Up @@ -786,7 +798,7 @@ class TestSuite {

testCaseFinished() {
this.reporter.setElapsedTime();
this.reporter.setTestStatus();
this.onTestSectionFinished();

if (!this.testcase) {
return Promise.resolve();
Expand Down
15 changes: 15 additions & 0 deletions lib/utils/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function logRequest(message, params) {
const instance = Logger.getInstance();

instance.output.push([timeIso, lodashEscape(message), lodashEscape(inspectObject(params))]);
instance.testSectionOutput.push([timeIso, lodashEscape(message), lodashEscape(inspectObject(params))]);
}

function logError(severity, errOrMessage, args) {
Expand All @@ -167,6 +168,7 @@ class Logger {
constructor() {
this.colors = colors;
this.output = [];
this.testSectionOutput = [];
}

logMessage(...args) {
Expand Down Expand Up @@ -447,3 +449,16 @@ module.exports.collectOutput = function() {

return output;
};

module.exports.collectTestSectionOutput = function() {
const instance = Logger.getInstance();

if (!instance) {
return [];
}

const {testSectionOutput} = instance;
instance.testSectionOutput = [];

return testSectionOutput;
};
20 changes: 14 additions & 6 deletions test/src/runner/testReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ describe('testReporter', function() {
assert.ok(Object.keys(module).includes('startTimestamp'));
assert.ok(Object.keys(module).includes('endTimestamp'));
assert.ok(Object.keys(module).includes('host'));
assert.ok(Object.keys(module).includes('name'));
assert.ok(Object.keys(module).includes('tags'));

// check for individual test properties
const test = module.completed['demoTest'];
assert.ok(Object.keys(test).includes('status'));
Expand Down Expand Up @@ -292,12 +295,17 @@ describe('testReporter', function() {

const completedSections = module['completedSections'];

// check for module properties
assert.ok(Object.keys(completedSections).includes('__after_hook'));
assert.ok(Object.keys(completedSections).includes('__before_hook'));
assert.ok(Object.keys(completedSections).includes('__global_afterEach_hook'));
assert.ok(Object.keys(completedSections).includes('__global_beforeEach_hook'));
assert.ok(Object.keys(completedSections).includes('demoTest'));
// check module properties all for hooks
const hooks = ['__after_hook', '__before_hook', '__global_afterEach_hook', '__global_beforeEach_hook', 'demoTest'];

hooks.forEach(hook => {
assert.ok(Object.keys(completedSections).includes(hook));

const sectionData = completedSections[hook];
assert.ok(Object.keys(sectionData).includes('startTimestamp'));
assert.ok(Object.keys(sectionData).includes('endTimestamp'));
assert.ok(Object.keys(sectionData).includes('httpOutput'));
});

assert.strictEqual(completedSections['__after_hook']['commands'].length, 1);
assert.strictEqual(completedSections['__after_hook']['commands'][0].name, 'end');
Expand Down

0 comments on commit 8707d52

Please sign in to comment.