Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Dashboard End time-stamp is not set correctly, takes the end date of the first test. [TestNG IReporter] #926

Closed
MohabMohie opened this issue Aug 3, 2017 · 4 comments

Comments

@MohabMohie
Copy link
Contributor

Summary

Dashboard End time-stamp is not set correctly (takes the end date of the first test).

As you can see from the three screenshots below, the time-stamp is correct for the start date but not the end date

dashboard:
test111
first test:
2
second test:
3

Expected Behavior

It should take the smallest start time of all the tests, and the largest end time of all the tests

Current Behavior

It takes the smallest start time of all the tests. and the smallest end time of all the tests

I believe that this should be "less than" not "greater than"
4

Sample

I'm using the TestNG IReporter with setReportUsesManualConfiguration(true);

There was also a problem with the test time stamp, as it should be the end time stamp for that test, yet it was something else... I fixed it by manually overriding the end time stamp for each step.

package io;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.testng.IReporter;
import org.testng.IResultMap;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.Reporter;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class ExtentTestNGITestListener implements IReporter {

	private static final String OUTPUT_FOLDER = "target/surefire-reports/html/";
	private static final String FILE_NAME = "index.html";

	private ExtentReports extent;

	@SuppressWarnings("rawtypes")
	@Override
	public void generateReport(List xmlSuites, List suites, String outputDirectory) {
		init();

		for (String s : Reporter.getOutput()) {
			extent.setTestRunnerOutput(s);
		}

		for (Object suite : suites.toArray()) {
			
			
			Map result = ((ISuite) suite).getResults();
			int testNumber=0;
			for (Object r : result.values()) {
				ITestContext context = ((ISuiteResult) r).getTestContext();
				buildTestNodes(context.getFailedTests(), Status.FAIL, testNumber);
				buildTestNodes(context.getSkippedTests(), Status.SKIP, testNumber);
				buildTestNodes(context.getPassedTests(), Status.PASS, testNumber);
				testNumber++;
			}
		}

		//extent.flush();
		// Open and Archive report
		ReportManager.archiveReport();
		ReportManager.openReport();
	}

	private void init() {
		ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
		htmlReporter.config().setDocumentTitle("SHAFT ExtentReport");
		htmlReporter.config().setReportName("SHAFT ExtentReport - Created by Mohab Mohie @Systematic Computer Science");
		htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
		htmlReporter.config().setTheme(Theme.STANDARD);
		htmlReporter.config().setTimeStampFormat("dd/MM/yyyy hh:mm:ss a");

		extent = new ExtentReports();
		extent.attachReporter(htmlReporter);
		extent.setReportUsesManualConfiguration(true);
		//set execution start time
		extent.flush();
	}

	private void buildTestNodes(IResultMap tests, Status status, int testNumber) {
		ExtentTest test;

		if (tests.size() > 0) {
			for (ITestResult result : tests.getAllResults()) {
				test = extent.createTest(result.getMethod().getMethodName());

				for (String group : result.getMethod().getGroups())
					test.assignCategory(group);

				if (result.getThrowable() != null) {
					test.log(status, result.getThrowable());
				} else {
					test.log(status, "Test " + status.toString().toLowerCase() + "ed");
				}
				Reporter.clear();
				test.getModel().setStartTime(getTime(result.getStartMillis()));
				test.getModel().setEndTime(getTime(result.getEndMillis()));
				test.getModel().getLogContext().get(testNumber).setTimestamp(getTime(result.getEndMillis()));
				//set and update execution end time
				extent.flush();
			}		
		}
	}

	private Date getTime(long millis) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(millis);
		return calendar.getTime();
	}
}

Environment Details

  • Extent report Version used: 3.0.6 community
  • Operating System and version: Windows 10 64-bit
  • JDK Version: 8, java version "1.8.0_131"
@MohabMohie MohabMohie changed the title Dashboard End time-stamp is not set correctly (takes the end date of the first test) Dashboard End time-stamp is not set correctly, takes the end date of the first test. [TestNG IReporter] Aug 3, 2017
@MohabMohie
Copy link
Contributor Author

@anshooarora If you'll allow me I can go fix it myself if you don't have time.

@anshooarora
Copy link
Owner

I believe that this should be "less than" not "greater than"

That's correct, thanks for finding this issue. Please feel free to send in a pull request. I will merge.

MohabMohie added a commit to MohabMohie/extentreports-java that referenced this issue Aug 6, 2017
Dashboard End time-stamp is not set correctly (takes the end date of the first test).
anshooarora#926
anshooarora added a commit that referenced this issue Aug 6, 2017
@MohabMohie
Copy link
Contributor Author

@anshooarora , my apologies if i'm being pushy on this... but can you please let me know when you'll be able to release this hotfix on Maven? it's really critical and it has a breaking effect on anyone using the listener's reports.

@robertoalfonso
Copy link

@MohabMohie On extent.setReportUsesManualConfiguration(true); //set execution start time extent.flush(); and
test.getModel().getLogContext().get(testNumber).setTimestamp(getTime(result.getEndMillis())); //set and update execution end time extent.flush();
How would you set execution start time and set and update execution end time ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants