Generating Declarations: Modifying Declarations to Use Abstracted Names


The code for the Name Database application does not define names for the text fields. In lieu of names, JavaStar refers to them by their order--for example, textField1, textField2, and textField3.

Ideally, the code would name the components. However, if the code you're testing uses default names for text fields, you can add your own by providing abstracted names in the declarations file. You do not have to do this in order to gain benefits from using declarations, but this provides an extra bonus. Using names makes scripts easier to modify, and logs easier to decipher. Updating the declarations to reflect GUI modifications is also more straightforward.

Note - When you change names in a declarations file, be sure to search to find any additional references to the original name, and update these, too.

Whether you use abstracted names or not, you always need to save and compile declarations after generating them. JavaStar creates on the .java files when you generate declarations, not the .class files.

Editing MainWin Declarations

  1. From the JavaStar main menu, select Edit Test Script.

  2. Load the MainWin.java declarations file.
    You'll find this in the NameData subdirectory of tutorial.

  3. Locate the declaration for the first text field.
    Scroll down through the file until you find the line:

    Note - The code to change and the replacement code is set in bold type for these examples. It won't appear in bold in the Script Editor window.

  4. Replace the default textField name with a field-specific identifier.
    Change textField() to nameTextField(). Your code should read:

  5. Edit the declarations for the other four text fields.

    1. For the second text field, replace textField2 with address1TextField.
      Replace:
        /* TextField */
        public static JSComponent textField2(){
        return Namedb().member("java.awt.TextField", 1);
        }

      With:
        /* TextField */
        public static JSComponent address1TextField(){
        return Namedb().member("java.awt.TextField", 1);
        }

      Note - When replacing "textField", don't forget to include the number that follows it.

    2. For the third text field, replace textField3 with address2TextField.
      Replace:
        /* TextField */
        public static JSComponent textField3(){
        return Namedb().member("java.awt.TextField", 2);
        }

      With:
        /* TextField */
        public static JSComponent address2TextField(){
        return Namedb().member("java.awt.TextField", 2);
        }

    3. For the fourth text field, replace textField4 with emailTextField.
      Remember that the Telephone field is no longer a TextField object, so we're not editing that declaration.
      Replace:
        /* TextField */
        public static JSComponent textField4(){
        return Namedb().member("java.awt.TextField", 3);
        }

      With:
        /* TextField */
        public static JSComponent emailTextField(){
        return Namedb().member("java.awt.TextField", 3);
        }

    4. For the fifth text field, replace textField5 with otherTextField.
      Replace:
        /* TextField */
        public static JSComponent textField5(){
        return Namedb().member("java.awt.TextField", 4);
        }

      With:
        /* TextField */
        public static JSComponent otherTextField(){
        return Namedb().member("java.awt.TextField", 4);
        }

  6. Save and compile.
    A dialog is displayed when the compile succeeds.

Editing SearchWin Declarations

  1. Load SearchWin.java into the Script Editor.

  2. Scroll down to locate the declaration for the textField component.
    This is the contains strings field:

  3. Change the component name to a field-specific identifier.
    Change textField() to containsStrTextField().

  4. Save and compile.

Editing NamesWin Declarations

The Names window doesn't contain any text field components, so you don't need to edit the contents of NamesWin. You do, however, need to compile the .java file.

  1. Load the NamesWin.java declarations file into the Script Editor.

  2. Save and compile the script.

  3. Close the Script Editor.



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