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).
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", "<<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.
You have a wonderful site for knowledge regarding UFT and it’s evolution over the years.
It is quite surprising that up till this day, companies are still using this tool.
Good to have a site like your’s , ready to help us programmers.
Hi Ankur,
Thank you for sharing the information.
Is there anyway I can email test set run result automatically once test set(automated) execution completed in ALM?
Hi,
Why does the following warning becomes failed when displayed under report? Is there a way to show warning in report?
Reporter.ReportEvent micWarn, “File Status”, “System was unable to delete.”
Thanks
@Sarahmear: The correct syntax is
micWarning
and notmicWarn
Hi, I am using UFT 12.01 and I copied and pasted your code to make the text bold, but it appears on the result as it is, not bold. The text is appearing in the result window exactly as- “LearnQTP”, “<This is bold”
Please advice.
Thank you.
I mean, The text is appearing in the result window exactly as- “LearnQTP”, “< This is bold” including the tags.
@Niloy: As mentioned above, HP removed the capability to inject HTML from versions QTP 11 to UFT 12.51. The above method
ReportHTMLEvent
would work only on UFT 12.52 and above.hi sir,
sir is there default implemention of reporter event in qtp test results because if we record and run a simple web application it will automatically generate scripts and provide pass/fail status to test scripts without writing reporter event in script?
@raviteja: That’s the purpose of checkpoints. Reporter object provides you with custom results.
Is it possible to have Reporter.ReportEvent added as a placeholder after each event so I can go back and populate the correct parameters inside of it?
Hi,
I would not like to see all the events “Done” in the test results window. I want to see only Pass or failed which are reported with statement Reporter.ReportEvent. Could any please help me with idea or code ?
@balu: Did you check Reporter.Filter?
Yes Ankur,
I tried Reporter.Filter with all the parameters. but i could not filter for the messages for only pass and fail in the QTP test results Report
@Balu: Ok, looks like you need to customize your results file.
Go to UFT(QTP) Documentation > HP Run Results Viewer Help > Run Results Viewer > Run Results Viewer Overview > Run Results XML File
Please read it start to finish. This is all what you need.
Hi Ankur, thanks for the reply, i am using QTP 10 , So i couldn’t find the doc specified by you. I have read other articles on customizing the test results. So i came to understand that the file “results.xml” has to be modified based on my requirement.
But what to modify in the “results.xml” is a big question.
It would be of great help, if you could explain this on the blog. and also the documentation path in QTP 10.
@balu: Sure we will try to come up with a post on this topic. For the time being, you can ask your question on QTP forums.
Hi,
I am looking out to customize the QTP report to make it more readable/understandable to the Functional guys executing the scripts.
Any suggestions how can the same be done?
just add functionality to that reports
Hi.
1. I am unable to identify a Calendar on a .ASPX page after I record the script and run it again to verify.
The code that is captured in Expert view appears as shown below:
Browser(“POLO Home”).Page(“Add Policy Standard”).Image(“Select a date from the”).Click 8,9
Browser(“POLO Home”).Page(“Add Policy Standard”).WebEdit(“ctl00$SPWebPartManager1$g_9142”).Click 52,7
2. Also, the user names that are picked from Active Directory do not get polpulated while playing the script, although this step was recoded.
The code for this step appears as shown below:
Browser(“POLO Home”).Page(“Add Policy Standard”).WebList(“ctl00$SPWebPartManager1$g_9144”).Click 5,5
Browser(“POLO Home”).Page(“Add Policy Standard”).WebEdit(“upLevelDiv”).Click 99,10
Browser(“POLO Home”).Page(“Add Policy Standard”).Check CheckPoint(“Add Policy Standard_4”)
Could you please help in getting this resolved.
Thanks in advance.
just go to object identification and set the object as standard windows in listbox and click userdefine and create the calender option
Hello Guys – I have a question related to Reporter.ReportEvent
Lets say I want to write to the same step, more than one row, how to do this?
Thank you
Can we report results in excel sheet in a systematic manner as steps failed or pssed
Hi, if dataTable have 4 record.
certainly, when I run, it return 4 result. I write: If Reporter.RunStatus=micFail Then
Reporter.ReportEvent micFail,”AAA”, “Error”
End If
-Step 1 is Done => Reporter.RunStatus=2
-Step 2 is Done => Reporter.RunStatus=2
-Step 3 is Failed
Reporter.RunStatus=1
-But Step 4 is Done
Reporter.RunStatus=1 ?????
I think, in step 4, if Done, Reporter.RunStatus=2
How do I do Reporter.RunStatus=2 not=1.
Thank a lot
I have a Qn :
If the test fail & trace out in the test report;how I pass that
particular through script.
Hi, What do I do if I want pass and fail in my test result report but not warnings??
Hi,
I know how to make my own reports, but is it possible to change the build in QTP reports (the ‘ReportStepName’ and/or ‘Description’), that is generated automatically when an error/warning occurs?
E.g. when I use ‘On Error Resume Next’ QTP, of course, is making a lot of error and warning reports. Is is then possible to ignore these reports, and replace them with my own?
Hope someone have an answer!
SwfWindow(“training”).SwfWindow(“Data Extraction”).SwfButton(“E_Save”).Click ‘//Clicks on Save button
If SwfWindow(“training”).Dialog(“Add Data Extraction”).WinButton(“E_PopupOK”).Exist (2) then
Reporter.ReportEvent micPass,”Data Extraction – Dataset Page”,” Data Extracion Created Sucessfully”
Print “E_DataExt_Dataset – Work Item ID : 48286)—> PASS)”
Else
Reporter.ReportEvent micFail,”Data Extraction – Dataset Page”,”Not able to Create Data Extraction”
Print “E_DataExt_Dataset – Work Item ID : 48286)—> FAIL)”
end if
SwfWindow(“training”).Dialog(“Add Data Extraction”).WinButton(“E_PopupOK”).Click ‘//Displayed popup message
In QC, i need results as below while running with UFT
Start Test
Start Action
Start Transaction
– Step Name, Status(Pass/Fail),Step Description,Expected, Actual
—–
—-
End Transaction
End Action
End Test