Testing Java Apps
Beginning with version 2.8, Cycle has the ability to interact with Java (Swing) applications. These new Java app Steps allow Cycle to interact with Java applications without relying on desktop steps that are not tied to a specific running application or using image matching.
When to Use Java App Steps
Using Cycle’s Java application steps is the preferred method when testing Java (Swing) applications. The following conditions are good decision points when deciding whether or not to use Java app steps instead of using the traditional desktop steps and image matching:
- The application you are testing has useful CSS locators that allow you to pinpoint specific elements (text boxes, radio buttons, check boxes, etc…) to interact with on screen.
- You are developing Cycle features that will locally test a Java application built with Java 8.
Cycle desktop steps and image matching steps will interact with Java applications, but these steps have limits that can result in negative test results. These limits should be taken into consideration when deciding whether or not to use Java app steps instead.
Desktop step limitations:
- You cannot guarantee the current application in focus on the desktop is the application you are testing. Cycle completes the desktop steps as written. Any key presses, typing, or clicking will continue to happen on the desktop in whatever application is currently running and the test will fail.
- You cannot guarantee mouse or cursor position on screen when using a feature that was developed on a different system with a potentially different resolution.
Image matching limitations:
- Screen resolution, themes, and color settings can vary across multiple devices. Images matching on one machine may not match on another machine if all video settings are not identical. These differences will cause tests to fail.
- Image matching can lead to false negative and positive results depending on the image correlation setting.
- Visual changes to the application due to a patch or modification may require images to be recaptured for the feature to execute properly.
- Developing features to run on multiple machines may require multiple libraries of image files.
Desktop steps and image matching can be utilized to test Java applications, but their limitations tend to make them less reliable that terminal steps and web steps. The Java app steps are much more in line with the precision provided by web steps and are the preferred option for interacting with Java applications.
Using Java App Steps
If you are comfortable developing web features using element locators and xPath, then you will be able to use the java app steps without much trouble. Less technically inclined users may find using java app steps a challenge until they are able to become comfortable with evaluating CSS locators and determining how to uniquely identify those objects.
Initial Setup
For Cycle to be able to execute the JavaAppDriver family of Steps, a few system environemnt variables must be established and a Java security permission will need to be added.
-
To Add and Edit System Wide Environment Variables, start by typing
run
into the Start Menu or Search box and open the Run Application. -
In the Open field type or paste
SystemPropertiesAdvanced
and click OK or press enter. -
The System Properties dialog box will open with the Advanced Tab selected. Click on the
Environement Variables...
button at bottom. -
Here we can add the necessary
New...
entries to the lower list of System variables:
JAVA_HOME
should point to the version of Java running on the machine, usually located inC:\Program Files\Java\
Note:
An additional Environment Variable is required for Cycle versions 2.14 and earlier marathon.agent.file will need to be added and point to the marathon driver that is packaged with Cycle at C:\Program Files (x86)\CycleLabs\Cycle\stage\lib\com.jaliansystems.marathon-java-agent-5.4.0.0.jar (depending on your Cycle install location). This Environment Variable is not needed in Cycle versions 2.15 and newer.
-
Finally, after selecting the
Path
System variable clickEdit...
and add an entry for%JAVA_HOME%\bin
-
Once updating these Environment Variables, Cycle will need to be closed and reopened for the Java App Steps to use these values to access the necessary resources.
You will also need to add a security permission to the Java Web Start policy file. You will need Administrator privileges to save changes to the file.
-
Ensure that the
%JAVA_HOME%/lib/security/javaws.policy
file exists. -
Open
Notepad
as an Administrator. -
Open the
%JAVA_HOME%/lib/security/javaws.policy
file inNotepad
. You may need to select theAll Files
file type for the file to appear. -
Ensure the
javaws.policy
file contains the following snippet. If this snippet is not present, add it to the file. This snippet enables Java to run JNLP files using Java Web Start. There may be other entries in the file for other applications on your system.
grant codeBase "file:${jnlpx.home}/javaws.jar" {
permission java.security.AllPermission;
};
- Add the following snippet to the file. This snippet enables JavaAppDriver to interact with Java Web Start applications.
grant codeBase "${marathon.agent}" {
permission java.security.AllPermission;
};
-
Save the file.
-
Close and reopen the file to ensure that the file contents are saved to disk. The file should contain the following contents:
grant codeBase "file:${jnlpx.home}/javaws.jar" {
permission java.security.AllPermission;
};
grant codeBase "${marathon.agent}" {
permission java.security.AllPermission;
};
- Cycle may need to be closed and reopened for the Java App Steps to run with the proper permissions.