Object Spy is an option or utility within UFT to add objects to the Object Repository. Object Spy can be accessed from the tool bar as shown below:
After spying the object, the object hierarchy will be shown. Let us say we are spying the search text box in ‘http://www.amazon.com‘. The object properties will be shown as below
After spying an object, click the ‘Highlight‘ option to highlight the object in the application.
For adding the object into the Object Repository, click the ‘Add Objects‘ button in the Object Spy dialog.
The properties and its values are displayed for the selected object in the dialog box, which is unique for UFT to recognize the objects while the script executes.
The supported operations on the object can be retrieved by clicking the operation tab. Operations such as ‘Click‘ for a button, ‘Set‘ for a text box are retrieved from the ‘Operations‘ tab as shown below:
Properties of an Object can be determined by other ways apart from Object Spy. They are explained below:
GetROProperty is an in-built method used to retrieve runtime value of an object’s property. Below are the steps followed:
1. Record the Object in the OR.
2. Use Object Spy to determine the runtime Object Property to use.
3. Use GetROProperty method to retrieve the identified runtime property and store the value in a variable.
4. Use this value for further deductions.
Refer below example code:
'Get value displayed in search text box and assign to variable searchValue = Browser("CreationTime:=0").Page("name:=Amazon.com: Online Shopping").WebEdit("name:=field-keywords","html tag:=INPUT").GetROProperty("innertext")
The SetTOProperty changes the value of a test object property. Changing the property doesn’t affect the Object Repository or Active Screen, but just the way UFT identifies the object during runtime.
Any changes you make using the SetTOProperty method applies only during the course of the run session, and do not affect the values stored in the test object repository.
'Code example to set Search text box object value during runtime Set obj = Browser("name:=Amazon.com.*").Page(“name:=Amazon.com.*”).WebEdit("name:=field-keywords") ‘Would retrieve the object html id from the test object description, whether it’s in the OR or DP defined ‘Now we set the name property obj.SetTOProperty “name”, “Books” ‘And retrieve it msgbox obj.GetROProperty(“name”)
The GetTOProperty returns the value of the property from the test object’s description, i.e., the value used by UFT to identify the object. It returns the value of a property for a test object which UFT recorded to identify during the recording (run time).
'Code example to get Search text box object property value that was set during scripting/recording Set obj = Browser("name:=Amazon.com.*").Page(“name:=Amazon.com.*”).WebEdit("name:=field-keywords") msgbox obj.GetTOProperty(“html id”)