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

MergeReport - Exception at CreateDomainFromJsonArchive

Open saravanakumar-nc opened this issue 1 year ago • 1 comments

Hi,

I have multiple json file that needs to be merged to generate one final html report file.

Lets say I have 15 files. Some of the files are being merged but some getting these errors. This is my code to merge the report. I even have the retry mechanism with delay, still I am getting the error.

// Initialize ExtentReports
var extent = new ExtentReports();

// Find all JSON files in the test results directory
var jsonFiles = Directory.GetFiles(testResultsDir, "*.json", SearchOption.AllDirectories);

if (jsonFiles.Length == 0)
{
    Console.WriteLine("No JSON report files found in the specified directory.");
    return;
}

Console.WriteLine("JSON files :- "+ Environment.NewLine + String.Join(Environment.NewLine, jsonFiles));

int i = 0;
foreach (var jsonFile in jsonFiles)
{
    int retry = 0;
    bool isFileAttached = false;
    Console.WriteLine("Attaching File-" + ++i + ": " + jsonFile);
    while (!isFileAttached && retry < 5)
    {
        try
        {
            extent.CreateDomainFromJsonArchive(jsonFile);
            isFileAttached = true;
            break;
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception while Attaching File-" + i + ": " + jsonFile);
            Console.WriteLine(e.Message + ": " + e.StackTrace);
            Thread.Sleep(1000);
            Console.WriteLine("Re-try attempt [" + ++retry + "] to attach the File-" + i + ": " + jsonFile);
        }
    }
}

var mergeSparkReporter = new ExtentSparkReporter(testResultsDir + @"\Final\merged-extent-report.html");
mergeSparkReporter.LoadJSONConfig(Utils.PROJECT_ROOT_PATH + @"\spark-config.json");
extent.AttachReporter(mergeSparkReporter);

// Generate the merged HTML report
extent.Flush();

This the stacktrace of the exception.

System.NullReferenceException: Object reference not set to an instance of an object. 
  at AventStack.ExtentReports.Model.ExceptionInfo..ctor(Exception ex)
   at Void .ctor(System.Exception)(Object[])
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at AventStack.ExtentReports.Model.Convert.TestEntityParser.CreateEntities(String jsonFilePath)
   at AventStack.ExtentReports.Core.AbstractProcessor.ConvertRawEntities(ExtentReports extent, String filePath)
   at AventStack.ExtentReports.ExtentReports.CreateDomainFromJsonArchive(String filePath)

Any help would be appreciated.

Thanks, Saravana

saravanakumar-nc avatar Jul 26 '24 10:07 saravanakumar-nc