After the execution of an API script, Run Results Viewer shows no run results <broken result> (UFT API)
Question ID: 108202
1
0

This API Script has calls to a couple of REST services, one through REST Activity and the other through HTTP Activity. Script has lot of user code with connections to DB and Excel workbooks. This script iterates a set of test data and logs results after verifying the expected xml/json responses. Scripts works for most of the data.
Problem happens, when a batch run is scheduled, after execution of the script, run results viewer does not generate the report and just displays <broken result>. I see "The given key was not present in the dictionary." error in output.
I have narrowed down the issue to a single test data and it is consistently reproducible.
Log results shows KeyNotFoundException at WriteStepToDisk method

Call Stack:
———–
2016-12-05 10:54:49,459 [1] ERROR HP.ST.Fwk.ReporterFWK.Reporter [(null)] – Problem in writing Step Xml
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at HP.ST.Fwk.ReporterFWK.Reporter.WriteStepToDisk(String stepId, String fileName)
at HP.ST.Fwk.ReporterFWK.Reporter.<>c__DisplayClass1.b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
2016-12-05 10:54:49,475 [1] DEBUG HP.ST [(null)] – System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at HP.ST.Fwk.ReporterFWK.Reporter.WaitToFinisheReports()
at HP.ST.Fwk.ReporterFWK.Reporter.Dispose()
at Script.WorkFlowScript.CreateReportFiles() in c:\\….Main.cs:line 844

Marked as spam
Posted by (Questions: 63, Answers: 1)
Asked on March 15, 2018 6:37 pm
232 views
Answers (1)
0
Private answer

I have found that in the past the input parameters in question for the CheckpointEventArgs.Checkpoint.Report method are strings and the code is attempting to inject Dictionary object that does not exist (the key is not present in the dictionary).

In the simple example provided below, the 'nokey' dictionary object is replaced with an array out of bounds exception being given to the method. This too causes the result to be broken. So, our conclusion was that if the cp.Checkpoint.Report method parameters are proper strings, then the result is not broken (as expected). Coding accordingly avoids the issue of the 'Broken Result'.

CheckpointEventArgs cp = new CheckpointEventArgs(CodeActivity4);

string [] myArr = {''1'',''2'',''3''};
cp.Checkpoint.Report(''green'', ''green'', ''green'', ''green'', ''green'', HP.ST.Fwk.RunTimeFWK.CheckpointFWK.StatusEnum.Succeed);
cp.Checkpoint.Report(''red'', ''red'', ''red'', ''red'', ''red'', HP.ST.Fwk.RunTimeFWK.CheckpointFWK.StatusEnum.Succeed);
cp.Checkpoint.Report(''blue'', ''blue'', myArr[3], ''blue'', ''blue'', HP.ST.Fwk.RunTimeFWK.CheckpointFWK.StatusEnum.Succeed);
cp.Checkpoint.Report(''white'', ''white'', ''white'', ''white'', ''white'', HP.ST.Fwk.RunTimeFWK.CheckpointFWK.StatusEnum.Succeed);

Recommend to use a try-catch (like below) in his code to catch the exception thrown (key was not present in the dictionary). I would recommend to incorporate some error checking into the final code to catch this exception and deal with the exception which occurs for only certain rows of input data to his script.

string myVar='''';
Dictionary myD =new Dictionary();
myD.Add(''cat'', ''brown'');
try {
myVar=myD[''noKey''];
} catch (Exception e) {
MessageBox.Show(e.Message);
}
}

Marked as spam
Posted by (Questions: 2, Answers: 98)
Answered on March 15, 2018 6:37 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top