- 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
Obtaining Data from a Test Object That the Rational Functional Tester Verification Point Wizard Does Not Capture
This large topic is discussed here and explored in more detail in other sections. Several techniques are used to deal with this challenge, the simplest of which from a coding perspective is to try to get the data into the Clipboard. If this can reliably be done, you can get the data into a script variable (though this technique might not be your first choice).
As discussed in the “Working with the Clipboard Object” section in this chapter, Rational Functional Tester gives you access to the system Clipboard. This provides access to the two methods used for manipulating the Clipboard: setText() and getText(). These enable you to work with test objects that Rational Functional Tester has difficulty extracting data from.
The following reference example is an open document in Microsoft Word. If you point the Rational Functional Tester Verification Point Wizard at a Microsoft Word document, it does not see the contents of the document. You can, however, get the data into a variable in your script by using the keyboard and a little code.
First, you click the document to place keyboard focus on it. Then you use the keyboard to put the data into the Clipboard (versus trying to manipulate the Word menu). The Rational Functional Tester API has two methods to work with the keyboard: inputChars() and inputKeys(). Both take string arguments, but there’s a key difference between them: inputChars() treats every character it has passed literally, and inputKeys() assigns special meaning to certain characters, as shown in Table 3.9.
Table 3.9 Characters with Special Meanings in Scripts
Apply Ctrl to the next character.
Apply Alt to the next character.
Apply Shift to the next character.
Passing inputKeys ^a^c causes Rational Functional Tester to press Ctrl+A (select all) and then Ctrl+C (copy), copying the contents of the entire document to the Clipboard. After the data is copied to the Clipboard, you are home free. To get the data in the Clipboard, you call getSystemClipboard().getText(). This is detailed in Listing 3.13.
Listing 3.13. Using the Clipboard to get data from a test object
Java microsoftWordDocumentwindow().click(); ((TopLevelSubitemTestObject) microsoftWordDocumentwindow() .getTopMappableParent()).inputKeys("^a^c"); String text = getSystemClipboard().getText(); System.out.println(text);