Adding Parameters for Flexibility: Editing the Scripts


This lesson describes how to add parameters, using the script editor included with JavaStar. The JavaStar Script Editor includes a button for saving and compiling the modified code, making it convenient for this exercise. You can use any editor you like to edit the scripts--just make sure you compile the code when you are done.

This section covers:

Editing OpenFile

  1. In the JavaStar main menu, click Edit Test Script.

  2. Open OpenFile.java for edit.
    Next to the Script name field, click the Browse button. Locate and select OpenFile.java. Double-click the filename or click Open.

    JavaStar Script Editor

  3. Scroll down to the play method.
    The play method opens with the line:

  4. Replace the test.db reference with args[0].
    The current line reads:
    Change "test.db" to args[0]. Leave the "." parameter before the filename so that JavaStar knows to look for the database file in the current directory. Remove the quotation marks. The new line should read:

  5. Edit the synchronize operation to handle a variable filename.
    Right now, this script checks the Name Database header in the window to see that it reads Name Database - test.db. This is done with this line:
    You accommodate the variable filename in this comparison by changing "Name Database - test.db" to "Name Database - " + args[0]. Be sure to change it in both places on this line--in the member() and waitFor() method calls--and include the plus-sign.

  6. Click Save & Compile.
    JavaStar should return a message that it compiled the script successfully. If not, check for errors--make sure you didn't accidentally delete a parenthesis or comma, or leave out the plus-sign.

Editing EnterFieldData

  1. In the Script Editor, open EnterFieldData.java for edit.

  2. Scroll down to the play method.
    The play method opens with the line:

  3. Edit the first data entry line.
    Find the line:
    On this line, change "Count von Count", 0, 0 to args[0] so that it reads:
    Note that in addition to replacing the text string with the argument, you're deleting the position values (0,0) that follow. The JavaStar API provides two versions of the of the typeString() method--one requiring the string to replace, selection start, and selection end parameters, and the other requiring only the string to replace. Here you're replacing the default version recorded in the script with a simpler method call. That just replaces the entire contents of the text field.

  4. Edit the remaining data entry lines:

    1. Change the reference to "123 Numbers Lane", 0 ,0 to args[1].
      Find:
        NameData.MainWin.address1TextField().typeString("123 Numbers Lane", 0, 0);
        

      Replace with:
        NameData.MainWin.address1TextField().typeString(args[1]);
        

    2. Change the reference to "Transylvania", 0 ,0 to args[2].
      Find:
        NameData.MainWin.address2TextField().typeString("Transylvania", 0 ,0);
        

      Replace with:
        NameData.MainWin.address1TextField().typeString(args[2]);
        

    3. Change the reference to "01-2-34567", 0 ,0 to args[3].
      Find:
        NameData.MainWin.telephoneTF().typeString("01-2-34567", 0, 0);
        

      Replace with:
        NameData.MainWin.telephoneTF().typeString(args[3]);
        

    4. Change the reference to "count@count.com", 0 ,0 to args[4].
      Find:
        NameData.MainWin.emailTextField().typeString("count@count.com", 0, 0);
        

      Replace with:
        NameData.MainWin.emailTextField().typeString(args[4]);
        

    5. Change the reference to "Bean Counter", 0 ,0 to args[5].
      Find:
        NameData.MainWin.otherTextField().typeString("Bean counter", 0, 0);
        

      Replace with:
        NameData.MainWin.otherTextField().typeString(args[5]);
        

  5. Click Save & Compile.

Editing DefineSearch

  1. In the Script Editor, open DefineSearch.java for edit.

  2. In the Play method, edit the line that specifies the search string.
    Find the line:
    (This code appears as a single line in the Script Editor.)
    Replace the line with:

    Note - Argument references always start at 0 within a script. The argument value refers to the arguments position in the array of arguments passed to the script at runtime. It does not refer to an absolute position for all arguments passed into the JST.

  3. Save and compile.

Editing GetSearchResults

  1. In the Script Editor, open GetSearchResults.java for edit.

  2. In the Play method, edit the line that selects the Count von Count record by name.
    Find the line:
    Replace "Count von Count" with args[0] so the line reads:

  3. Edit the code to remove the selection position.
    Currently the code passes a position and a string to the select method. The JavaStar API provides another version of this method that selects an item using only the string. If you now plan to pass the string name to the script, you don't know what the position of that string will be within the list when this is executed as part of a test, so you need to perform the selection based solely on the string value.
    To make this modification, delete 0, so the line reads:

  4. Save and compile.

Editing VerifyRecord

  1. In the Script Editor, open VerifyRecord.java for edit.

  2. In the Play method, edit the line that selects the Count von Count record by name.

    1. Find the line:
        NameData.MainWin.nameTextField().verify(this,"Count von Count", "Verify expected field text");
        

    2. On this line, change "Count von Count" to args[0] so that it reads:
        NameData.MainWin.nameTextField().verify(this, args[0], "Verify expected field text");
        

  3. Edit the remaining verification lines.

    Replace With
    "123 Numbers Lane" args[1]
    "Transylvania" args[2]
    "01-2-34567" args[3]
    "count@count.com" args[4]
    "Bean Counter" args[5]

  4. Save and compile.



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