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

End time on tests not being set correctly - total time taken incorrect #815

Closed
TinyCamera opened this Issue Mar 20, 2017 · 13 comments

Comments

Projects
None yet
5 participants
@TinyCamera

TinyCamera commented Mar 20, 2017

I am seeing this issue on 3.0.0 and 3.0.3.

I am parsing an XML test report and generating an Extent Report. I parse the start and end time of each test use them to set the start and end time of each Extent Report explicitly.

In the Extent report, the start time is displayed correctly but the end time is being set to the time the report is generated(not the end time explicitly set). This gives each test a massively inflated incorrect execution time.

I can gaurentee the start and end time are in the same format and being parsed correctly.

screen shot 2017-03-20 at 11 10 02 am

Heres the code for generating the report.


import java.util.List;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;


public class ExtentReoprtGenerator {
	String outputFile; 
	XmlReport report;
	ExtentReports extentReport;

	public ExtentReoprtGenerator(String _outputFile, XmlReport _report){

		outputFile = _outputFile;
		report = _report;

		ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(outputFile);
		extentReport = new ExtentReports();
		extentReport.attachReporter(htmlReporter);
	}

	public void generate(){
		System.out.println(String.format("Generating Extent report %s", outputFile));
		addTests();
		extentReport.flush();
	}

	private void addTests(){
		for(XmlTest test: report.getTests()){
			ExtentTest extentTest = extentReport.createTest(test.getTestName());

			addSteps(extentTest, test.getTestSteps());
			
			if(test.getStartTime()!=null){
				extentTest.getModel().setStartTime(test.getStartTime());
				extentTest.getModel().setEndTime(test.getEndTime());
			}else{
				extentTest.getModel().setStartTime(report.getRunDate());
				extentTest.getModel().setEndTime(report.getRunDate());
			}
		}
	}

	private void addSteps(ExtentTest test, List<Step> steps){
		if (steps.isEmpty()){
			test.log(Status.SKIP, "Not tests steps run");
		}
		for(Step step: steps){
			switch (step.getLogStatus()) {
			case FAIL:
				test.fail(step.getName() +"<br>"+ step.getMessage());
				break;
			case PASS:
				test.pass(step.getName() +"<br>"+ step.getMessage());
				break;

			default:
				break;
			}
		}
	}
}
@anshooarora

This comment has been minimized.

Show comment
Hide comment
@anshooarora

anshooarora Mar 20, 2017

Owner

This should fix it:

extentReport.setReportUsesManualConfiguration(true);

Example: http://extentreports.com/docs/versions/3/java/#testng-ireporter

Owner

anshooarora commented Mar 20, 2017

This should fix it:

extentReport.setReportUsesManualConfiguration(true);

Example: http://extentreports.com/docs/versions/3/java/#testng-ireporter

@TinyCamera

This comment has been minimized.

Show comment
Hide comment
@TinyCamera

TinyCamera Mar 20, 2017

Thanks for the reply anshooaroa. I actually fixed part of the problem by setting the timestep of each step explicitly.

test.getModel().getLogContext().get(stepNum++).setTimestamp(step.getEndTime());

After that, the times displayed for tests were accurate. However, the report is still showing incorrect end time and because of this, a massive incorrect duration.

screen shot 2017-03-21 at 9 14 09 am

This is the case with and without setReportUsesManualConfiguration(true);

TinyCamera commented Mar 20, 2017

Thanks for the reply anshooaroa. I actually fixed part of the problem by setting the timestep of each step explicitly.

test.getModel().getLogContext().get(stepNum++).setTimestamp(step.getEndTime());

After that, the times displayed for tests were accurate. However, the report is still showing incorrect end time and because of this, a massive incorrect duration.

screen shot 2017-03-21 at 9 14 09 am

This is the case with and without setReportUsesManualConfiguration(true);

@anshooarora anshooarora reopened this Mar 21, 2017

@anshooarora

This comment has been minimized.

Show comment
Hide comment
@anshooarora
Owner

anshooarora commented Mar 22, 2017

@TinyCamera

This comment has been minimized.

Show comment
Hide comment
@TinyCamera

TinyCamera Mar 23, 2017

Hey again anshooarora, thanks for reopening.

I am seeing the same issue present with testng-ireporter.

Here is a very simple example that you can run that should expose the issue I am seeing.


public class ExtentBroke {
	String outputFile; 
	XmlReport report;
	ExtentReports extentReport;
	static Date startDate;
	static Date endDate;
	public static void main(String args[]){

		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, -6);   
		startDate = cal.getTime();
		cal.add(Calendar.HOUR,1);
		endDate = cal.getTime();
		
		ExtentBroke broke = new ExtentBroke("tosca.html");
		broke.generate();
	}

	public ExtentBroke(String _outputFile){

		outputFile = _outputFile;

		ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(outputFile);
		htmlReporter.config().setDocumentTitle("ExtentReports - Created by TestNG Listener");
		htmlReporter.config().setReportName("ExtentReports - Created by TestNG Listener");
		htmlReporter.config().setTheme(Theme.STANDARD);
		extentReport = new ExtentReports();
		extentReport.attachReporter(htmlReporter);
		extentReport.setReportUsesManualConfiguration(true);
	}

	public void generate(){
		System.out.println(String.format("Generating Extent report %s", outputFile));
		addTests();
		extentReport.flush();
	}

	private void addTests(){
		ExtentTest extentTest = extentReport.createTest("Test from 6 months ago");

		extentTest.getModel().setStartTime(startDate);
		extentTest.getModel().setEndTime(endDate);


	}

}

This adds a single test to the report with a timestamp from 6 months ago. The total execution time is 6 months as the start date of the report is the start date of the first tests and the end date is time the report is run. Please let me know if you can recreate the issue.

TinyCamera commented Mar 23, 2017

Hey again anshooarora, thanks for reopening.

I am seeing the same issue present with testng-ireporter.

Here is a very simple example that you can run that should expose the issue I am seeing.


public class ExtentBroke {
	String outputFile; 
	XmlReport report;
	ExtentReports extentReport;
	static Date startDate;
	static Date endDate;
	public static void main(String args[]){

		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.MONTH, -6);   
		startDate = cal.getTime();
		cal.add(Calendar.HOUR,1);
		endDate = cal.getTime();
		
		ExtentBroke broke = new ExtentBroke("tosca.html");
		broke.generate();
	}

	public ExtentBroke(String _outputFile){

		outputFile = _outputFile;

		ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(outputFile);
		htmlReporter.config().setDocumentTitle("ExtentReports - Created by TestNG Listener");
		htmlReporter.config().setReportName("ExtentReports - Created by TestNG Listener");
		htmlReporter.config().setTheme(Theme.STANDARD);
		extentReport = new ExtentReports();
		extentReport.attachReporter(htmlReporter);
		extentReport.setReportUsesManualConfiguration(true);
	}

	public void generate(){
		System.out.println(String.format("Generating Extent report %s", outputFile));
		addTests();
		extentReport.flush();
	}

	private void addTests(){
		ExtentTest extentTest = extentReport.createTest("Test from 6 months ago");

		extentTest.getModel().setStartTime(startDate);
		extentTest.getModel().setEndTime(endDate);


	}

}

This adds a single test to the report with a timestamp from 6 months ago. The total execution time is 6 months as the start date of the report is the start date of the first tests and the end date is time the report is run. Please let me know if you can recreate the issue.

@anshooarora anshooarora added the bug label Mar 23, 2017

@anshooarora

This comment has been minimized.

Show comment
Hide comment
@anshooarora

anshooarora Mar 23, 2017

Owner

Thanks for the great sample and the creative class name.

I have fixed this - will be part of the next release.

Owner

anshooarora commented Mar 23, 2017

Thanks for the great sample and the creative class name.

I have fixed this - will be part of the next release.

@Priyamalatesh

This comment has been minimized.

Show comment
Hide comment
@Priyamalatesh

Priyamalatesh Sep 22, 2017

Hi anshoo,

I am using the extent report version 3 for reports.

But my report does not display the time properly.

Sep 22, 2017 11:16:28 AM Sep 22, 2017 11:16:28 AM 0h 0m 0s+0ms .

please help me.

Priyamalatesh commented Sep 22, 2017

Hi anshoo,

I am using the extent report version 3 for reports.

But my report does not display the time properly.

Sep 22, 2017 11:16:28 AM Sep 22, 2017 11:16:28 AM 0h 0m 0s+0ms .

please help me.

@anshooarora

This comment has been minimized.

Show comment
Hide comment
@anshooarora

anshooarora Sep 22, 2017

Owner

Are you using 3.0.7?

Owner

anshooarora commented Sep 22, 2017

Are you using 3.0.7?

@sumeet-srknec

This comment has been minimized.

Show comment
Hide comment
@sumeet-srknec

sumeet-srknec Oct 2, 2017

Hi Anshoo,

Is this issue mentioned by @TinyCamera fixed? Adding a part of comment here for context.
"However, the report is still showing incorrect end time and because of this, a massive incorrect duration."

I am using extentreports-3.0.7 build and noticing incorrect end-time for the report.

Thanks,
Sumeet

sumeet-srknec commented Oct 2, 2017

Hi Anshoo,

Is this issue mentioned by @TinyCamera fixed? Adding a part of comment here for context.
"However, the report is still showing incorrect end time and because of this, a massive incorrect duration."

I am using extentreports-3.0.7 build and noticing incorrect end-time for the report.

Thanks,
Sumeet

@Priyamalatesh

This comment has been minimized.

Show comment
Hide comment
@Priyamalatesh

Priyamalatesh Oct 3, 2017

Hi Anshoo,

I am using 3.0.6 version of extent report

Priyamalatesh commented Oct 3, 2017

Hi Anshoo,

I am using 3.0.6 version of extent report

@AnushaGovindan

This comment has been minimized.

Show comment
Hide comment
@AnushaGovindan

AnushaGovindan Oct 30, 2017

Hi Anshoo,

I'm facing the same issue (incorrect end time and duration) with 3.0.7v. Could you please advise ?

capture

Thanks.

AnushaGovindan commented Oct 30, 2017

Hi Anshoo,

I'm facing the same issue (incorrect end time and duration) with 3.0.7v. Could you please advise ?

capture

Thanks.

@AnushaGovindan

This comment has been minimized.

Show comment
Hide comment
@AnushaGovindan

AnushaGovindan Nov 3, 2017

Hi Anshoo,

Any update?
I wrote a simple test with no logic and just thread wait time to show the issue. In the below screenshot, I have highlighted the durations and timestamp in test steps. If you notice, duration for individual test is updated correctly whereas the overall duration of whole test suite is not right.
Could you please take a look? I'm using 3.0.7v.

extrpt_start_end_time_issue

Thanks.

AnushaGovindan commented Nov 3, 2017

Hi Anshoo,

Any update?
I wrote a simple test with no logic and just thread wait time to show the issue. In the below screenshot, I have highlighted the durations and timestamp in test steps. If you notice, duration for individual test is updated correctly whereas the overall duration of whole test suite is not right.
Could you please take a look? I'm using 3.0.7v.

extrpt_start_end_time_issue

Thanks.

@anshooarora

This comment has been minimized.

Show comment
Hide comment
@anshooarora

anshooarora Nov 3, 2017

Owner

Your case is different from the issue reported in this ticket. Please open a new ticket and share steps to repro.

Owner

anshooarora commented Nov 3, 2017

Your case is different from the issue reported in this ticket. Please open a new ticket and share steps to repro.

@AnushaGovindan

This comment has been minimized.

Show comment
Hide comment
@AnushaGovindan

AnushaGovindan Nov 3, 2017

Done !! Here is the new issue:

Extent Reports 3.0.7v : End time and Duration of overall test is incorrect #978

AnushaGovindan commented Nov 3, 2017

Done !! Here is the new issue:

Extent Reports 3.0.7v : End time and Duration of overall test is incorrect #978

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment