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
In this lesson, you insert a Java code snippet so that HCL DevOps Test UI (Test UI) 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
-
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 theClick 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 theClick Password
test line so that Java code is executed before the password control is tested. - Click 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 to save the Java script.
Play back the script
About this task
Procedure
- 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 dataset Iteration Count list to
access all the records in the dataset; then click Finish.
Test UI 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.