Skip to content

Tutorial: Java Testing (JavaScript)

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

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

This version of the tutorial uses the JavaScript test editor option in Rapise. If you'd prefer to use the Rapise Visual Language (RVL), please go to the main Tutorial instead.

Example 1 - Launching the Sample AWT/Swing Application

On the Start Page of Rapise, click on the Fetch Samples button to make sure you have all of the latest samples available.

Then go to

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

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

If you have Java configured correctly, you will see:

awtswing_sample1

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

Once the application is started, open up Rapise and click File > New Test:

clip0128

Enter the name Java Test 1 as the name and choose Basic: Windows Desktop Application as the methodology.

Choose the JavaScript option during test creation instead of RVL.

clip0129

Once the test is created, you will see:

newtestcreatedscreen

Click on 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 click Select.

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

rad_java1

When you click Finish, you will see the recorded test script and learned objects:

testscript_java

You can drag and drop any of the learned objects from the left-hand pane into the main test script. You can also just type SeS("button1") (for example) and Rapise will display the list of available functions.

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

clip0132

Sometimes you need to learn objects that are not visible or are obscured by other objects. To help with this, Rapise has the Object Spy tool. The Spy tool lets you see the objects in the application in a hierarchy that you can learn. When you are in the middle of recording, click on 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 on them and choosing Parent. Once you have found the desired object, click on the Learn Object in the Spy toolbar and Rapise will add the object in the Spy to the list of learned objects that you can test against.

Example 2 - Launching the Sample SWT Application

On the Start Page of Rapise, click on the Fetch Samples button to make sure you have all of the latest samples available.

Then go to

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

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

If you have Java configured correctly, you will see:

sample_app_swt

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

Once the application is started, open up Rapise and click the menu FIle > New Test:

clip0128

Enter the name "Java Test 2" as the name and choose Basic: Windows Desktop Application as the methodology.

Choose the JavaScript option during test creation instead of RVL.

clip0129

Once the test is created, you will see:

newtestcreatedscreen

Click on 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 click Select.

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

rad_swt

When you click Finish, you will see the recorded test script and learned objects:

testscript_swt

You can drag and drop any of the learned objects from the left-hand pane into the main test script. You can also just type SeS("OK") (for example) and Rapise will display the list of available functions.

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

report_swt_sample

Sometimes you need to learn objects that are not visible or are obscured by other objects. To help with this, Rapise has the Object Spy tool. The Spy tool lets you see the objects in the application in a hierarchy that you can learn. When you are in the middle of recording, click on 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 on them and choosing Parent. Once you have found the desired object, click on the Learn Object in the Spy toolbar and Rapise will add the object in the Spy to the list of learned objects that you can test against.

See Also