- 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
Waiting for Test Objects to Come into Existence
When GUI objects aren’t rendered in a timely manner, you simply want your script to wait until they appear. Chapter 1 discussed the pros and cons of using global delay settings (for example, using Rational Functional Tester’s playback settings). You also just learned about using the sleep() method in the previous section. This is helpful because the delay is specific to a script, releasing your dependencies on the global tool settings. However, it is a static delay. It waits until a specified number of seconds elapse, regardless of whether the GUI object appears sooner or not. This section discusses a happy medium between the global delay settings and the sleep() method.
The Rational Functional Java API provides a useful waitForExistence() method or WaitForExistence() function if you’re using VB.NET. In either case, it comes in two variants. One is dependent upon global playback settings. The other is script-specific.
To use this method, you need to call it from a test object. Simply put, you need to tell your script which object to wait for. You can either type the name of the object, followed by opening and closing parentheses, directly into your code and hit the period key, or you can simply place your cursor in the script where you wish the command to go, right-click the test object in the Test Objects folder (within the Script Explorer view), and click Insert at Cursor from the displayed menu. Either of these two options displays an IntelliSense drop-down window (some people refer to this as “code complete”). This window provides you with a list of methods and functions that you can call. Typing the word wait shows you the methods and functions that begin with wait. The waitForExistence() method is among them. Figures 3.3 and 3.4 show how to call the waitForExistence() method, using the Eclipse and .NET Studio environments, respectively.
If you use the Java language, you need to append a semicolon at the end of the line. If you use the VB.NET language, you are set and there is nothing further to do. Listing 3.2 shows you how the command looks in the same Rational Functional Tester script, using Java and VB.NET, respectively.
Listing 3.2. Using waitForExistence() / WaitForExistence() in a script
Java public void testMain(Object[] args) { startApp("ClassicsJavaA"); // USE waitForExistence() ON MAIN WINDOW TO MAKE // SURE IT IS THERE BEFORE PERFORMING VERIFICATION classicsJava().waitForExistence(); // Frame: ClassicsCD tree2().performTest(VerifyComposerListVP()); classicsJava(ANY,MAY_EXIT).close(); }
VB.NET Public Function TestMain(ByVal args() As Object) As Object StartApp("ClassicsJavaA") ' USE WaitForExistence() ON MAIN WINDOW TO MAKE ' SURE IT IS THERE BEFORE PERFORMING VERIFICATION ClassicsJava().WaitForExistence() ' Frame: ClassicsCD Tree2().PerformTest(VerifyComposerListVP()) ClassicsJava(ANY,MAY_EXIT).Close() Return Nothing End Function
In Listing 3.2, ClassicsJava() is a test object, representing the main window of the application. You call this test object’s waitForExistence() method to tell your script that it needs to wait until this object appears, prior to executing the next line. The value of this method is that it immediately continues execution of the script after the test object renders on the screen (versus waiting a static period of time). However, this particular variant of the method is dependent upon global delay settings accessed from Rational Functional Tester’s primary playback settings. Figures 3.5 and 3.6 show these options for Java and VB.NET.
The last two settings are specific to the waitForExistence()/WaitForExistence() method. If you want to change how long it waits or how often it checks for a test object’s existence, you simply override the defaults and supply your own values. You should note that using this variant of the method keeps you dependent upon Rational Functional Tester’s global settings.
To become script-specific, you would use the second variant of this method—waitForExistence(double arg0, double arg1). This enables you to provide the maximum amount of time script playback waits for the object to render (that is arg0). You also enter the amount of time it waits between attempts to find the test object (that is arg1). You specify these two values using seconds. Using this version of the method keeps your scripts independent from the values in the global delay settings for the waitForExistence() method. Listing 3.3 shows how this would look in both Java and VB.NET.
Listing 3.3. Using the script-specific version of waitForExistence()/WaitForExistence() in a script
Java public void testMain(Object[] args) { startApp("ClassicsJavaA"); // USE waitForExistence() ON MAIN WINDOW TO MAKE // SURE IT IS THERE BEFORE PERFORMING VERIFICATION // WAIT A MAXIMUM OF 180 SECONDS/3 MINUTES // CHECK FOR THE MAIN WINDOW EVERY 2 SECONDS classicsJava().waitForExistence(180.0, 2.0); // Frame: ClassicsCD tree2().performTest(VerifyComposerListVP()); classicsJava(ANY,MAY_EXIT).close(); }
VB.NET Public Function TestMain(ByVal args() As Object) As Object StartApp("ClassicsJavaA") ' USE WaitForExistence() ON MAIN WINDOW TO MAKE ' SURE IT IS THERE BEFORE PERFORMING VERIFICATION ' WAIT A MAXIMUM OF 180 SECONDS/3 MINUTES ' CHECK FOR THE MAIN WINDOW EVERY 2 SECONDS ClassicsJava().WaitForExistence(180.0, 2.0) ' Frame: ClassicsCD Tree2().PerformTest(VerifyComposerListVP()) ClassicsJava(ANY,MAY_EXIT).Close() Return Nothing End Function
You can see that your script now waits for the main window (for example, classicsJava) of the application for a maximum of 180 seconds, searching for it every two seconds.
Of the three synchronization topics that you have seen thus far, this is the most desirable. It provides you with the ability to have your scripts wait until a test object appears versus waiting for a static amount of time to elapse. Further, it enables you to become script-specific, allowing any tester on your team to run it without having to adjust global playback delay settings.