Forum Discussion

gopalmalu's avatar
gopalmalu
Contributor
15 years ago
Solved

Can we do descriptive programming

Hi,



Can we do scripting (descriptive programming) with TC if application is not developed ?



Thanks,

Gopal
  • Hi guys..



    Prakash Konduru  is explain descriptive programming concept very well with example.



     Using Find, FindAll, FindChild, FindAllChilderen  methods we can performed descriptive programming in TestComplete. (all the above methods will help for Dynamic Descriptive programming).

                          

    3- Find : - This method is used to search the object from the TestedObj hierarchy.This method searches an object with the specified values of the specified properties. here search starts from TestedObj parent node and continue upto the depth mention.

    Syntax


         


           Set myObject = TestObject.Find(PropertyName, PropertyValue, Depth)        


     


     


    Example - Suppose you want to search "gmail link" on google page, We will write Descriptive programming like -


     


    Set lnkgmail = Sys.Browser("IExplorer").Page("google.com").Find("ContentText", "gmail", 10) 


     


    Here - 


    1- Property Name = ContentText       


    2- Property Value = gmail


    3- Depth = 10


     


    4- FindChild : - A TestedObj may have one or more child objects with specified values of the specified properties so in this case we will using FindChild Method. FindChild method searches  child objects from the TestedObj.

    Syntax -




               Set myObject = TestObject.FindChild(PropertyName, PropertyValue, Depth)    


     


    Note - The difference between Find and FindChild is that, FindChild searches child objects, while Find searches TestedObj only.


     


    5- FindAll : - FindAll method is used to search desire object from the TestedObj hierarchy. FindAll Method searches the entire object that have Specified value of the Specified properties. it's return a collection of objects and stored entire object list into an Array.


    Syntax -


         

           Set myObject = TestObject.FindChild(PropertyName, PropertyValue, Depth)   




    6- FindAllChildren : – FindAllChildren method is same as FindAll method (as mention above), it will search all the children and store them into an Array.




    Set myObject = TestObject.FindAllChildren(PropertyName, PropertyValue, Depth)   




    Note - We can search a object with the combination of multiple properties and values. Suppose we want to search gmail link which is enabled on page, so in this case we will need to define arrays for Property Name and Property Value and use them like below-

    Example

        

      PropertiesName = Array ("ContentText","ObjectType", "Enabled")

      PropertieValue = Array("gmail","Link", "True")



     Set myObject = TestObject.FindChild(PropertiesName, PropertieValue, 100)     



    This May help you.

                                

15 Replies

  • Yes we can! Try this one



    Function Descript()




       Set pg=Sys.Browser("iexplore").Page("*")


       NameProperty = Array("textContent","outerText","Id","tagName") 


       ValueProperty = Array(strPropVal1,strPropVal2,strPropVal3,strPropVal4)


       Set obj=pg.FindAllChildren(NameProperty,ValueProperty,9999999,True)


       obj.Method  



    End Function



    Based on your requirement enter the Name property and their Property value into array.



    Thank you,

    Srini.



     

  • Yes! we need to pass the property values into the function for which property you supposed to search. i just mentioned some property names for understanding purpose you can change it based on your requirement.



    if you want use it as a generic function then we need to start from top level i think so! 



    Thanks,

    Srini.
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1


    (Been in a good and relaxed mood... :) )



    For me the situation is obvious...



    > Set obj=pg.FindAllChildren(NameProperty,ValueProperty,9999999,True)

    This line requests search for *all* objects that meet specified criteria starting from the specified root. I hope that it is clear that the higher the root is in the objects hierarchy the 'more generic' search is. At the same time, the higher the root is in the objects hierarchy the worse search performance is. (Just because even if you need first found object and the sought for object is found in the first branch of the objects tree, the search will not stop until it traverses all search tree.)

    And the optimal balance between the performance and reusability is a matter of a good code architecture (which, unfortunately, is a rare thing nowadays... :(. And is one of the reasons I love tools by SmartBear).



    Just my $0.02... Nothing to argue about :)


    • Everseeker's avatar
      Everseeker
      Contributor

      Does TestCompete support Regex in this context (or at all)?