extent-framework / extentreports-csharp

Extent Reporting Library, .NET
http://extentreports.com
Apache License 2.0
49 stars 40 forks source link

Timestamp cannot be configured in ExtentSparkReporter #206

Open dcdraper opened 5 months ago

dcdraper commented 5 months ago

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

namilkimfree commented 5 months ago

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

dcdraper commented 5 months ago

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

sudheshg commented 5 months ago

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

dcdraper commented 5 months ago

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

sudheshg commented 5 months ago

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

dcdraper commented 5 months ago

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

SerreauFrederic commented 3 months ago

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

sharon-sharonmuffins commented 3 months ago

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.

SerreauFrederic commented 3 months ago

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

sharon-sharonmuffins commented 3 months ago

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

SerreauFrederic commented 3 months ago

You can use DateTime.UtcNow

namilkimfree commented 2 months ago

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

dcdraper commented 2 months ago

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

anshooarora commented 2 months ago

Sorry for the delay, currently looking into this.

anshooarora commented 2 months ago

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.

dcdraper commented 1 month ago

@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

anshooarora commented 3 weeks ago

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)

smestvirishvili commented 1 week ago

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

anshooarora commented 1 week ago

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