Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MergeReport - Exception at CreateDomainFromJsonArchive #226

Open
saravanakumar-nc opened this issue Jul 26, 2024 · 1 comment
Open

MergeReport - Exception at CreateDomainFromJsonArchive #226

saravanakumar-nc opened this issue Jul 26, 2024 · 1 comment

Comments

@saravanakumar-nc
Copy link

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
Copy link
Author

I believe the issue is with Extenttest.Fail(Exception). If i use Extenttest.Fail(Message) everything looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant