Repository: nightwatchjs/nightwatch
Pull request #3502 (2022-11-30 04:45:12)

Added host, buildtime to reporter
Added Host, buildtime and timestamps to reporter. (https://github.com/nightwatchjs/nightwatch/pull/3494)


Patch:
diff --git a/lib/reporter/global-reporter.js b/lib/reporter/global-reporter.js
index 3dd974fe..2fa5ec98 100644
--- a/lib/reporter/global-reporter.js
+++ b/lib/reporter/global-reporter.js
@@ -23,7 +23,10 @@ module.exports = class GlobalReporter {
       assertions: 0,
       errmessages: [],
       modules: {},
-      modulesWithEnv: {}
+      modulesWithEnv: {},
+      elapsedTime: 0,
+      startTimestamp: null,
+      endTimestamp: null
     };
   }
 
@@ -92,8 +95,13 @@ module.exports = class GlobalReporter {
       initialReport.errmessages.push(errorMessage);
     }
 
-    this.elapsedTime = new Date().getTime() - startTime;
+    const endTime = new Date().getTime();
+    this.elapsedTime = endTime - startTime;
+    
     this.globalResults = Results.createGlobalReport(this.suiteResults, initialReport);
+    this.globalResults.elapsedTime = (this.elapsedTime/1000).toPrecision(4);
+    this.globalResults.startTimestamp = new Date(startTime).toUTCString();
+    this.globalResults.endTimestamp = new Date(endTime).toUTCString();
 
     return this;
   }
diff --git a/lib/reporter/results.js b/lib/reporter/results.js
index 6d085e8f..96771684 100644
--- a/lib/reporter/results.js
+++ b/lib/reporter/results.js
@@ -46,6 +46,8 @@ module.exports = class Results {
     this.sessionId = '';
     this.projectName = capabilities.projectName || desiredCapabilities.projectName || '';
     this.buildName = capabilities.buildName || desiredCapabilities.buildName || '';
+    const {webdriver = {}} = settings;
+    this.host = webdriver.host || '';
 
     this.initCount(tests);
   }
@@ -232,7 +234,8 @@ module.exports = class Results {
     suiteResults.results.isMobile = this.isMobile;
     suiteResults.results.status = this.getTestStatus();
     suiteResults.results.seleniumLog = this.seleniumLog;
-    
+    suiteResults.results.host = this.host;
+
     // Backwards compat
     suiteResults.results.tests = this.testsCount;
     suiteResults.results.failures = this.failedCount;


Test patch:
diff --git a/test/src/runner/testReporter.js b/test/src/runner/testReporter.js
index f5d35a2a..e0627fb2 100644
--- a/test/src/runner/testReporter.js
+++ b/test/src/runner/testReporter.js
@@ -237,6 +237,11 @@ describe('testReporter', function() {
           waitForConditionTimeout: 50,
           retryAssertionTimeout: 50,
           reporter: function (results) {
+            // check for results properties
+            assert.ok(Object.keys(results).includes('elapsedTime'));
+            assert.ok(Object.keys(results).includes('startTimestamp'));
+            assert.ok(Object.keys(results).includes('endTimestamp'));
+
             const module = results.modules['sample'];
             // check for module properties
             assert.ok(Object.keys(module).includes('sessionCapabilities'));
@@ -245,6 +250,7 @@ describe('testReporter', function() {
             assert.ok(Object.keys(module).includes('buildName'));
             assert.ok(Object.keys(module).includes('startTimestamp'));
             assert.ok(Object.keys(module).includes('endTimestamp'));
+            assert.ok(Object.keys(module).includes('host'));
             // check for individual test properties
             const test = module.completed['demoTest'];
             assert.ok(Object.keys(test).includes('status'));