Home > Articles > Programming

This chapter is from the book

Working with the Clipboard Object

Rational Functional Tester gives you a type of verification point that works with textual data on the Windows Clipboard. You might ask, “Why would I want to use the Windows Clipboard with Rational Functional Tester?” You want to do this for several reasons, but in most cases, it comes down to an easy way to get around object recognition difficulties. Often you need a test script to do something, such as checking a value, and if the normal way to do this (in this example, using a verification point) doesn’t immediately work, using the Clipboard might be the fastest way to make it work.

Getting a test script to work reliably with the application interface you are testing often comes down to robust object recognition. Dealing with object recognition is covered in more detail in Chapter 8, “Handling Unsupported Domain Objects,” and in Chapter 9, “Advanced Rational Functional Tester Object Map Topics.” In some cases, you want to follow that information to fully implement Rational Functional Tester’s recognition and interface with the test objects. The reason that you might not follow that approach, but instead use the Clipboard, usually has to do with how quickly you need to get something to work. Do not think of the Clipboard approach as a work-around or interim solution, though, as it is often the most effective and efficient way to automate a test procedure.

You use the Clipboard for handling object recognition with Rational Functional Tester, which specifically means getting, setting, or otherwise using values from the application under test or associated applications. You might do this for any of the following reasons:

  • Verifying some functionality or output from the application
  • Controlling the timing of your test scripts
  • Manipulating the flow of the test procedures
  • Logging additional information into the test results

When you use this technique, you record steps to copy and/or paste data to the Clipboard, and then use it as a kind of data source. The Clipboard can be used as an intermediate place to hold data from the application under test, and Rational Functional Tester can get data from the Clipboard or send data to it. You can also test anything that gets onto the Clipboard with a verification point.

There are three general approaches to using the Clipboard with automated testing:

  1. Verifying some value from the application
  2. Getting some value from the application to use in the test
  3. Sending some value from the test to the application

For each of these tactics, you usually record some steps to select and copy data from some GUI, and then add some Clipboard actions into the test script. This chapter describes several examples, with specific steps, for each of the three approaches.

You do not have to manually code the methods previously described; you can simply use the Recorder toolbar to generate the Clipboard code. You add these Clipboard actions much like you would other kinds of verification points or script actions. The wizards for adding Clipboard actions into a test are found in the Script Support Functions on the Recorder toolbar.

Figure 3.9 illustrates how to access the Clipboard actions from the Rational Functional Tester Recorder toolbar.

Like all of Rational Functional Tester’s script support functions, you need to click Insert code to add the commands to your test script.

The first consideration you have when using the Clipboard is determining exactly how you can select and copy, or perhaps paste, data to and from the Clipboard. In some cases, you might select text using a mouse click and drag, followed by a Ctrl+C keyboard shortcut. In other cases, you might have a menu option in the application under test to copy information to the Clipboard. You might have to use a combination of interactions with the application under test, the operating system, various keyboard inputs, and right-clicking or other menu selections.

The exact method used to get data to and from the Clipboard is of critical importance to the resilience of the automated test script. Some of the steps that you record, such as clicking and dragging, rely on coordinates within an object. These methods are therefore more susceptible to playback failure. You should always strive to record actions that are most likely to replay in the maximum (and reasonable) test environments and playback conditions.

The following looks at several related examples of creating test scripts that use the Clipboard and starts with one possible scenario of creating automated test scripts leveraging the Clipboard. This is not intended to be the most realistic scenario possible, but it illustrates different ways of using the Clipboard with Rational Functional Tester.

In this scenario, you have to test a system that includes an older reporting component. Rational Functional Tester can recognize only parts of this component’s interface and doesn’t seem to automatically capture a particular value: the current job number. This alphanumeric string has to be checked against expected values and it is used as an input value to another test. Finally, because this is a lower priority test case, you cannot spend too much time developing the test script.

You can figure out how to get Rational Functional Tester to recognize the objects and properties to access the job number value, but that might take time. You realize that the job number field can be easily selected and copied to the Clipboard, so you use the Clipboard to quickly get a working automated test script.

First, you create a Clipboard verification point for the job number value. This differs from other verification points in that you do not directly access the object or properties to get the value. You can record a test script to do this as follows:

  1. Record the initial steps of the test script, getting to the point where the job number (the value we want to verify) is displayed.
  2. Select the job number text and copy it to the Clipboard. A robust method for doing this could be tabbing to the field if the application GUI is not likely to change.
  3. Open the Script Support Functions from the Recorder toolbar, and click Clipboard > Verification Point Tab (see Figure 3.10). You will see the value that was copied in the verification value field.
  4. Enter a descriptive name for the verification point in the VP Name field.
  5. Click Insert Code, and then click Close to exit the Script Support Functions and return to recording mode.

At this point, the script contains the code for a Clipboard verification point, as shown here:

getSystemClipboard().performTest(JobNumberVP());

You now get the job number value and store it in a local variable within the test script. You can record a test script to do this as follows:

  1. Record any initial steps of the test script or continue the previous example, getting to the point where the job number (the value we want to capture) is displayed.
  2. Select the job number text and copy it to the Clipboard. If you combine this with the previous verification point example, you can skip directly to the next step.
  3. Open the Script Support Functions, and click Clipboard > Assign Text Tab (see Figure 3.11).
  4. Enter a descriptive name for the script variable in the Variable Name field, and then select Precede variable assignment with type declaration.
  5. Click Insert Code, then click Close to exit the Script Support Functions and return to recording mode.

At this point, the script contains the code for a new string variable to hold whatever was copied to the Clipboard, as shown here:

String JobNum = getSystemClipboard().getText();

This variable can now be used for any number of reasons within the test.

You also have the ability to send data to the Clipboard. You might want to do this if you need to test your application’s paste function. If you set the data in the Clipboard immediately before performing a paste function, you can ensure that you know what should be pasted into your application. Another reason you might do this is for continuity. For example, if one piece of your application provides a record number, you might wish to store it in a variable (for example, JobNum in the preceding line of script). You can then use this variable to paste into the piece of your application that does a record lookup. In any case, setting the Clipboard is easy. You simply use the following line of code in your script:

getSystemClipboard().setText(JobNum);

Returning to the scenario, you now need to enter a new job number, different from the current one, into the application. You want to paste this value from the Clipboard into the application GUI field. You therefore need to set the value contained in the Clipboard. You might calculate or look up the particular value in several ways, but for this example, you simply show a static string. You can record a test script to do this as follows:

  1. Record any initial steps of the test script or continue the previous example, getting to the point where you enter the new value.
  2. Open the Script Support Functions, and then click Clipboard > Set Text Tab. The value field on this tab is empty (shown in Figure 3.12).
  3. Enter the value that you want to send to the Clipboard. You might simply enter a placeholder value when you are recording and then replace it in the script to some calculated or retrieved variable (for example, JobNum).
  4. Click Insert Code, then click Close to exit the Script Support Functions and return to recording mode.

At this point, the script now contains the code to set the value of the Clipboard, as shown here:

getSystemClipboard().setText("SomeValue");

As mentioned in step 3, you might want to replace the hard-coded value entered during recording mode (IncrementedJobNumber) with some variable or other value. An incomplete example of this is shown in following code snippet.

// retrieve JobNum from the getText() method
String JobNum = getSystemClipboard().getText();
...
//replace recorded setText() value to JobNum variable
getSystemClipboard().setText(JobNum);

Instead of using the recorder, you might want to manually add the code for Clipboard interactions. This is easy to do because you would have to add only one line of code for each type of Clipboard action, not counting the lines of script to select, copy, or paste the data. An example of a line to capture something to the Clipboard is:

someTextField().inputKeys("{ExtHome}+{ExtEnd}^c");

The preceding line of code performs the following steps:

  1. Press the Home key (that is {ExtHome})—This places the cursor at the beginning of the field.
  2. Perform a Shift+End keystroke combination (that is +{ExtEnd})—This selects everything in the field (from the beginning to the end of it).
  3. Perform the Ctrl+C keystroke combination (that is ^c)—This executes the copy function of the application.

    After this, you can manually add the following line to your script for a Clipboard verification point:

    getSystemClipboard().performTest(myClipVP());

The Rational Functional Tester API has a public interface IClipboard in the com.rational. test.ft.script package that defines the set of methods exposed for a Clipboard. The three methods in this are:

  • getText—Returns a copy of the text from this Clipboard.
  • setText—Copies the supplied text value to this Clipboard.
  • performTest:—Captures, compares, and logs active Clipboard text against the supplied baseline data.

There are several things to consider when using the Clipboard with Rational Functional Tester:

  • The Clipboard is often used to verify, get, and set data without mapping and directly accessing objects and properties. This can make script maintenance more difficult because you do not have an object map of the objects containing the values.
  • The steps used to capture data to the Clipboard or paste data from it might be less resilient and more susceptible to playback problems. This can be a risk if you have to resort to click and drag or other actions using coordinates.
  • There is a risk with the system Clipboard that scripts might not play back the same way in different test environments. Although this should ideally work the same way on Windows and Linux operating systems, it can also fail on the same operating system due to different conditions in the test environment.
  • + Share This
  • 🔖 Save To Your Account