Sunday, 6 February 2011


QTP checkpoints are very limiting when it comes to maintenance and transport of the same across scripts. It is always best to avoid QTP checkpoints whenever possible and create your own checkpoint routines that does the work. This article will give a brief introduction on how create custom checkpoints or how to simulate checkpoint validations through reporter object.
Before we start we need to take a look at the Reporter.ReportEvent method
Syntax:
Reporter.ReportEvent EventStatus, ReportStepName, Details
EventStatus can take 5 possible values
  • micPass – Passed event
  • micFail – Failed event
  • micDone – No event status
  • micWarning – Warningevent
  • micInfo – Information event. (Note: This event is not document in QTP help file)
ReportStepName – Name/Text of node to be shown in the test results tree view
Details – Text to be shown in the detail column of the report
Below sample code demonstrates the usage
Reporter.ReportEvent micPass, "micPass", "This is a passed event"
Reporter.ReportEvent micFail, "micFail", "This is a failed event"
Reporter.ReportEvent micDone, "micDone", "This is a general event"
Reporter.ReportEvent micWarning, "micWarning", "This is a warning event"
Reporter.ReportEvent micInfo, "micInfo", "This is a information event"
Above would generate test results as shown in below screen shot
Test Resut summary
Test Result summary
Standard checkpoint
Below screenshots shows the properties to be validated and expected values for a checkpoint.
Checkpoint Properties
Checkpoint Properties
In the above checkpoint QTP will get the actual values of the the properties specified and compare it with the expected values that are set. We can get actual values using the GetROProperty method on the object. Below code demonstrate how we can create a similar checkpoint through code
'Function to validate object property and report status in test results
 
Function ValidateProperty (Object, PropertyName, ExpectedValue, NodeName)
    'First check if the object exists or not
    If Not Object.Exist(0) Then
        'Report a failure in the test results
        Reporter.ReportEvent micFail, NodeName, "The object does not exist"
 
        'Return false
        ValidateProperty = False
        Exit Function
 
        'Check if actual property value is same a expected value
    ElseIf Object.GetROProperty(PropertyName) = ExpectedValue Then
 
        'Reporet success to test results
        Reporter.ReportEvent micPass, NodeName, " Property = " & PropertyName _
            & ", ExpectedValue = ActualValue = " & ExpectedValue
 
        'Return true
        ValidateProperty = True
        Exit Function
 
    Else
        'Expected and actual values are different. Report failure and
        'report both value to report.
        Reporter.ReportEvent micFail, NodeName, " Property = " & PropertyName _
            & ", ExpectedValue = " & ExpectedValue & ", Actual Value = " & _
            Object.GetROProperty(PropertyName)
 
        'Return false
        ValidateProperty = False
        Exit Function
    End If
End Function
 
'Execute the checkpoint on a object
Set oLink = Browser().Page().Link("Subject")
ValidateProperty oLink, "html tag", "A", "Validate html tag for Subject Link"
ValidateProperty oLink, "innertext", "Subject", "Validate innertext for Subject Link"
ValidateProperty oLink, "text", "Subject", "Validate text for Subject Link"
On similar lines we can simulate any kind of checkpoint present in QTP. Though it might look like a lengthy process as compared to using inbuilt checkpoints but it if well coded it is easily maintenable.

0 comments:

Post a Comment

TrainingHUB. Powered by Blogger.

Total Pageviews

THE BEST QTP TRAINING INSTITUTE IN HYDERABAD

QTP Training in hyderabad

Sql Tutorial

Popular Posts

Our Facebook Page

TrainingHUB

Followers