Forum Discussion

kcsahu777's avatar
kcsahu777
Contributor
13 years ago

Any way to search for a particular property value

Is there any way to search for a property value?



Example: 



 I am logging in to my tested apps using user id as 'ABC'



I want to know is there any property that is there in the application which will have the value as "ABC"?  Can we search that in object browser with just one button press search so that it will search througout all the objects property values.

1 Reply

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Krushna,


    There is no such functionality in TestComplete UI. But you can create a script that will iterate through the object hierarchy of your tested application and find the needed value in properties of each object. Since you don't know the property you are looking for, the script will have to iterate through all the properties of an object. Below is the code snippet that demonstrates how you can do this. I'd like to note that scripts like this are not safe enough: when TestComplete obtains a property value, it may need to call code of your application, and in general, this may cause issues in the application under test or even cause a crash.




    ' Main test routine

    Sub Test2

      Set p = Sys.Process("YourProcess")

     

      Set Result = CheckObject(p, "ABC")


      If Result Is Nothing Then

        Log.Warning "Not found"

      Else

        Log.Message "Found: " + Result.FullName

      End If   

    End Sub


    Function CheckObject(AObject, AValue)

      Set ResultObject = Nothing

     

      ' Get object properties

      Set Props = aqObject.GetProperties(AObject)

     

      ' Iterate through object properties

      Do While Props.HasNext

        Set PropertyItem = Props.Next

        If CanUseProperty(PropertyItem) Then ' Exlude certain properties from comparison

          If PropertyItem.Value = AValue Then

            Set ResultObject = AObject

            Exit Do

          End If

        End If

      Loop

     

      ' Iterate through child objects

      If ResultObject Is Nothing Then

        For i = 0 to AObject.ChildCount - 1

          Set ResultObject = CheckObject(AObject.Child(i), AValue)

          If Not (ResultObject Is Nothing) Then

            Exit For

          End If

        Next

      End If

     

      Set CheckObject = ResultObject

    End Function


    ' This function excludes certain properties from comparison

    Function CanUseProperty(APropertyItem)

      ' Exclued properties by name

      If APropertyItem.Name = "PopupMenu" Or _

         APropertyItem.Name = "SystemMenu" Then

        CanUseProperty = False

        Exit Function

      End If


      ' Exclude properties that use parameters

      If APropertyItem.ParamCount <> 0 Then

        CanUseProperty = False

        Exit Function

      End If

     

      ' Exclude properties that don't have string type

      If VarType(APropertyItem.Value) <> varOleStr Then

        CanUseProperty = False

        Exit Function

      End If

     

      CanUseProperty = True

    End Function