Skip to content

Tutorial: Java Testing (RVL)

In this section, you will learn how to record and execute Rapise scripts against Java applications. We will show you how to test the following three different types of Java applications:

  • Java AWT Apps
  • Java Swing Apps
  • Java SWT Apps

This version of the tutorial uses Rapise Visual Language (RVL) in scriptless mode. If you're interested in the JavaScript version, a separate tutorial is available.

Example 1 - Launching the Sample AWT/Swing Application

From Rapise's Start Page, click the Fetch Samples button to ensure you have all the latest samples available.

Then navigate to

1
C:\Users\Public\Documents\Rapise\Samples\Java\AUTJAVA

and right-click the x86run.cmd file, then choose Run as Administrator.

If Java is configured correctly, you will see:

awtswing_sample1

If the application doesn't start correctly, ensure Java SE and the Rapise Java Bridge are installed, and the JAVA_HOME environment variable is correctly set to your Java Runtime (JRE). For more details, please refer to: Java AWT/Swing Testing.

Once the application starts, open Rapise and click File > New Test:

clip0128

Name the test Java Test 1 and choose Basic: Windows Desktop Application as the methodology.

On the next page, choose Rapise Visual Language (RVL) as the scripting language:

clip0125

Once the test is created, you will see:

clip0126

Click the Record button to display the "Select an Application to Record" dialog:

sar_dialog_java

Choose the AUT JAVA process from the list of running applications, change the library selection from Auto to Java, and then click Select.

Now, in the sample application, click some of the AWT and/or Swing controls. Rapise will record the actions:

rad_java1

When you click Finish, Rapise will prompt you to confirm where to place the recorded test steps:

clip0130

Select the first row in the test grid and click Insert Here. You will see the recorded test script and learned objects in Rapise:

clip0131

When you click Play, Rapise will play back your test script against the application:

clip0132

You can add steps to your script using any of the learned objects from the left-hand pane (or any of the standard global utility objects). To do this, click the blank row at the end of the recording and choose the following options from the dropdown lists in that row, for example:

  • Type = Action
  • Object = button1
  • Action = DoAction

This process is illustrated below:

clip0133

Sometimes, you need to learn objects that are not visible or are obscured by other objects. To help with this, Rapise provides the Object Spy tool. The Spy tool lets you view the objects in the application within a learnable hierarchy. While recording, click the Spy button, and Rapise will display the Java Spy:

sample_java_spy

You can then use the Java Spy to track and find objects in the application hierarchy. You can navigate to parent objects by right-clicking them and choosing Parent. Once you have found the desired object, click the Learn Object in the Spy toolbar, and Rapise will add the object from the Spy to the list of learned objects you can test against.

Example 2 - Launching the Sample SWT Application

From Rapise's Start Page, click the Fetch Samples button to ensure you have all the latest samples available.

Then navigate to

1
C:\Users\Public\Documents\Rapise\Samples\JavaSWT\AUTJavaSWT

and double-click the JavaSWTAUT.bat file to start the sample application.

If Java is configured correctly, you will see:

sample_app_swt

If the application doesn't start correctly, ensure Java SE is installed and the JAVA_HOME environment variable is correctly set to your Java Runtime (JRE). For more details, please refer to: Java SWT Testing.

Once the application starts, open Rapise and click File > New Test:

clip0128

Name the test "Java Test 2" and choose Basic: Windows Desktop Application as the methodology. On the next page, choose Rapise Visual Language (RVL) as the scripting language:

clip0125

Once the test is created, you will see:

clip0126

Click the Record button to display the Select an Application to Record dialog:

sar_dialog_swt

Choose the Test Java SWT Application from the list of running applications, change the library selection from Auto to UI Automation and SWT, and then click Select.

Now, in the sample application, click some of the SWT controls. Rapise will record the actions:

rad_swt

When you click Finish, Rapise will prompt you to confirm where to place the recorded test steps:

clip0134

Select the first row in the test grid and click Insert Here. You will see the recorded test script and learned objects in Rapise:

clip0135

When you click Play, Rapise will play back your test script against the application:

clip0136

You can add steps to your script using any of the learned objects from the left-hand pane (or any of the standard global utility objects). To do this, click the blank row at the end of the recording and choose the following options from the dropdown lists in that row, for example:

  • Type = Action
  • Object = Image_Button
  • Action = DoAction

This process is illustrated below:

clip0137

You can drag and drop any of the learned objects from the left-hand pane into the main test script.

When you click Play, Rapise will play back your test script against the application.

Sometimes, you need to learn objects that are not visible or are obscured by other objects. To help with this, Rapise provides the Object Spy tool. The Spy tool lets you view the objects in the application within a learnable hierarchy. While recording, click the Spy button, and Rapise will display the UIAutomation Spy:

sample_swt_spy

You can then use the UIAutomation Spy to track and find objects in the application hierarchy. You can navigate to parent objects by right-clicking them and choosing Parent. Once you have found the desired object, click the Learn Object in the Spy toolbar, and Rapise will add the object from the Spy to the list of learned objects you can test against.

See Also