Lesson 8: Insert Java custom code

You can switch to Java scripting if you want to insert Java codes to perform additional operations such as extending an API or any functions that cannot be performed directly in the simplified script editor.

About this task

To use both the simplified script and the Java scripting, you must use the Insert Java Code Snippet or Insert Java Method feature available in the simplified script editor and switch to Java scripting. If you modify the Java script directly without using these features, the Java script changes are lost and the simplified script is executed during playback.

In this lesson, you insert a Java code snippet so that Rational® Functional Tester waits until the Password control in the Member Logon window is displayed in the application during playback and then test the control.

You can enable the option to wait for the control to be displayed for a test line in the Playback page in the Properties view. But in this tutorial, to understand the process of inserting a custom Java code, you perform the following steps:

Procedure

  1. Select the test line Click Password in the script editor.
    (The first test line in the Member Logon group.)
  2. Right-click and select Insert Java Code Snippet.
    The test line Click here to tag the Java snippet test line is inserted after the Click Password.
  3. Select the inserted test line and replace the test line text by typing Wait for control.
  4. Drag the Wait for the control test line and drop it above the Click Password test line so that Java code is executed before the password control is tested.
    Wait for control test line
  5. Click File > Save to save the simplified script.
  6. Click Java editor that is displayed next to the Script editor.
    Notice that Wait for control is displayed as comments with the start and the end point for inserting the Java code in the Java editor.
  7. Type the Java code password().waitForExistence(); within the start and the end comment section.
    Java code
  8. Click File > Save to save the Java script.

Play back the script

About this task

Play back the test script and verify the results of the modified test script.

Procedure

  1. To play back the script, click Run Functional Test Script (Run) on the toolbar.
  2. In the Select Log window, keep the default log name Order, and then click Next.
  3. Select the Iterate Until Done option from the dataset Iteration Count list to access all the records in the dataset; then click Finish.
    Rational® Functional Tester plays back the modified script. During playback, notice that the click action on the Details page of the Album is not executed.

    When playback is finished, the HTML log displays the results of the test run. Each event listed in the log includes Pass in the event headings in green. You can also view the snapshot of the composers list.

Lesson checkpoint

About this task

In this lesson you learned how to modify the simplified test script and insert a Java custom code snippet to a simplified script.