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.

ReporterEvent Method:

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.
Syntax:

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.
and
ReportStepName is name of step
and
Details are the user defined details for the given step.
For Example:

Reporter.ReportEvent micPass, "Login Authorization", "The user-defined step passed."

Filter property

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.
Syntax:

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.

ReportPath Property

This is used to get the path in which current test results are stored.
Syntax:

Path_of_Results = Reporter.ReportPath

RunStatus Property

This is used to get the current status of the run session
Syntax:

Reporter.RunStatus

For Example:

if Reporter.RunStatus = 0 then flag=1;

ReportHTMLEvent

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]

where

  • 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>.

Example Usage:

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). 

ReportHTMLEvent QTP

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.

Example Usage:

Reporter.ReportEvent micDone, "LearnQTP", "&lt;<b>This is bold</b>"

QTP 8 to QTP 10

These versions use simple HTML in the steps and details arguments.
Example Usage:

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.