extentreports-csharp icon indicating copy to clipboard operation
extentreports-csharp copied to clipboard

Timestamp cannot be configured in ExtentSparkReporter

Open dcdraper opened this issue 1 year ago • 19 comments

I want to show seconds in the ExtentReport, but there is no "TimeStampFormat" option to configure that, even though the documentation and codebase (spark-config.json) indicates that it is possible:

Code running in Visual Studio image

[extentreports-csharp]/[config]/spark-config.json in GitHub image

ExtentReport image

dcdraper avatar Jan 10 '24 17:01 dcdraper

did you loader json config?


var yourConfigPath= Path.Combine(@"..\..\..\..\", @"config\spark-config.json");
            var spark = new ExtentSparkReporter("Spark.html");
            spark.LoadJSONConfig(yourConfigPath);

check please.

@dcdraper

namilkimfree avatar Jan 22 '24 09:01 namilkimfree

@namilkimfree Thank you for those instructions to load the config file. I successfully loaded and manipulated other settings via the spark-config.json file like theme, timelineEnabled, documentTitle and reportName. However the timestamps do not change regardless of what I change the format to in spark-config.json.

I want to change the timestamp format for each step of a test, underlined in my screenshot in my original post. We are not getting valuable data to see how many seconds it took to get to the next step, etc. Modifying the timeStampFormat in spark-config.json does not change the format anywhere at all on the report.

dcdraper avatar Jan 25 '24 18:01 dcdraper

@namilkimfree Thank you for those instructions to load the config file. I successfully loaded and manipulated other settings via the spark-config.json file like theme, timelineEnabled, documentTitle and reportName. However the timestamps do not change regardless of what I change the format to in spark-config.json.

I want to change the timestamp format for each step of a test, underlined in my screenshot in my original post. We are not getting valuable data to see how many seconds it took to get to the next step, etc. Modifying the timeStampFormat in spark-config.json does not change the format anywhere at all on the report.

The timeStamp property was not serialized and was not used anywhere in the extent report library, and I think it should be removed from the documentation.

There is a possibility of datetime conflict issues with the multicultural provider. For example, if my local instance culture is set to en-US, if I pass "dd/MM/yyyy hh:mm:ss" (31/1/2024), it won't work. This could be a reason it is not implemented, I guess.

sudheshg avatar Jan 31 '24 14:01 sudheshg

@sudheshg The seconds do display in other areas in that screenshot above. Perhaps, if not configurable, the steps could use that same format as is already used in those other places? Again we are missing valuable log information here and may need to add our own timestamp each time we write to the log, which defeats the purpose a little of having a reporter like ExtentReports. 😁

dcdraper avatar Jan 31 '24 15:01 dcdraper

@sudheshg The seconds do display in other areas in that screenshot above. Perhaps, if not configurable, the steps could use that same format as is already used in those other places? Again we are missing valuable log information here and may need to add our own timestamp each time we write to the log, which defeats the purpose a little of having a reporter like ExtentReports. 😁

Then need to pass the expected TimeZone info in the config file to match the timeStampformat.

sudheshg avatar Feb 01 '24 10:02 sudheshg

@sudheshg Then need to pass the expected TimeZone info in the config file to match the timeStampformat.

I do not know what this means. There is no timezone option in the config file.

dcdraper avatar Feb 02 '24 20:02 dcdraper

I have the same problem, I'm on a French machine, and I don't have the seconds displayed.

I tested with the json configuration but it doesn't change anything, and no possibility in C#.

Is there a solution ?

image

SerreauFrederic avatar Mar 19 '24 16:03 SerreauFrederic

As we are using the same report in different time zones the report shows different time formats according to the user system time format . We need to set a specific time format , I tried using json-config but there is no change. This issue is of high importance , could you please resolve this and give us an option to set format.

sharon-sharonmuffins avatar Mar 21 '24 05:03 sharon-sharonmuffins

For workaround the issue, I did this solution :

I set my date in the details log with a separator (for example : TIME )

string myText = "my log line";
myText = $"{DateTime.Now:HH:mm:ss}_TIME_{myText}";

Test.Log(status, myText , media); // Test is ExtentTest object, media is optionnal

in config of ExtentSparkReporter, I set a json script like this :

ExtentSparkReporter extentSparkReporter = new ExtentSparkReporter(path);

extentSparkReporter.Config.JS = @"
                        var elements = document.getElementsByClassName('event-row')

                        for (let i = 0; i < elements.length; i++) {
                            var cellules = elements[i].getElementsByTagName('td');
                            var split = cellules[2].innerHTML.split('_TIME_');
                            var timestamp = split[0].replace('\n', '');
                            cellules[1].innerHTML = timestamp;
                            cellules[2].innerHTML = split[1];    
                        }";

at the end, my timestamp has seconds :)

image

SerreauFrederic avatar Mar 21 '24 12:03 SerreauFrederic

Thank you for the work around , the issue I am facing right now is In my report generated I see that it is picking up the date time of the system time I need to fix the time stamp which should not change with Time zone change ReportImage Please help me fix the time stamp to be consistent across all timezones

sharon-sharonmuffins avatar Mar 21 '24 18:03 sharon-sharonmuffins

You can use DateTime.UtcNow

SerreauFrederic avatar Mar 21 '24 19:03 SerreauFrederic

@dcdraper ExtentReports/Views/Spark/Partials/Log.cshtml at line19 The TimeStamp value is hardcoded as a short. In order to modify it, you need to read the config value and format it.

namilkimfree avatar Apr 16 '24 09:04 namilkimfree

@namilkimfree Thanks for responding again, but I do not have any idea how I can read or format it. There is no config option for Timestamp. Have you done this? Do you have an example or sample code?

dcdraper avatar Apr 16 '24 19:04 dcdraper

Sorry for the delay, currently looking into this.

anshooarora avatar Apr 25 '24 23:04 anshooarora

The fix in this branch fixes the issue. There are several fixes made to the template due to which, I will need to do further testing + write tests as necessary.

anshooarora avatar Apr 26 '24 18:04 anshooarora

@anshooarora Thank you for working on this! I was curious so I tried the fix branch today, and it is giving me what we desperately needed.

I did notice a couple things I did not quite expect...

  1. Removing the date part of the format also removes it from the header, which does not matter to me but seems different than how it used to work. If you look at my original screenshot you can see the header has the date part but the Timestamp column does not: image

  2. Using the date part adds it back to the header but makes the Timestamp too long to fit on one line; the report does not auto-adjust for that: image

dcdraper avatar May 10 '24 17:05 dcdraper

Thanks, this is also fixed. I will prepare for release next.

PS. this fix should also improve performance slightly.

(Sorry for the delay in this, I did not have a Windows machine (until now) and doing all this on a mac was quite painful)

anshooarora avatar Jun 14 '24 14:06 anshooarora

Is still is not fixed in v5.0.4. It does not matter which format I use, it always displays datetime in this format: image I want report to display datetime in this format (changed from devtools): image

smestvirishvili avatar Jun 28 '24 11:06 smestvirishvili

@smestvirishvili - it should change the event timestamp, please see the original post for context.

anshooarora avatar Jun 28 '24 13:06 anshooarora