GetRoProperty, GetToProperty in QTP/UFT with Example

⚡ Smart Summary

Object Spy reveals the properties and methods of any control in the application under test, while GetROProperty, GetTOProperty and SetTOProperty read and write those property values from a QTP or UFT One script at run time.

  • 🔎 Object Spy first: Point it at a control to see the test object properties, the run-time properties, the methods and the full hierarchy.
  • ☑️ Two object worlds: The test object is the stored description; the run-time object is the live control in the application.
  • GetROProperty: Reads the current value from the live control, so the application must be open and the object must exist.
  • 🧪 GetTOProperty: Reads the stored description instead, which is why the two methods can return different values.
  • 🛠️ SetTOProperty: Changes the description for this run only; the repository is never touched and the change is discarded at the end.
  • 📌 No SetROProperty: A script can read the application but cannot write a property back into it.

Object Spy and the GetROProperty, GetTOProperty and SetTOProperty methods in QTP and UFT One

This tutorial demonstrates Object Spy.

Object Spy can help determine the useful properties and methods associated with an object in your environment.

The HP/Micro Focus UFT tutorials also describes GetROProperty, GetTOProperty & SetTOProperty.

⚠️ Version note: The tool described here shipped as HP QuickTest Professional, became Micro Focus Unified Functional Testing, and is sold today as OpenText Functional Testing (UFT One). Object Spy and all three methods still work exactly as described below.

Click here if the video is not accessible

Object Spy

  • Object Spy is a feature in QTP using which you can view both the test and run-time object properties and methods.
  • It also gives the syntax for a selected method.
  • Object Spy gives the complete hierarchy of the object you have selected.

That hierarchy matters, because a property name copied out of Object Spy is the exact string the three methods below expect. Spying an object is therefore the first step in almost every property retrieval task.

GetROProperty

  • GetROProperty – is an inbuilt method used to retrieve the runtime value of an object property.

There are 4 steps involved in using the GetROProperty:

  1. Record the Object on which you want to use the GetROProperty in Object Repository.
  2. For the recorded object identifies the run-time property which could be used. You may use Object Spy.
  3. Use GetROProperty method to retrieve the identified Run-time property and store the value in a variable.
  4. Use this value for further deductions.

Because the value is read from the live control, the application must be open and the object must actually exist on screen when the line runs.

SetTOProperty & GetTOProperty

  • Consider a Web Button stored in the Object Repository
  • When the test is run QTP creates a copy of this object called Test Object and compares it with the Run Time Object
  • Using GetTOProperty you can retrieve the value of a property of Test Object
  • Using SetTOProperty you can change the property value of a Test Object
  • When the test is completed, this test object is discarded and so are any modifications you made in the object properties using the SetTOProperty
  • When the test is re-run, a new copy of the test object is created with original property values stored in the object repository
  • You can consider using GetTOProperty and SetTOProperty when your test script has multiple lines of codes and your environment is sporadic
  • For a note, there is no SetROProperty

Syntax and Examples

All three methods are called on a test object at the end of its hierarchy, and all three take a description property name as a string. The table gives the signature of each.

Method Syntax Reads or writes
GetROProperty object.GetROProperty(Property) Reads the live control in the application
GetTOProperty object.GetTOProperty(Property) Reads the stored test object description
SetTOProperty object.SetTOProperty Property, Value Writes the test object description for this run only

Reading a run-time value is a single statement. This example, taken from the official retrieve and set values reference, pulls the target address of a link during the run session.

link_href = Browser("Technologies").Page("Technologies").Link("Jobs").GetROProperty("href")

Writing then reading a test object property is just as short. The pair below sets the Submit button name to my button and reads the same value straight back.

Browser("QA Home Page").Page("QA Home Page").WebButton("Submit").SetTOProperty "Name", "my button"
ButtonName = Browser("QA Home Page").Page("QA Home Page").WebButton("Submit").GetTOProperty("Name")

A typical verification joins the two ideas: read the run-time value with GetROProperty, then compare it against what the test expects.

strValue = Browser("Welcome").Page("Find a Flight").WebList("fromPort").GetROProperty("selection")
If strValue = "Acapulco" Then
    Reporter.ReportEvent micPass, "Default city", "Default city is correct"
Else
    Reporter.ReportEvent micFail, "Default city", "Unexpected value: " & strValue
End If

Difference Between GetROProperty and GetTOProperty

The two names differ by one letter and are the most confused pair in the tool. RO stands for run-time object, TO for test object, and each reads from a different place.

Point of comparison GetROProperty GetTOProperty
Source of the value The live control in the running application The description stored for the test object
Application must be open Yes No
Sees a SetTOProperty change No Yes, for the current run
Typical use Verifying what the user actually sees Checking or debugging how the object is being identified
Matching setter None — there is no SetROProperty SetTOProperty

A worked contrast makes the split obvious. Set an html id on a list that has none, then read it back both ways: GetROProperty returns an empty string because the application never changed, while GetTOProperty returns the value that was just written into the description.

Common Errors and How to Fix Them

Property retrieval fails for a small number of predictable reasons. The table lists the ones testers meet most often.

Symptom Cause Fix
The call returns an empty string The property name is wrong, or the object does not expose it Spy the object again and copy the property name exactly as listed
Object not found at the GetROProperty line The control had not rendered yet Add a synchronisation step before the read
GetROProperty ignores a SetTOProperty change The two methods address different objects by design Read the change back with GetTOProperty instead
A SetTOProperty change disappears Test object edits last only for the current run Edit the object in the repository, or use descriptive programming
SetROProperty raises a syntax error No such method exists Drive the application through a normal step such as Set or Click

Two habits prevent most of these: spy the control before writing the line rather than guessing the property name, and keep VBScript retrieval calls close to the step that needs the value, so the object is still on screen when the read happens.

FAQs

Object Spy lists the identification properties the tool holds for that class, plus the native properties exposed by the browser. Attribute and style values are reached with the attribute and style prefixes inside the property string.

A run-time object belongs to the application, not to the test, so the tool will not write into it. To change what the application holds, drive the control with an ordinary step such as Set, Select or Click.

No. The temporary test object is discarded when the run ends, and a fresh copy is built from the repository next time. Permanent changes belong in the object repository itself.

Yes. A described object built inline accepts the same calls, so GetROProperty works with descriptive programming too. GetTOProperty then returns the value from the inline description rather than from a stored entry.

AI-assisted locator tools rank several candidate properties for the same control and repair a broken description when one attribute changes. That reduces the manual spying loop, though the suggested property still needs a human check.

Copilot completes the hierarchy and method call once it sees a few similar lines in the file. It cannot know your real object names or which properties the control exposes, so verify every generated string in Object Spy.

Object Spy is an inspection tool that shows values while you build the script. A checkpoint is a step that runs inside the test and reports pass or fail against a stored expected value.

Only if the object still exists in the application. A control that has not rendered, or one that was removed from the page, raises an object not found error rather than returning an empty value.

Summarize this post with: