UFT API testing reporting
When working with API Testing in UFT I am lacking a good way to handle writing to the report programmatically. Is there anyway to write something (supported or unsupported).
For GUI test I use Reporter.setContext, Reporter.unSetContext, Reporter.LogEvent extensivly to get logging the way I want. Is there any possibility to do something similiar in API Testing?
Or atleast be able to write something to a new report node? where you preferably can write html code to the log.
I attach a picture to illustrate how I have it in GUI Testing. There instead of using UFT iterations (which I feel lack flexibility) I take care of my own iterations and by doing so am able to put a name on them Market SE, Market FI and even 10 more which was setup to not run in this test so therefor they are not displayed.
There is absolutely a way to do this. Instead of using the Reporter object, you use event handlers for your test step.
You need to do the following:
- In the step for which you want to write to the report, in the Properties pane, open the Events tab.
- In the Events tab, select the AfterExecuteStepEvent handler. Click the down arrow in that row and select Create a default handler..
- In the TestUserCode.cs file that opens, find the section of code that contains //TODO: Add your code here...
- In the place of the //TODO comment, use the Report method to send the message to the run results:
- Enter the this object to access the activity on which you are working. Add the period character after the this.
- Enter the name of the activitiy (you can find it from the intellisense list too.), followed by the period character (.)
- Enter the Report method with the following syntax: Report("custom feld to be entered in the results", data to be reported).
So for example, if you want to report a custom message to the run results for a Concatanate Strings activity, you can enter this example:
(Don't forget the semicolon after the method syntax...)
Then you see this in the run results:
Hope that helps!
Note: You can find all of this in the UFT documentation (from UFT 12.00 and onward), if you need instructions and/or examples. See this chapter: UFT User Guide > API Testing Design > Writing Event Handlers for API Test Steps
Thanks for the reply. I was however aware of this approach but its not what I am after.
I want to create completly custom report nodes in the left side tree structure. And I also want to write my log entry to "result details" instead of as a row in the captured data. And also I want to be able to set passed/failed/warning to the node.
My reason for this is
Say I do a REST call to an endpoint that returns a JSON with an array of data that I want to verify. Now say this array is 1000 entries large. Now I could use the GUI to manually enter which verifications I need but for 1000 entries that is pretty painful. And opening the result will be even more painful.
The nice approach would be if I can use the c# feature to loop though the results and check the values I want and then just do a log entry with passed if everything is okey, or fail and log the failing entries in a nicely formatted output (meaning preferably not plain text)
I am a big fan of a simple report and frankly the default logging is very cluttered so I try to remove as much as I possible can and rely on just showing but I decide is needed. I want my result files to be understandable for more people than the person that wrote the script.