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

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

Open testingGlobalIndia opened this issue 8 months ago • 0 comments

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

testingGlobalIndia avatar Feb 25 '25 07:02 testingGlobalIndia