Getting Started with JavaStar: Recording a Script


Now you're going to record a script that tests several functions of the Name Database. Testing multiple functions in a single recorded test script isn't necessarily the recommended way to build tests--Chapter 2, "Using a Modular Approach" discusses this in more detail--but for now it provides a tour of the JavaStar features. It also gives you a deeper appreciation of why you'll later want to compose tests of many small scripts instead.

Because this process contains a lot of steps--click here, type this, click that--this part of the tutorial is broken down into sections. These sections are all part of one script, though, so you can't selectively carry out sections and have the script run properly. If you're the type of person who learns best by reading these instructions through before, instead of carrying them out, you'll find this organization a bit more readable.

Start Creating the Script

  1. Start the application you want to test:

    1. In the JavaStar main menu, click Create Test Script.
      This opens the Create Test Script dialog. This dialog includes the same fields in the Project Settings App panel; this is so you can override settings for a session, or, if you have not defined a project file, define settings to use while the Record/Playback window is open.

      Create Test Script dialog
      If you created a Project File as described in "Creating a Project File," the Class and Classpath fields should already be filled in.

    2. Click the Advanced tab
      This brings the advanced options to the forefront. See Figure 2-3 for an example. Here you can override more project file settings, including the directory settings you defined in the Project Settings Test panel. For now, you're just going to override the logfile name.

      Advanced tab for Create Test Script

    3. Change the Log file field value to tutorial.log.

    4. Click Start to launch the application under test.
      The Record/Playback window and the Name Database application open.

      Record/Playback window

If namedb does not start

If you get the message:

Here are some things to try:

Verify that you are using a fully-qualified class name. If your class is within a package, be sure to type packageName.className.

  1. Move the Name Database window to one side.
    Position it as best you can (given your monitor size) so you can see both the Record/Playback Window and the Name Database window. This makes it easier to record your interaction with the application under test while keeping the JavaStar controls accessible.

  2. Begin record mode:

    1. Click Record.
      This brings up the Record Test Script dialog.

    2. In the Create Script field, type TestNameDB.
      This lesson does not use non-component locators or map files, so leave the fields relating to these topics blank. The advanced JavaStar tutorial for "Generating and Using Declarations" addresses Record with map files, and 'Locators for Non-Components" describes Non component locators.
      This window also provides you with an option to toggle the Record with delays checkbox. If you turn this feature on, JavaStar will record the time of any delays between events and add this to the script. You can later scale the delays using settings in Playback Options. For this script, delays aren't important, so you can leave this box unchecked.

      Note - If you were recording a script that interacted with a Canvas component, recording with delays would be a good idea. With a Canvas, the speed of user interaction has an affect on the result, especially when combined with the speed of the system on which you run the test. Taking advantage of the delay feature gives you more control--you can later scale that delay to compensate for system speed.

    3. Click OK.
      You're now in record mode. Anything you do in a Name Database window will be recorded to your script.

Opening the Test Database

The first step of the test will be to load the database into the Name Database application. Whether or not this first step succeeds is critical to the integrity of the test--if it does not succeed, your later results are compromised. To ensure this doesn't happen, you'll insert a synchronization comparison.

JavaStar provides two types of comparisons: verifications and synchronizations. The difference between the two is not in what you can compare (that's identical) but in how JavaStar responds to the results during playback.

With a verification, JavaStar performs the comparison, evaluating the results as you specified. If the verification fails, JavaStar checks the component again, repeating until a specified timeout interval has elapsed. If the verification hasn't succeeded by the time the timeout expires, JavaStar logs this as a verification failure and continues on with the test.

A synchronization works the same way with one exception--if the comparison fails at the timeout, JavaStar throws an exception and the script ends abnormally. Terminating the current script after a failed synchronization and indicating that the termination was abnormal is important, because a synchronization error requires recovery. (In the next chapter, you'll learn how to compose a test that automatically handles this kind of recovery.)

While you follow the steps in this section, the Record/Playback window should be open and visible on your desktop. This window contains the controls for recording (to the left) and dynamically displays the log file for this session in the text panel to the right.

  1. Make the Name Database window active.
    Click on the border of the Name Database window.

  2. In the Name Database window, open the test database.

    1. In the Name Database window, click Open.
      This brings up the file dialog window.

    2. Open test.db.
      If the file dialog doesn't automatically open to the tutorial directory, navigate to that directory. Select test.db from the list of files. Click Open. The file dialog closes.
      If you are following this tutorial on a UNIX system, you may be prompted with OK instead of Open within the file dialog window.

      Note - JavaStar doesn't record specific mouse-clicks or movements because, if it did, the tests wouldn't be platform independent--what worked for a UNIX file browser might not work for a Windows 95 file browser. By passing only a relative file call to the dialog, JavaStar keeps your test platform-independent, even if the file dialog itself is not.

  3. Now, to setup a comparison to check that the right file is open, click Synchronize in the Record/Playback window.
    When you click Synchronize, JavaStar automatically pauses record mode. The right portion of the window also changes to show prompts for the operation you selected.

  4. Set up the synchronize operation as follows:

    1. Click on the component you want to verify in the application under test--in this case, click on the Name Database - test.db label at the top of the Name Database window.
      Note that the text panel of the Synchronization window displays the selection code. In addition, JavaStar flashes the component so you know which one you chose.

      Select for Synchronization
      Selection code for the object you selected appears in the synchronization select panel. Immediately below, JavaStar lists the default method of synchronization, and gives you the option to choose the default or customize the method of comparison.
      The bottom panel displays the log file for this session.

    2. Click Use default.
      The panel changes to prompt you for a purpose for the comparison. The object to compare and the method of comparison are displayed here, as well.

      Synchronization prompt for purpose

    3. At the prompt to enter purpose below, type Continue only if correct file loaded.
      While you don't have to type a purpose for the comparison, it can be helpful to do so. JavaStar includes the purpose in the test results, making it easier for you to evaluate results. Because this string also appears in the script code, it can help you understand the script if you decide to edit it in the future.

    4. Click the Insert synchronization into test.
      JavaStar returns you to the first synchronization panel.

    5. In the left button bar, click Continue.
      The right portion of the window changes to display recording data, and record mode resumes.

Recording Text Input

  1. In the Name Database main window, clear the display.
    Click Clear. This only clears the display--it doesn't remove the record that displayed when you opened the database.

  2. Enter record for Count von Count.

    1. Click in the Name text field and type Count von Count

    2. Using the TAB key to advance through the fields, enter the following information into the remaining fields:

  3. Click Add to update the database with this information.

  4. Save the database.
    Click the Save button.

  5. Click Clear to clear the display.
    This returns the application to a "neutral state" before proceeding to the next step, where you'll select this record from the names list and verify that it displays accurately.

Checking the Search Operation

Now you're ready to verify whether the search function will locate the record you just added. As mentioned earlier, the verify option works similarly to synchronize--the dialog is almost identical. The difference is how JavaStar processes the two types of comparisons. Synchronizations that fail throw an exception, but do not affect the pass/fail count for comparisons. In contrast, verifications that fail do not throw exceptions (meaning that your test is not interrupted) but JavaStar notes them as comparison failures in the test log. Each type of comparison is useful in different situations.

For comparing the search results, a verification makes sense. If the search fails, it doesn't necessarily affect the integrity of the tests that follow. Noting the failure in the log is sufficient.

This part of the test uses two types of verification:

When you verify the search results list, you'll be looking for the number of items returned by the search. For this exercise, you'll obtain that value using the VerifyAny feature to compare the return values for any of the component's methods and variables. You'll compare the return value of the list component's getItemCount().

To verify each field of the record that the search operation returns, you'll use the "using text" option. This is the same option you used when synchronizing to the database filename.

  1. To bring up the Search window, click Search in the Name Database main window.

    Search window

  2. From the select criteria choice list, choose address2.
    This operation will now only search the address2 field.

  3. In the contains strings field, type Transylvania.

  4. Click Search.

  5. Verify the number of items returned by the search:

    1. In the Record/Playback window, click the Verify button.
      The right portion of the window changes to show the first verification panel: select an object to verify. This panel is very similar to the Synchronization panel you worked with earlier.

    2. In the Name Database search window, click on the search results list as your object to verify.
      The selection code for the list appears in the verification panel. The default method for this component (a List) is "enabled."

      Note - At this point, instead of selecting a object--or to override an object you already selected--you could toggle on the All visible windows option. This option would instruct JavaStar to verify all objects in all visible windows for your application under test. For this example, though, you need specific information on a single component, so leave this option unchecked.

    3. In the Verification panel, click the Customize button.
      The panel changes to show the object to verify and to prompt for a verification method.

      How to Verify panel

    4. Select Using Simple Methods and Data Members.

    5. Click the button Select Simple Methods and Data Members.
      The panel changes to show you a list of all available simple data members and methods, sorted by name.

    6. Scroll through the method list to locate int getItemCount(), and select it.
      To select the method, click anywhere on the line other than on the returns button. A black bar highlights the line to let you know it is selected. You can select multiple lines when you verify using simple methods and data members, and JavaStar will compare them all. For this exercise, though, you'll only compare getItemCount().
      If you want to preview the return value to make sure this is the correct method, click the returns button next to the name. This shows you the current return value based on your interaction with the application--in this example, the return value should be new Integer(1).

      Select methods to use for verification

    7. Click the Enter a purpose button.
      The panel changes to show you the object you selected for comparison and the comparison method. It also prompts you for a string to identify the purpose for the comparison.

    8. Enter Verify number of items found in the purpose field.

    9. Click Insert verification into test.

  6. In the Record/Playback window, click Continue to resume recording.
    Note that the log shows this line of code added to the script:
    This code uses the verifyAnyMethod() method from the JavaStar API library.

  7. Select the search result and click View result.
    The record is displayed in the Name Database main window.

  8. Set up a series of comparisons to ensure that the contents of each field for this record is correct.
    Here you'll do verify operations instead of a synchronize, because even if one field fails the test during playback, you want the test to continue on and test the others.

    1. Go back into verify mode.
      Click Verify.

    2. Click inside the Name text field to select it.
      The field flashes to confirm your selection, and the code displays in the verification window. The verification panel shows "using text" as the default method of comparison, meaning that if you use the default, JavaStar will compare the text inside the field (not the field label).

    3. Click Use default.
      The panel changes to prompt you for a purpose.

    4. In the purpose field, type Verify text entry.

    5. Click Insert verification into test.
      This adds the verification code to your script:
      JS.frame("Name Database").member("namedb").member("java.awt.TextField", 0).verify(this,"Count von Count", "Verify text entry");
      JavaStar returns you to the first Verification panel so you can specify more verify operations.

    6. Set up verifications for the remaining text entry fields by clicking inside each field, clicking Use default, then clicking Insert verification into test.
      The type of comparison and the Why string remain the same as long as you keep the Verification window, so you don't have to reset these for each field.

    7. Click Continue to resume recording.

  9. Close the Search window of the Name Database.

What if you need to create a test before the application performs the correct computations?

You might need to create a test that exercises a feature of the product that, at the time you create the test, returns an incorrect value. If you insert a comparison (whether a verification or synchronization) you will be setting the test to compare to an incorrect value--meaning that as long as the tested feature returns the wrong value, the test will pass. What can you do to create a test that checks for values that are not yet correct at the time you record the script?

In this case, you can manually edit the script and replace the string JavaStar uses for comparison with the correct text. Because this is a text comparison, this is relatively easy to do. You'll learn how to edit scripts in the chapter "Adding Parameters for Flexibility."

Ending Record Mode

  1. In the Name Database main window, click Clear.
    This returns the application to a neutral state. It's a good idea to end your scripts in a state you can anticipate, especially if you plan on running one script after another, as in the case of a composed test.

  2. In the Record/Playback window, click Stop.
    JavaStar saves the script as a .java file and compiles the code into a .class file. It writes these files to your work directory.

  3. Quit the Record/Playback window.
    JavaStar will prompt you for confirmation that you want to quit. Once you respond affirmatively, JavaStar closes both the Record/Playback window and the application under test.



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