- Test Script Synchronization
- Placing a Generic Delay in Your Script
- Waiting for Test Objects to Come into Existence
- Timing How Long Something Takes to Execute in a Script
- Working with Test Objects
- Working with the Clipboard Object
- Viewing an Objects Properties
- Retrieving All Properties of a Test Object
- Retrieving the Value of a Single Property
- Programmatically Retrieving Data from an Object in My Application
- Determining a Test Objects Valid Test Data Type Arguments to getTestData()
- Using getTestData to Extract Data from a Text Field
- Using getTestData to Extract Data from a List
- Using getTestData() to Read Data in a Table
- Using getTestData() to Extract Data from a Tree
- Obtaining Data from a Test Object That the Rational Functional Tester Verification Point Wizard Does Not Capture
- Creating a Custom Verification Point
- Changing the Value of a Test Objects Property
- Evolving Custom Scripting into Reusable Methods
- Summary
Retrieving All Properties of a Test Object
The two sets of properties discussed in the “Viewing an Object’s Properties” section—value and nonvalue properties—can be retrieved from a test object in a script by invoking getProperties() and getNonValueProperties(), respectively. Each of these methods returns a Hashtable of property names and values. For nonvalue properties, the values are references to the actual objects in the target application (remote JVM). Listing 3.7 shows three methods: one that retrieves value properties, one that retrieves nonvalue properties, and one that calls both methods.
Listing 3.7. Methods for retrieving all properties of a test object
Java public void printValueProperties(TestObject testObject) { Hashtable valueProperties = testObject.getProperties(); Enumeration valuePropNames = valueProperties.keys(); Enumeration valuePropValues = valueProperties.elements(); while (valuePropNames.hasMoreElements()) { System.out.println(valuePropNames.nextElement() + ":" + valuePropValues.nextElement()); } } public void printNonValueProperties(TestObject testObject) { Hashtable nonValueProperties = testObject.getNonValueProperties(); Enumeration nonValuePropNames = nonValueProperties.keys(); Enumeration nonValuePropValues = nonValueProperties.elements(); while (nonValuePropNames.hasMoreElements()) { System.out.println(nonValuePropNames.nextElement() + ":" + nonValuePropValues.nextElement()); } } public void printAllProperties(TestObject testObject) { printValueProperties(testObject); printNonValueProperties(testObject); }
VB.NET Public Sub printAllProperties(ByVal testObject As TestObject) printValueProperties(testObject) printNonValueProperties(testObject) End Sub Public Sub printValueProperties(ByVal testobject As TestObject) Dim valueProperties As Hashtable = testobject.GetProperties Dim valuePropNames As ICollection = valueProperties.Keys Dim valuePropValues As ICollection = valueProperties.Values Dim enumPropNames As IEnumerator = valuePropNames.GetEnumerator() Dim enumPropVals As IEnumerator = valuePropValues.GetEnumerator() Do While enumPropNames.MoveNext And enumPropVals.MoveNext Dim currentProp As String = enumPropNames.Current Dim currentPropVal As Object = enumPropVals.Current If TypeOf currentPropVal Is Object Then If Not (TypeOf currentPropVal Is String) Then currentPropVal = currentPropVal.ToString End If End If Console.WriteLine(currentProp + ":" + currentPropVal) Loop End Sub Public Sub printNonValueProperties(ByVal testobject As TestObject) Dim valueProperties As Hashtable = testobject.GetNonValueProperties Dim valuePropNames As ICollection = valueProperties.Keys Dim valuePropValues As ICollection = valueProperties.Values Dim enumPropNames As IEnumerator = valuePropNames.GetEnumerator() Dim enumPropVals As IEnumerator = valuePropValues.GetEnumerator() Do While enumPropNames.MoveNext And enumPropVals.MoveNext Console.WriteLine(enumPropNames.Current + ": " + enumPropVals.Current) Loop End Sub