What will you do if you wish to send customized information to your QTP/UFT test results? or if you want to disable reporting of steps in the test results? or if you want to dynamically get the location where test results are stored. This is the topic of our article today. Reporter Object is used for sending information to the test results. With the help of this object you can:
- Report the status of test results (like pass, fail, warning)
- Enable/Disable reporting of step(s) following the statement.
- Retrieve the folder path in which the current test’s results are stored.
- Retrieve the run status at the current point of the run session.
- Report HTML in test results.
There are some very important methods and properties associated with it.
I think this is a very common method used with Reporter object. I am sure even if you have worked on QTP/UFT for a relatively short period, you would have come across this.
Reporter.ReportEvent EventStatus, ReportStepName, Details
where EventStatus can be:
0 or micPass: If this step runs test passes which is shown in test report.
1 or micFail: If this step runs test fails which is shown in test report.
2 or micDone: Used to send message to the test report and does not affect status of test.
3 or micWarning: Again, used to send warning message to the test report and does not affect status of test.
ReportStepName is name of step
Details are the user defined details for the given step.
Reporter.ReportEvent micPass, "Login Authorization", "The user-defined step passed."
I have mentioned this on my other post Some Useful Tips with QTP but would like to mention it again here since I get a lot of questions on this.
There can be situations where you don’t want the full status displayed on the test report. This property can be used to selectively filter the status of your tests.
Reporter.Filter = NewMode
where NewMode can be:
0 or rfEnableAll: This is the default mode. All reported events are displayed in the Test Results.
1 or rfEnableErrorsAndWarnings: Only those events with a warning or fail status are displayed in the Test Results.
2 or rfEnableErrorsOnly: Only those events with a fail status are displayed in the Test Results.
3 or rfDisableAll: All events in the Test Results are disabled.
This is used to get the path in which current test results are stored.
Path_of_Results = Reporter.ReportPath
This is used to get the current status of the run session
if Reporter.RunStatus = 0 then flag=1;
I started working on QTP since version QTP 8.0. Historically, Mercury and then HP had allowed usage of HTML in test results. However since QTP v11, things changed. According to HP, for versions QTP 11 to UFT 12.51 because of exposed security risks they purposefully disabled usage of HTML in test results viewer.
Since UFT 12.52 HPE has introduced another method ReportHTMLEvent using which you can use HTML in test results.
Given the above discussion, here is how you can use HTML in various versions of QTP/UFT.
UFT 12.52 and above
Reporter.ReportHTMLEvent EventStatus, ReportStepName, Details [, ImageFilePath]
- EventStatus is same as defined above for ReportEvent
- ReportStepName is the name of Step in HTML format.
- Details Complete description in HTML format
- [ImageFilePath] Square brackets denote optional property. Staring from UFT 11.5, you can insert an image in the test results. This argument takes path and filename of the image to be displayed in the Captured Data pane of the Run Results window.
In EventStatus and ReportStepName above, use HTML judiciously. Don’t use tags like <html>, <body>, <script>.
Reporter.ReportHTMLEvent micDone, "<b>LearnQTP:</b> <i>Learn Reporter Objects</i>", "<span style='color:red'>Complete Guide on Reporter Objects in QTP/UFT (colored red using HTML).</span>"
You can copy and paste the above statement in UFT editor and simply run this statement. When seen in RunResultsViewer, the above example will produce bold effect on the text LearnQTP, italicize the text Learn Reporter Objects and will color the text red Complete Guide on Reporter Objects in QTP/UFT (colored red using HTML).
QTP 11 to UFT 12.51
Officially, HPE removed the capability to send HTML to run results viewer in these versions of QTP/UFT. As a workaround, you can still use HTML on ReportEvent by escaping first HTML tag.
Reporter.ReportEvent micDone, "LearnQTP", "<<b>This is bold</b>"
QTP 8 to QTP 10
These versions use simple HTML in the steps and details arguments.
Reporter.ReportEvent micDone, "LearnQTP", "<b>This is simple HTML</b>"
This concludes our guide on Reporter Objects in QTP/UFT. In case you have any tips/suggestions/questions around it, please let me know using comments section below.