anshooarora / extentreports-java

Community version of Extent API for Java has moved to https://github.com/extent-framework/
http://extentreports.com
Other
528 stars 318 forks source link

Tests page Timestamp for each test is incorrect #993

Open carlc986 opened 7 years ago

carlc986 commented 7 years ago

Summary

The Timestamp value for each test on the Tests page is the Suite End Time, not the Test End time

Expected Behavior

The Timestamp value for each test should either be the Test Start Time or the Test End time, but neither is used. It appears that the Suite End time is used by mistake so all the tests listed on the page have the same Timestamp value.

Current Behavior

The Timestamp value for each test should either be the Test Start Time or the Test End time, but neither is used. It appears that the Suite End time is used by mistake so all the tests listed on the page have the same Timestamp value.

Sample

// Sample code goes here

Environment Details

Screenshots

carlc986 commented 7 years ago

extentreports_993

carlc986 commented 7 years ago

extentreports_993_2

anshooarora commented 7 years ago

Are you using a TestNG listener which builds the report after all tests have run? Are you using setUsesManualCondiguration?

carlc986 commented 7 years ago
  1. no, I am using an IReporter class to build the report, and the sample IReporter code on the wiki also has the same problem. We used this format with ExtentReports 2.4.2 and it always worked fine, nothing has changed with it.
  2. Whether I set setUsesManualConfiguration to true or false doesn't seem to matter either, same result with the Timestamp field.
anshooarora commented 7 years ago

Can you share the listener code?

anshooarora commented 7 years ago

Can you also share the setup code for ExtentReports?

anshooarora commented 7 years ago

I am a little confused. Are you using IReporter or ITestListener hook?

carlc986 commented 7 years ago

It looks like IReporter, but I add some data from my ITestListener as well, but that should not affect the Timestamp

anshooarora commented 7 years ago

Ff you are using IReporter, uncomment this line:

extent.setReportUsesManualConfiguration(true);

Also, I do not see where you are setting the timestamps for tests. When running using the IReporter listener, tests are created at the very end so the API does not know when they were really started and ended.

See here for example: http://extentreports.com/docs/versions/3/java/#testng-ireporter. You are missing this:

test.getModel().setStartTime(getTime(result.getStartMillis()));
test.getModel().setEndTime(getTime(result.getEndMillis()));
carlc986 commented 7 years ago

Hi Anshoora, I have been using the call to extent.setReportUsesManualConfiguration(true);, this is what is reporting the incorrect Timestamps. As far as setting the start and end times, I am doing that already, I didn't send you that part of the code. But, even when I use the sample code you have on your site, those values are incorrect. Let me include that code and the report screenshot here.

carlc986 commented 7 years ago

Here is your sample IReporter code on your site, please note, I fixed 2 issues with the parameters and map, they are commented out:

public class ExtentIReporter_sample implements IReporter {

private static final String OUTPUT_FOLDER = "test-output/Reports/";
private static final String FILE_NAME = "ExtentIReporter_sample.html";

private ExtentReports extent;

@Override
//public void generateReport(List xmlSuites, List suites, String outputDirectory) {
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
    init();

    for ( ISuite suite : suites ) {
        //Map result = suite.getResults();
        Map<String, ISuiteResult> result = suite.getResults();

        for (ISuiteResult r : result.values()) {
            ITestContext context = r.getTestContext();

            buildTestNodes(context.getFailedTests(), Status.FAIL);
            buildTestNodes(context.getSkippedTests(), Status.SKIP);
            buildTestNodes(context.getPassedTests(), Status.PASS);

        }
    }

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

    extent.flush();
}

private void init() {
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(OUTPUT_FOLDER + FILE_NAME);
    htmlReporter.config().setDocumentTitle("ExtentReports - Created by TestNG Listener");
    htmlReporter.config().setReportName("ExtentReports - Created by TestNG Listener");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
    htmlReporter.config().setTheme(Theme.STANDARD);

    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    extent.setReportUsesManualConfiguration(true);
}

private void buildTestNodes(IResultMap tests, Status status) {
    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");
            }

            test.getModel().setStartTime(getTime(result.getStartMillis()));
            test.getModel().setEndTime(getTime(result.getEndMillis()));
        }
    }
}

private Date getTime(long millis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(millis);
    return calendar.getTime();
}
carlc986 commented 7 years ago

screen shot 2017-12-01 at 6 49 35 am

anshooarora commented 7 years ago

Can you create a project and share the link? I will check.

carlc986 commented 7 years ago

Are you asking me to create a github project? That would take some time. Are you not seeing this in your reports?

anshooarora commented 6 years ago

I am unable to reproduce.

Here is the test: https://github.com/anshooarora/extentreports-java/blob/master/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsIReporter.java

It generates the correct timestamps for each test in my case.

carlc986 commented 6 years ago

I believe you have to build it as an IReporter to see the problem, as it builds the entire report at the end. Where do you get the value for the field "Timestamp"? When running as an IReporter, it takes the value for the Suite End Time and use it for the Timestamp field in each test case, so they are all the same. The Test Start and End times are correct, its the Timestamp field that's gets logged with the status that is incorrect.

carlc986 commented 6 years ago

I need to remove some of the bitmaps and the sample code I added, as I see some co. info displayed in it. I can provide a sample script and reporter class if you want to run that which doesn't include RSA, etc...

carlc986 commented 6 years ago

ExtentReports.zip

carlc986 commented 6 years ago

Hi Anshoo, I created a sample file set to show you the issue. I uploaded it as a .zip file. Just unzip and drop the 5 files into a test folder in your IDE, and create a test-output folder for the report to go in. (or wherever you want it to go).

  1. Drop the files into 1 folder
  2. Create a test-output folder for the report
  3. Run the GetEmployees.xml file, the ExtentIReporter_sample entry is in the xml file.
  4. The sample report is from your wiki page
  5. Notice the Suite End Time is used as the "Timestamp" fields for each test in the report, but the Start and End Time are correct.
carlc986 commented 6 years ago

screen shot 2018-01-04 at 3 53 21 pm screen shot 2018-01-04 at 3 52 41 pm

carlc986 commented 6 years ago

Hi Anshoo, I didn't close this defect myself, the system closed it when I added the sample project .zip file. Can you or did you try to run ti to view the Timestamp problem? Thanks.

anshooarora commented 6 years ago

I ran your suite, and here are my findings:

Tests:

test1: Feb 12, 2018 11:40:36 PM, Feb 12, 2018 11:40:46 PM, 0h 0m 10s+14ms test2: Feb 12, 2018 11:40:26 PM, Feb 12, 2018 11:40:36 PM, 0h 0m 10s+5ms test3: Feb 12, 2018 11:40:56 PM, Feb 12, 2018 11:41:06 PM, 0h 0m 10s+5ms test4: Feb 12, 2018 11:40:46 PM, Feb 12, 2018 11:40:56 PM, 0h 0m 10s+10ms test5: Feb 12, 2018 11:40:16 PM, Feb 12, 2018 11:40:26 PM, 0h 0m 10s+2ms test6: Feb 12, 2018 11:41:06 PM, Feb 12, 2018 11:41:16 PM, 0h 0m 10s+5ms test7: Feb 12, 2018 11:40:06 PM, Feb 12, 2018 11:40:16 PM, 0h 0m 10s+13ms

Dashboard:

Start: Feb 12, 2018 11:40:06 PM End: Feb 12, 2018 11:41:17 PM Time Taken: 0h 1m 10s+650ms

It looks correct to me..

carlc986 commented 6 years ago

What is the "Timestamp" value for all the tests, that's where the issue is, not the Start and End times. The files I sent you does show the problem. You're not looking at the right field it's in the "test-steps" Timestamp field.