Sunday, February 22, 2009

Reporter Object

Simply put Reporter object is an object, which is used to send information to the test results.

It has an associated method called ReportEvent.

It has few associated properties:

  • Filter
  • ReportPath
  • RunStatus

Lets talk about ReportEvent and see few of its examples:

Its syntax is as follows:
Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

EventStatus: 0 or micPass, 1 or micFail, 2 or micDone, 3 or micWarning

An example using the above syntax and a screenshot:

Reporter.ReportEvent micDone, “NAME”, “These are the details”, “C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg”





Simple example (without ImageFilePath)
(Write the whole below code in a new test and run it and check the results.)

dim sum
sum=InputBox("What is the sum of 2 + 2 ?:")

if (sum=4) then
Reporter.ReportEvent 0, "My Step 1", "Yes you are right!"
else
Reporter.ReportEvent 1, "My Step 1", "No, the sum should be 4"
End if


Simple example (with ImageFilePath)
(Write the whole below code in a new test and run it and check the results.)

dim sum
sum=InputBox("What is the sum of 2 + 2 ?:")

if (sum=4) then
Reporter.ReportEvent 0, "My Step 1", "Yes you are right !", "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Winter.jpg"
else
Reporter.ReportEvent 1, "My Step 1", "No, the sum should be 4"
End if


The following line will include a link in the results report to launch a notepad
(Write the whole below code in a new test and run it and check the results.)



[To see Your Computer Name: right click on My Computer icon on desktop, select Properties, a System Properties window will open, go to Computer Name tab and see your "Full computer name:"]


The following example shows how to display text in two separate lines in results report using vbcrlf

(Write the whole below code in a new test and run it and check the results.)

myname = "sachin"

If myname = "sachin" Then
Reporter.ReportEvent 0, "Hello", "Hi "&myname&vbcrlf&" How are you."
Else
Reporter.ReportEvent 1, "Hello", "You are not Sachin!"
End If


A simple example to show Built-in Environment variable (File->Settings and Environment) in the results report
(Write the whole below code in a new test and run it and check the results.)

Reporter.ReportEvent 0, Environment("ActionName"), "Hey, this is an env variable"


A simple example to show how to color text in results report
(Write the whole below code in a new test and run it and check the results.)