Object Identification in TestComplete – Descriptive Way
The Object Identification in TestComplete is based on the properties and values of the object stored in Name Mapping. Sometimes, the properties and the value of the application objects gets changed at run-time, which results in failure of the object identification by TestComplete.To overcome this problem,we use descriptive approach for the identification of the object on Application Under Test (AUT).
TestComplete provides several methods for the same. Some of them are :
- Find
- FindAll
- FindChild
Find method:
Find method is used to search the object in the desired hierarchy. Searching is based on the set of values of the specified properties.
Syntax
TestObj.Find(PropName,PropValues,Depth,Refresh)
where
TestObj:Refers to an reference (object) from where the search for the desired object will begin
PropName:Set of unique properties of object for identification.
PropValue:Set of values of the properties used for object identification.
Depth:Refers to the level till what the TestComplete needs to drill down to find the object.
Refresh : It instructs TestComplete what to do if the object we are searching is not present in the TestComplete Object cache.This is an optional field.
Output : Object
For example we need to perform click operation on a web button whose text changes at run time.
Approach :
First we need to identify some properties which will uniquely identify the object on webpage.Here we chooses the class and text property of the button.After the identification of the properties we nee dto store all the properties and relevant values in two separate array.
VarA=array("Class","Text") Varb=array("WebButton","Click Here")
Once we have defined the array,next we need to find the object for which we are searching
Set obj=testObj.Find(VarA,VarB,10)
In this statement testObj refers to the reference node from where the search will began and search for the object who has the properties that of properties stored in VarA and values equal to values stored in VarB.And 10 tells TestComplete to search for the object till the 10th level of the reference node and not more than that and store the result in an object.
To determine whether the search was successful or not ,we can use Exists method on obj object .If the Exists method return false,it implies that search was unsuccessful else if it returns True,search was successful and we can perform the click operation
If obj.Exists then obj.click else msgbox "No object found" End if
FindAll method:
FindAll method is used to search the object in the desired hierarchy i.e in both objects and child objects. Searching is based on the set of values of the specified properties.The output is in the form of the set of collection of the object which matches the criteria.
Syntax
TestObj.FindAll(PropName,PropValues,Depth,Refresh)
where
TestObj:Refers to an reference (object) from where the search for the desired object will begin
PropName:Set of unique properties of object for identification.
PropValue:Set of values of the properties used for object identification.
Depth:Refers to the level till what the TestComplete needs to drill down to find the object.
Refresh : It instructs TestComplete what to do if the object we are searching is not present in the TestComplete Object cache.This is an optional field.
Output : An array consisting of all the objects of specified values of specified proprties.
For example we need to count the number of buttons on a page.
Approach :
First we need to identify some properties which will uniquely identify the object on webpage.Here we chooses the class property of the button.After the identification of the properties we need to store all the properties and relevant values in two separate array.
VarA=array("Class") Varb=array("WebButton")
Once we have defined the array,next we need to find the object for which we are searching
NoOfTextbox=testObj.FindAll(VarA,VarB,10)
In this statement testObj refers to the reference node from where the search will began and search for the object who has the properties that of properties stored in VarA and values equal to values stored in VarB.And 10 tells TestComplete to search for the object till the 10th level of the reference node and not more than that. and store the result in an array.
Once we get an array we can tell the no of button on the webpage as following:
msgbox ubound(NoOfTextbox)
FindChild method:
FindChild method is used to search the object in the desired hierarchy i.e in the child object only. Searching is based on the set of values of the specified properties.
Syntax
TestObj.FindChild(PropName,PropValues,Depth,Refresh)
where
TestObj:Refers to an reference (object) from where the search for the desired object will begin
PropName:Set of unique properties of object for identification.
PropValue:Set of values of the properties used for object identification.
Depth:Refers to the level till what the TestComplete needs to drill down to find the object.
Refresh : It instructs TestComplete what to do if the object we are searching is not present in the TestComplete Object cache.This is an optional field.
Output : Object
For example we need to perform click operation on a web button containing text as “Login” on a webpage
Approach :
As we know the web button is a child element of the page.So we can use FindChild method here.For that firstly, we need to identify some properties which will uniquely identify the object on webpage.Here we chooses the class and text property of the button.After the identification of the properties we need to store all the properties and relevant values in two separate array.
VarA=array("Class","Text") Varb=array("WebButton","Login")
Once we have defined the array,next we need to find the object for which we are searching
Set obj=testObj.Find(VarA,VarB,10)
In this statement testObj refers to the reference node from where the search will began and search for the object who has the properties that of properties stored in VarA and values equal to values stored in VarB.And 10 tells TestComplete to search for the object till the 10th level of the reference node and not more than that and store the result in an object.
To determine whether the search was successful or not ,we can use Exists method on obj object .If the Exists method return false,it implies that search was unsuccessful else if it returns True,search was successful and we can perform the click operation
If obj.Exists then obj.click else msgbox "No object found" End if
So, these are some other ways by which we can identify the dynamic objects in TestComplete.
Happy Learning!!!
[…] Therefore the FindAllChildren function is handy when it is non realistic to build mapped objects at dynamic times and obviously this proves to be better off in those times. The use of this function can be compared to be the descriptive mode with respect to QTP style of handling the similar situation. For more information on the Test Complete descriptive way read further to object-identification-in-testcomplete-descriptive-way […]
Hi
Nice way to track down dynamic objects in TestComplete…..But if I use the Name Mapping Method and adding the ObjectType and IdStr property which do not change wouldn’t this be a better approach and make scripting easier….
Regards,
Savio Coelho
Yes, That is always a better approach to use Namemapping if the object’s property dont change. But I think we should prefer to go for Descriptive approach when it is not static, i.e. changing dynamically at runtime.
Hi, thanks for the article, your website is really useful!
I’d just like to ask, is the code in this article VBScript? Like the code on your article https://automated-360.com/test-complete/automation-object-model-testcomplete/ ? As a follow-on question, is it possible to develop scripts for TestComplete in VBS using the OLE automation like in the above-mentioned article? I assume it should be, but I’d just like to be sure.
Thanks. And keep it up!
Thanks for good words!!!Yes the code given is in vbscript.
Yes it is possible.
Hi All,
can some one plz explian descriptive programming in trst complete.
regards,
amar
Hi All,
can some one plz explian descriptive programming in test complete with example.
regards,
amar
Hi Amar,
below posts should help you, let us know if you are looking for any specific topic
https://automated-360.com/test-complete/object-identification-in-testcomplete-descriptive-way/
https://automated-360.com/test-complete/how-test-complete-handles-unexpected-windows/
https://automated-360.com/test-complete/using-low-level-procedure-in-testcomplete/
https://automated-360.com/test-complete/most-useful-function-in-test-complete-findallchildren/