< Previous | Next >
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.
To use both the simplified script and the Java scripting, 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:
- Select the test line Click Password in the script editor. (The first test line in the Member Logon group.)
- 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.
- Select the inserted test line and replace the test line text by typing Wait for control.
- 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.
- Click File > Save to save the simplified script.
- 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.
- Type the Java code password().waitForExistence(); within the start and the end comment section.
- Click File > Save to save the Java script.
Play back the script
Play back the test script and verify the results of the modified test script.
- To play back the script, click Run Functional Test Script () on the toolbar.
- In the Select Log window, keep the default log name Order, and then click Next.
- Select the Iterate Until Done option from the Datapool Iteration Count list to access all the records in the datapool; then click Finish. IBM 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.
In this lesson you learned how to modify the simplified test script and insert a Java custom code snippet to a simplified script.
< Previous | Next >