Adding Parameters for Flexibility: Editing JSTs to Use Parameters


Now you'll go into Compose Test to set the JSTs to accept and pass parameters. You'll be working with seven parameters that you'll pass to the acceptance test at runtime:

$0 Name
$1 Address 1
$2 Address 2
$3 Phone
$4 Email
$5 Other
(for the Other field in the name database record)
$6 Test database filename

A Note About Argument Identifiers

The argument numbers you specify in the Edit Node dialog for a particular node represent the positions of the arguments that node will inherit from its parent node. These numbers do not reflect the position numbers used by the individual scripts. Each script takes whatever arguments you pass to it and numbers them sequentially within its own args[] array, starting at zero.

Because this exercise uses parameters that are passed from one node to the other in the same order, it's hard to see what this would mean, except in the case of OpenFile. The OpenFile script uses the last parameter passed to Acceptance.jst at runtime--args[6]. When you specify the argument number in the Test Composer, you refer to argument #6. But the OpenFile script references args[0] in the actual code, because it takes whatever parameters you pass it (whether it's args[0], args[3], or args[6]) and renumbers them starting at args[0].

This keeps your script independent of the JST's implementation. You don't have to change a script depending on how you want to get nodes from the parent. All the Edit Node dialog needs is information on which arguments you want it to get from the parent, and it will do the rest.

Editing the OpenFile Node

To edit the OpenFile node pass parameters to the script:

  1. In the JavaStar main menu, select Compose test.

  2. Load Acceptance.jst.
    Click the Browse button. Locate Acceptance.jst in the Tutorial directory, then click Open.

  3. Select the OpenFile node and click the Edit button.
    The Edit Node dialog opens.

  4. In the Edit Node dialog window, select Parent parameter from the pull-down menu.
    The Value field changes to Argument #.

  5. In the Argument # field, type 6.
    For this node, you'll use the seventh parameter passed to the acceptance test, after the first six field values. The seventh parameter occupies position 6 in the args array, since the first parameter is numbered 0.

  6. Click the Add (after) button.
    This adds the parameter to the list. This is the only parameter you need for this script.

  7. Enter a comment to describe the parameter.
    In the Comments field, type $6 = Database filename.

    Edit Node dialog for OpenFile

  8. Click Apply and click Close.

You have now set up this node of the test so that it takes the seventh argument passed to Acceptance.jst and passes it to its own script. The script, in turn, refers to the single passed parameter as args[0].

Editing the AddRecord .jst Node

Now you need to edit the AddRecord node to prepare it to pass the correct parameters to EnterFieldData.

  1. Select the AddRecord.jst node and click the Edit button.
    The Edit Node dialog opens.

  2. In the Edit Node dialog window, select Parent parameter from the pull-down menu.
    The Value field changes to Argument #.

  3. In the Argument # field, type 0.

  4. Click the Add (after) button.
    This adds the parameter to the list.

  5. Add arguments 1 through 5.
    Type the next number, then click Add (after). Continue until you have six parameters, numbered 0 through 5.
    If you make a mistake, you can correct it by double-clicking on the parameter from the Parameters list and using the Update and Delete buttons.

  6. In the Comments field, list each argument and the field it maps to.
    This is an important step--if you don't note the purpose of each argument here and later forget, you'll need to read the script code to decipher it.
    Type:
    $0 Name
    $1 Address 1
    $2 Address 2
    $3 Phone
    $4 Email
    $5 Other

    You're going to need to use these same comments in other nodes. You can save yourself some typing by selecting this text and copying it to the clipboard for later use.
    The Edit Node dialog should look like this:

    Edit Node for EnterFieldData, after parameters added

  7. Click Apply.

  8. In the Edit Node dialog, click Close.

  9. Click Save to record changes to Acceptance.jst.
    JavaStar informs you that Acceptance.jst exists and asks you for confirmation to overwrite the file.

  10. Click OK.

Editing EnterFieldData Node

  1. With the Acceptance.jst open, open AddRecord.jst.
    Click on the AddRecord.jst node to select it. Click Open.

  2. Select the EnterFieldData node and click the Edit button.
    The Edit Node dialog opens.

  3. Add arguments 0 through 5, one for each of the text fields.

  4. Add a comment describing what each of these parameters maps to.
    If you copied the comments from EnterFieldData to the clipboard, you can paste the text in.

  5. Click Apply to record your edits.

  6. Close the Edit Node dialog.
    Click Close.

  7. In the Test Composer, click Save.

Editing VerifySearch.jst

Because you have the Acceptance.jst open already, it is easiest to define parameters for VerifySearch.jst next.

  1. In AddRecord.jst, click the Back button to navigate back to Acceptance.jst.
    The Back button is located in the Test Composer, above the Comments field.

  2. Select the VerifySearch node and edit.

  3. Add six parent parameters (0-5).

  4. Paste or re-type the comments you used for the EnterFieldData node.

  5. Click Apply.

  6. In the Edit Node window, click Close.

  7. In the Test Composer, click Save.

Editing the DefineSearch Node

Now you need to edit the nodes within VerifySearch.jst. You can start with DefineSearch.

  1. Navigate to VerifySearch.jst.
    With the VerifyName node still selected, click the Open button. This loads VerifySearch.jst.

  2. Edit the DefineSearch node.
    Click on DefineSearch node. Click the Edit button.

  3. For Argument #, type 2.
    This test uses the value for the Address2 field, which is the third parameter (args[2]) you pass to VerifySearch.jst.

  4. Click Add (After).

  5. In the Comment field, type Value to search for.

  6. Apply the changes and close the window.

Editing the GetSearchResults Node

  1. Still in VerifySearch.jst, click on GetSearchResults node.

  2. Edit the GetSearchResults.
    Click on GetSearchResults node. Click the Edit button.

  3. For Argument #, type 0.
    This test uses the record name, the first parameter passed to VerifySearch.jst.

  4. Click Add (After).

  5. In the Comment field, type Name to select.

  6. Apply the changes and close the window.

Editing the VerifyRecord Node

  1. Click on VerifyRecord node.

  2. Click Edit.

  3. Add arguments 0-5.

  4. Add comments to describe the six arguments.

  5. Apply the changes and close the window.

  6. Save the JST.

  7. Close the Test Composer.

The acceptance test is now set to take six parameters at the command line and pass these down to the three scripts you edited.




Send feedback to JavaStar-feedback@suntest.com
Copyright © 1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303. All rights reserved.