Open carlc986 opened 7 years ago
Are you using a TestNG listener which builds the report after all tests have run? Are you using setUsesManualCondiguration?
Can you share the listener code?
Can you also share the setup code for ExtentReports?
I am a little confused. Are you using IReporter or ITestListener hook?
It looks like IReporter, but I add some data from my ITestListener as well, but that should not affect the Timestamp
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()));
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.
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();
}
Can you create a project and share the link? I will check.
Are you asking me to create a github project? That would take some time. Are you not seeing this in your reports?
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.
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.
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...
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).
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.
I ran your suite, and here are my findings:
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
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..
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.
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
Environment Details
Screenshots