New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Projects
None yet
3 participants
@MohabMohie
Contributor

MohabMohie commented Aug 3, 2017

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 from Dashboard End time-stamp is not set correctly (takes the end date of the first test) to Dashboard End time-stamp is not set correctly, takes the end date of the first test. [TestNG IReporter] Aug 3, 2017

@MohabMohie

This comment has been minimized.

Show comment
Hide comment
@MohabMohie

MohabMohie Aug 3, 2017

Contributor

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

Contributor

MohabMohie commented Aug 3, 2017

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

@anshooarora

This comment has been minimized.

Show comment
Hide comment
@anshooarora

anshooarora Aug 3, 2017

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.

Owner

anshooarora commented Aug 3, 2017

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

Fixed issue #926
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

This comment has been minimized.

Show comment
Hide comment
@MohabMohie

MohabMohie Aug 7, 2017

Contributor

@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.

Contributor

MohabMohie commented Aug 7, 2017

@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.

@anshooarora anshooarora closed this Aug 9, 2017

@robertoalfonso

This comment has been minimized.

Show comment
Hide comment
@robertoalfonso

robertoalfonso Aug 10, 2017

@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 ?

robertoalfonso commented Aug 10, 2017

@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 join this conversation on GitHub. Already have an account? Sign in to comment