Hello Friends!
In this post, we'll see how to customize and manage the information in QTP Test Result file. Test Result is automaticaly generated after every test run.
Reporter Object is used for sending information/message to the QTP test results. Following are the method/properties we can use with ‘Reporter’..
• ReportEvent Method
• Filter Property
• ReportPath Property
• RunStatus Property
ReportEvent Method
ReportEvent is commonly used method od Reporter and most of you must be already aware of this!
As the name suggest, it reports an event to the test results. Means, by using Reporter.ReportEvent, you can send information to QTP test result file.
Syntax:
Reporter.ReportEvent EventStatus, ReportStepName, Details
As we can see above, ReportEvent takes 3 arguments. Let's discuss these briefly-
EventStatus: Status of the step i.e. Pass/Fail etc. It can be four types..
0 or micPass: Causes the status of this step to be passed and sends the specified message to the report.
1 or micFail: Causes the status of this step to be failed and sends the specified message to the report. When this step runs, the test fails.
2 or micDone: Sends a message to the report without affecting the pass/fail status of the test.
3 or micWarning: Sends a warning message to the report, but does not cause the test to stop running, and does not affect the pass/fail status of the test
ReportStepName: It is name of step. It can be any string value.
Details: It is also any string value. You should provide description of steps here.
Example of ReportEvent Method
The following examples use the ReportEvent method to report a failed step.
Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."
or
Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."
You can leave last two arguments (ReportStepName and Details) blank as well but recommended.
Reporter.ReportEvent 1, "", ""
or
Reporter.ReportEvent micFail, "", ""
Okay friends! It was most important part of Reporter. Let's quickly discuss remaining three properties also.
Filter property
Using Filter property, you can instruct QTP about what type of event to display in result.
Syntax:
Reporter.Filter = Mode
What is the use of Filter property?
Filter is used if you dont want to display all types of events in QTP test result. For example you have 10 Reporter.ReportEvent statements in your test (5-
Pass and 5-fail). By default all 10 will be displayed in result. You can use Filter if you want to display only pass or only fail events in the result. One way to comment all unwanted type of Reporter statements, but what if you can do that by writing just one line in your code!
There can be four types of Filter modes..
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. No event will be displayed in result file.
Example of Filter Property:
Reporter.Filter = 2
or
Reporter.Filter = rfEnableErrorsOnly
ReportPath Property
It simply retrieves the folder path in which the current test's results are stored.
Do not use this property to attempt to set the results folder path. Means it is used for 'getting the path' not 'setting the path'.
Syntax:
Path = Reporter.ReportPathExample of ReportPath Property
Dim Path
Path = Reporter.ReportPath
MsgBox (Path)
Above example uses the ReportPath property to retrieve the folder in which the results are stored and displays the path in a message box.
RunStatus Property
It retrieves the run status at any particular point during the run session. For tests, it returns the status of current test during the test run.
Syntax:
Reporter.RunStatusExample of RunStatus Property
If Reporter.RunStatus = micFail Then
Msgbox "Run Status is fail. Exiting from Action iteration."
ExitAction
End If
Above example uses the RunStatus property to retrieve the status of the run session at a specific point and exit the action if the test status is fail. If the test status is not fail, the test run continues.
In case of any queries/suggessions, please post your comments.