You often record tests using specific values, for input and expected values, which become hard-coded (literals) into the script. Even if you choose certain test data to be variable using the data driven test wizard, you may not realize other hard-coded values that will later need to be changed. You can change static test data in a script into dynamic values by adding datapool variables. You can use datapools for both test input and for expected values (verification points).

You can add a data driven code (commands that input test data from a datapool) using the Insert Data Driven Actions wizard as follows:

1. Get the application under test to the appropriate point where the test data should be added. You might want to play back the test script in debug mode, breaking (pausing) at the data input form or dialog.
2. Position the cursor on a blank line in the test script where you want to add the data driven commands.
3. Select the menu Script > Insert Data Driven Commands, which will open the Data Driven Commands wizard as shown in below Figure. This is essentially the same as going into recording mode except that you will not see the recorder monitor.

Insert data driven actions wizard

4. Complete the wizard to select the data input objects. You can find more about the Data Driven Commands wizard in the online Help.

If you had not already created or added a datapool for the test script, then a new one will be created. Note that this wizard will add new lines of code to set (input) datapool values to the test object selected in the wizard. If you had already recorded typing or selecting values then the script will set the values twice. In this case, you can either delete the redundant script lines, or you can replace the literal test input values as described in the following paragraphs.

If you already have a shared datapool then you can add it to your test script as follows:

1. Right-click on the Test Datapool folder in the Script Explorer and select Associate with Datapool.
2. Select one datapool, and then click OK. You can then see the datapool listed in the Script Explorer. You can associate only one datapool with a test script.

At this point, you have associated only the datapool with the test script. You need to replace the literal strings (hard-coded values) with values from the datapool. You do this as follows:

1. Select the menu Script > Find Literals and Replace with Datapool Reference. Script menu selection Find Literals and Replace with Datapool will be enabled if you have a script open that already has a datapool associated with it. Otherwise, this menu line is disabled.
2. In the Datapool Literal Substitution window, as shown in below Figure, select the variable (column) you want to use from the Datapool Variable drop-down list.

Replacing literals with datapool values

3. Click Find repeatedly until the correct value is highlighted in the script and then click the Replace button.
4. Repeat step 2 until you have replaced all occurrences in the script.
5. You can select another Datapool variable from the drop-down list and repeat steps 2 through 3 for other values.
6. Click Close when you have finished replacing values.

You might already have a datapool with some substitutions for script values, but realize you need to replace additional literal values. You can repeat steps 3 through 6 to add more datapool substitutions to your test script at any time.

How to Manually Add Script Code

So far, we have discussed different ways to add recorded lines and test objects, verification points, and datapool commands to a test script using wizards and other recording or capture techniques. If you are familiar with the test script syntax, then you might find it useful to manually add these things directly to the script.

Adding Test Steps

If you have already captured test objects in a map, you can add them to your script along with actions for the test to perform as shown in below Figure, or with verification points to check. You do this as follows:

1. Position the cursor on a blank line in the script where you want to add the new test step.
2. Right-click either a verification point or a test object in the Script Explorer and select Insert at Cursor.

Adding an existing test element to the script

You now have an incomplete reference to either a test object or a verification point in the script. If you add an object, you need to then select an operation (test action) to perform. If you add a verification point, you need an object and not just any object but one capable of returning the expected value. Complete the test script statement for either a test object or verification point:
  • For a test object, select an operation from the drop-down list of methods. For example, select click() to make the script click on the test object during test playback. This action is added after the object reference.
  • For a verification point, you must add a test object reference. You can either type or copy the object name, or you can add it from the Script Explorer using Insert at Cursor. This object must be added before the performTest operation.
With both Java and Visual Basic .NET scripting, if you position your cursor at the end of a test object call (class), just after the parenthesis, and type a period, you will see the list of methods available for that class. If you add the object from the Script Explorer, you might have to press Backspace over the period and retype it. If you then select the method from the list, the editor adds the operation to your script. Figures 1.32 and 1.33 show this for both Eclipse and Visual Studio.

Selecting an operation for a test object in Java

Selecting an operation for a test object in Visual Basic .NET

For Java, you also have to type the ending semi-colon yourself.

Adding Programming Code to Your Tests

Rational Functional Tester scripts are implemented in either Java or Visual Basic .NET and are in fact just programs with specific testing functions. Therefore, in addition to adding test steps as described in the previous section, you can also add virtually any programming devices or functions that you would develop for any other Java or Visual Basic program. This includes not only simple looping or conditional constructs, but also calls to more elaborate programming classes. The constraints to this are that the test script must be an extension of com.rational.test.ft.script.RationalTestScript and they must be executed from Rational Functional Tester execution mechanisms.

Other Script Enhancements

So far, we have discussed several ways to edit test scripts to modify, complete, enhance, or extend their capabilities. Another purpose of editing tests is to improve their readability and potential reuse. This is done by adding comments and descriptions, naming or renaming test elements, and possibly restructuring test scripts into smaller modular tests.

Comments and Descriptions

In a given testing effort, you create many tests, object maps, datapools, and other test elements. There are most likely be other people who have to use or reference these same test artifacts. Comments and descriptions should be added to test artifacts and elements to explain their purposes, usages, and any other relevant information. This makes it much easier for someone else other than the test’s creator to understand. This also increases the value of the tests as software development artifacts.

You add comments directly into the test scripts. You can add as many as you like without affecting the execution, and in general, the more, the better. You can add comments during recording using the Script Support Functions, or at any time after recording. Here are examples of comments in each scripting language:

// This is a comment in Java
' This is a comment in Visual Basic

If you are using Rational Functional Tester with Java scripting, then you can also use Javadoc documentation in your test scripts. Some of this is generated automatically at the beginning of each test script in Java, and you can add more text or tags if you need. More information on Javadoc can be found in the Rational Functional Tester Help.

* Description : This is Javadoc content
* @author You

You can add descriptions for certain test elements including test scripts, test objects, and verification points. Descriptions for test scripts are simply Javadoc comments. You can add a description for test objects by opening the object map, selecting an object, and then selecting Test Object > Description Property from the menu, as shown in below Figure.

Adding a description for a test object

You can add a description for a verification point by opening the verification point and editing the description property, as shown in Figure 1.35.

Adding a description for a verification point

Naming and Reuse

In addition to adding comments and descriptions, you can improve the readability of a test by renaming test elements to more accurately reflect their meaning or purpose. This is perhaps most important for verification points because you interpret test results largely from these. You have a much harder time understanding a test log or report that has a failure on _1695Text than one with a failure on OrderTotal. You might also consider renaming test objects, datapool variables (columns), and test scripts."Names for Your Test Elements"

Names for Your Test Elements

Although this discussion is about renaming things, the best time to name your test elements, especially verification points, is when you first record or develop your test.

Renaming Objects and Verification Points

You can rename test objects and verification points by right-clicking the item in the Script Explorer and selecting Rename, as shown in below Figure. This automatically renames the reference to the object or verification point in the test script.

Renaming script elements in the Script Explorer

Renaming Datapool Variables

You may need to rename datapool variables, especially if they are generated by the test data wizard, which copies the test object names. The variables (columns names) are used to reference the values in the script, and the name should reflect the real value or purpose. You can rename a datapool variable by opening the datapool (or the script for a private datapool), clicking on the variable name (column header), and entering a new name for the variable as shown in below Figure. This automatically renames the reference to the datapool variable in the test scripts.

Renaming datapool columns

If you rename a variable in a shared datapool, the Rational Functional Tester automatically lets you know which scripts are updated with the new name as shown in below Figure.

Updating all scripts with a new datapool variable name

Renaming Scripts

You might want to rename a test script to better reflect its function or purpose or to comply with project naming conventions. You can do this by right-clicking the item in the Project Explorer and selecting Rename. This will automatically rename all the hidden files associated with the test script, such as the helper and verification point files.