The SetTo and GetTo properties are most handy for an automation tester when working with objects. In this post, we will uncover the details.
Objectives:
On completion of this post, you would answer the following questions –
what are Test Objects ?
What are Run Time Objects ?
what is GetTOProperty ?
What is SetTOProperty ?
What is GetROProperty ?
Let’s start with the test objects:
Test Objects:
Objects which are present in the object repository are called as test objects.
Run Time Objects:
Objects present in the application (Application under Test or AUT) are known as Run time objects.
While recording a script, QTP will store the objects, along with the property names and values, in object repository. (We can add the objects to object repository either manually based on requirement).
So, while executing the script, QTP will compare the objects in object repository to the objects present in application (AUT) to check the object existence.
GetTOProperty:
To get the value of particular property of a Test Object, which is stored in object repository.
Example: Open Flight application and record the login functionality
Script: Dialog("Login").WinEdit("Agent Name:").Set "test" Dialog("Login").WinEdit("Password:").Set "mercury" Dialog("Login").WinButton("OK").Click
The object repository looks like below image:
Let us validate the stored properties in Object repository:
1.Get the “text” property value of ‘Login’ Dialog
Msgbox Dialog(“Login”).GetTOProperty(“text”)
Output- Login
2. Get the “attached text” property value of ‘OK’button
Msgbox Dialog(“Login”).WinButton(“OK”).GetTOProperty(“attached text”)
Output is Blank because there no value in object repository for “attached text” property
3. Get the “text” property value of ‘OK’button
Msgbox Dialog(“Login”).WinButton(“OK”).GetTOProperty(“text”)
Output – OK
4. Get the “attached text” property value of ‘Agent Name’
Msgbox Dialog(“Login”).WinEdit(“Agent Name:”).GetTOProperty(“attached text “)
Output – Agent Name:
GetTOProperties:
To get values of all properties of a particular Test Object, which is stored in object repository.
Let us pick up object ‘AGENT NAME’ as shown in the below image:
Script: Set a = Dialog("Login").WinEdit("Agent Name:").GetTOProperties For i = 0 To a.count-1 propertyName = a(i).Name propertyValue = a(i).Value msgbox propertyName & " - " & propertyValue Next Output: nativeclass - Edit attached text - Agent Name:
SetTOProperty:
To set the test object property during run time. This is only temporary change do not affect the values stored in the test object repository.
Example1:
Msgbox Dialog("Login").WinButton("OK").GetTOProperty("text") Output – OK
Dialog("Login").WinButton("OK").SetTOProperty "text", "YES" Msgbox Dialog("Login").WinButton("OK").GetTOProperty("text")
Output is ‘YES’ and the value in object repository is also ‘YES’
Object Repository after execution:The change is only temporary. The ‘Text’ property does not change in Object repository.
Example2:
The ‘Native class’ property value is ‘Button’ for ‘OK’ object. See the above image.
Change the ‘native class’ value as ‘Edit’. Now script will fail when user tries to click the ‘OK’ button.
Dialog("Login").WinButton("OK").SetTOProperty "nativeclass", "Edit" Dialog("Login").WinButton("OK").click
GetROProperty:
To get the value of particular property of a Run Time Object. (Objects in AUT)
Example:
Dialog("Login").WinEdit("Agent Name:").Set "test" Dialog("Login").WinEdit("Password:").Set "mercury" Msgbox Dialog("Login").WinEdit("Agent Name:").GetROProperty("text") Output – test
Any Questions:
If you have any questions or any kind of doubts in your mind feel free to ask. Please put in the comments section below.