Skip to content

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

@testingGlobalIndia

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions