How to verify object property using UFT

We have to verify object property using UFT in almost every automation script we create while working on any test automation project. Here we have written a ready-to-use code block for verifying object property using UFT.

This function takes the object, expected property name, expected property value, and test case id as an argument.

This function removes the line change from expected and actual values before comparing them to remove any discrepancy generated because of different types of newline characters in rendering.

This function can also verify object property if the expected property value is Blank.

Function to verify object property using UFT
Function VerifyObjectProperty(objweb,expPropertyName,expPropValue,TC)
    
    If IsObject(objweb) Then
        
        sActProp = Replace(objWeb.getROProperty(expPropertyName),vbCrLf,"")
        expPropValue = Replace(expPropValue,Chr(10),"")
        
        Select Case expPropValue
            Case "Blank","BLANK"
            If Len(Trim(sActProp)) = 0 Then
                reporter.ReportEvent micPass, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= Blank" & vbCrLf & "Expected Value = Blank"
                VerifyObjectProperty = True
            Else
                reporter.ReportEvent micFail, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                VerifyObjectProperty = False
            End If
            
            Case Else
            If IsDate(expPropValue) Then
                
                If  CDate(sActProp) = CDate(expPropValue) Then
                    
                    reporter.ReportEvent micPass, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                    VerifyObjectProperty = True
                    CaptureScreenShot(TC)
                Else
                    reporter.ReportEvent micFail, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                    VerifyObjectProperty = False
                    CaptureScreenShot(TC)
                End If
                
            Else
                
                Select Case TC
                    Case "Equal","EQUAL"
                    If StrComp(Trim(sActProp),Trim(expPropValue)) = 0 Then
                        
                        reporter.ReportEvent micPass, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                        VerifyObjectProperty = True
                        CaptureScreenShot(TC)
                    Else
                        reporter.ReportEvent micFail, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                        VerifyObjectProperty = False
                        CaptureScreenShot(TC)
                    End If
                    
                    Case "Contain"
                    If InStr(Trim(sActProp),Trim(expPropValue)) > 0 Then
                        
                        reporter.ReportEvent micPass, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                        VerifyObjectProperty = True
                        CaptureScreenShot(TC)
                    Else
                        reporter.ReportEvent micFail, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                        VerifyObjectProperty = False
                        CaptureScreenShot(TC)
                    End If
                    Case Else
                    
                    If InStr(Trim(sActProp),Trim(expPropValue)) > 0 Or StrComp(Trim(sActProp),Trim(expPropValue)) = 0 Then
                        
                        reporter.ReportEvent micPass, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                        VerifyObjectProperty = True
                        CaptureScreenShot(TC)
                    Else
                        reporter.ReportEvent micFail, TC & "- Validation of " & expPropertyName & "- property in  " & objweb.ToString , "Application Value= " & sActProp & vbCrLf & "Expected Value = " & expPropValue
                        VerifyObjectProperty = False
                        CaptureScreenShot(TC)
                    End If
                End Select
            End If
        End Select
    Else
        reporter.reportEvent micFail, "Object not found on the page for " & expPropertyName & "-" & expPropValue,""
        VerifyObjectProperty = False
        
    End If
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.