Skip to content

Time taken showing incorrect after adding multiple testcases in same extent report using json #236

Open

Description

@testingGlobalIndia

private int currentScenarioNumber = 0;
private int currentScreenshotNumber = 0;
private ExtentTest currentTestReport;
private ExtentReports extentReports;
private string currentStep;

private void InitExtentReports()
{
try
{
if (extentReports == null)
{
// Initialize a new instance per test execution
string reportPath = GetExtentReportsPath();
string jsonPath = GetExtentJsonPath();

        // Ensure we don't delete existing reports on rerun
        if (!File.Exists(reportPath))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(reportPath));
        }

        var sparkReporter = new ExtentSparkReporter(GetExtentReportsPath());
        var jsonFormatter = new ExtentJsonFormatter(jsonPath);
        extentReports = new ExtentReports();
        // If JSON file exists, load previous data to avoid overwriting
        if (File.Exists(jsonPath))
        {
            extentReports.CreateDomainFromJsonArchive(jsonPath);
        }
        extentReports.AttachReporter(jsonFormatter, sparkReporter);
        // Add system information
        extentReports.AddSystemInfo("Machine Name", Environment.MachineName);
        extentReports.AddSystemInfo("Logged In User", Environment.UserName);
        extentReports.AddSystemInfo("Operating System", Environment.OSVersion.ToString());
        extentReports.AddSystemInfo("Domain", "CS");
        
    }
    // Start a new test
    if (currentTestReport == null)
    {
        currentTestReport = extentReports.CreateTest(TestContext.CurrentContext.Test.Name);
        currentTestReport.Model.Info.Add("Module Name", TestContext.CurrentContext.Test.FullName.Split('.')[2]);
    }
}
catch (System.Exception exception)
{
    currentTestReport = null;
}

}

zyx.json

Activity

  1. Thowk commented on Feb 26, 2026

    @Thowk

    I noticed the same issue. Log timestamp is not transferred properly from the source JSON.

    Quick fix is to take the TestEntityParser.cs and add one more line to the parser:

    if (log.Details != null)
    {
    extentTest.Log(log.Status, log.Details, m);
    }

    if (log.Details != null)
    {
        var testObj = extentTest.Log(log.Status, log.Details, media);
        testObj.Test.Logs.Last().Timestamp = log.Timestamp;    // <- this line will copy the original timestamp
    }
    

    The last one change is this replacement. Looks like they are interchangeable, but the latter one is public and the first protected.
    _extent.UsingNaturalConf = false;
    with
    _extent.UseNaturalTime = false;

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions