Java GUI Plugins/en

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen

Supported Java Technologies[Bearbeiten]

expecco supports the automation of Java applications implemented with Java Swing, Java SWT or JavaFX. Also supported are applications that combine several of these technologies, e.g. a Swing application with embedded JavaFX content.

Java Swing[Bearbeiten]

This plugin for expecco allows you to create automated tests for Java applications whose user interfaces were created with Swing. The block library contains blocks for controlling and checking Swing user interfaces. This plugin is also integrated into the expecco GUI Test Extension. This extension supports the development of test sequences.

Main Features[Bearbeiten]

  • Automated operation and verification of Swing user interfaces
  • Simultaneous operation of several applications
  • Control of Swing user interfaces on remote target systems
  • Control of Java applications already running independently (no change to source code necessary, no recompilation of the application necessary)
  • Addressing of control elements by XPath
  • Access at object level possible via Java Bridge Interface Library
  • Integration into the expecco GUI Tests Extension
  • Block library with actions and checks for Swing components

Java SWT[Bearbeiten]

JavaFX[Bearbeiten]

Since Java 11 JavaFX is no longer included in the JDK. Therefore you have to install an additional JavaFX SDK, e.g. from OpenJFX. Then copy the jar files from the lib directory of the JavaFX JDK to packages\exept\expecco\plugin\javafx\lib in the expecco installation directory.

Functionality[Bearbeiten]

The interface establishes a connection to the Java VM and provides functions for reading widget attributes, recording user input, and remotely controlling the application. In addition, a library provides additional building blocks for automating tests. Essentially, the Java Swing plugin consists of two parts, the plugin for expecco and the application control (agent). To control the Swing application, an agent is loaded into the Java Virtual Machine of the running Java application. A Java Development Kit 1.8 (JDK) or higher is required to load the agent. However, the application to be tested can be run in a normal Java Runtime Edition 1.8 (JRE).

Requirements[Bearbeiten]

On the computer where the application to be tested is to run (local or remote):

The expecco requirements apply on the expecco computer.

Please note that both the agent and the application to be tested must be started with either 32 or 64 bit Java, otherwise no connection is possible.

Caused by JDK changes between Java versions, potential version conflicts may occur.

The compatibility of the versions is as follows. Further information on this.

JavaSwing Bridge Compatibility.png

Access Permissions[Bearbeiten]

To be able to guarantee a connection on the target system, additional parameters must be specified when starting the application to be tested (as well as the Java agent).

There are two ways to do this

  • Set an environment variable that is automatically loaded at the start of each Java application
  • Manual transfer of parameters at each start of a Java application
  • (Alternatively you can change access rights in the module-info.java files directly, but this is anything but practical)

Up to Java 11 it should be sufficient to set the following parameters:

-Djdk.attach.allowAttachSelf=true
--illegal-access=permit

Setting an environment variable works as follows (Example JDK_JAVA_OPTIONS which is loaded at every JVM start)

for Windows Systems

  • setx JDK_JAVA_OPTIONS "-Djdk.attach.allowAttachSelf=true; --illegal-access=permit"
  • or via the GUI (Windows key + Pause).

Windows Setenvironment.png]


for Unix systems

  • Bash: export _JAVA_OPTIONS='-Djdk.attach.allowAttachSelf=true; --illegal-access=permit'
  • C Shell: setenv _JAVA_OPTIONS '-Djdk.attach.allowAttachSelf=true; --illegal-access=permit'


Since Java 11 there is a stricter separation for the encapsulation of modules:

--illegal-access=permit will no longer work if the target application has a fixed module encapsulation (Details). In this case, additional parameters must be specified at program start which allow expecco access to the inherent resources. Depending on the technology used, the required parameters can vary, which is why you have to find them out for yourself. jdeps list-deps JARNAME.jar Jdeps is a freely available (part of the jdk) very useful tool for this purpose. A short overview of the commands can be found here ©


Example JavaFX:

The environment variable PATH_TO_FX which points to the JavaFX directory must be set (functionality see above) and the following parameters must be available when starting the Java application:

Parameter list (fold out)

  • --modul-path "%PATH_TO_FX%"
  • --add-modules=javafx.controls
  • --add-modules=javafx.swing
  • --add-modules=javafx.web
  • --add-opens öffnet javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
  • --add-opens javafx.graphics/javafx.stage=ALL-UNNAMED .
  • --add-opens öffnet javafx.graphics/javafx.scene=ALL-UNNAMED .
  • --add-opens javafx.graphicss/com.sun.javafx.stage=ALL-UNNAMED öffnet.
  • --add-opens javafx.graphics/javafx.scene.layout=ALL-UNNAMED
  • --add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED .
  • --add-opens javafx.controls/javafx.scene.control.skin=ALL-UNNAMED .
  • --add-opens javafx.controls/javafx.scene.chart=ALL-UNNAMED .
  • --add-exports javafx.controls/com.sun.javafx.charts=ALL-UNNAMED
  • --add-opens javafx.controls/com.sun.javafx.charts=ALL-UNNAMED
  • --add-exports javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED
  • --add-opens javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED .
  • --add-opens javafx.graphics/javafx.scene.image=ALL-UNNAMED
  • --add-opens javafx.graphics/javafx.scene.shape=ALL-UNNAMED
  • --add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED
  • --add-opens javafx.graphics/javafx.application=ALL-UNNAMED .
  • --add-opens javafx.graphicss/javafx.geometry=ALL-UNNAMED .
  • --add-opens öffnet javafx.graphics/javafx.scene.robot=ALL-UNNAMED .
  • --add-exports javafx.graphicss/com.sun.glass.ui=ALL-UNNAMED
  • --add-opens öffnet javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
  • --add-opens öffnet javafx.graphics/com.sun.glass.ui.win=ALL-UNNAMED .
  • --add-opens javafx.graphics/javafx.scene.input=ALL-UNNAMED .
  • --add-opens javafx.base/javafx.event=ALL-UNNAMED
  • --add-exports javafx.base/com.sun.javafx.runtime=ALL-UNNAMED
  • --add-opens javafx.base/com.sun.javafx.runtime=ALL-UNNAMED
  • --add-exports javafx.graphicss/com.sun.javafx.scene=ALL-UNNAMED
  • --add-exports javafx.graphicss/com.sun.javafx.util=ALL-UNNAMED
  • --add-exports javafx.graphicss/com.sun.javafx.scene.input=ALL-UNNAMED
  • --add-exports javafx.web/com.sun.webkit.dom=ALL-UNNAMED

If you still get a java.lang.IllegalAccessError, you have to extend this parameter in the following way:

  • Error text of the type Module <module> does not open "<package>" for unnamed modules.
--add-opens <modules>/<package>=ALL-UNNAMED >
Example: Module java.base does not open java.lang for unnamed module solve with --add-opens java.base/java.lang=ALL-UNNAMED.
  • Error text of the type cannot access the class <package>.<class name> (in module <module>), because the module <module> <package> does not export to the unnamed module.
---add-exports <modules>/<package>=ALL-UNNAMED >
Example: cannot access the class com.sun.javafx.scene.input.ExtendedInputMethodRequests (in the module javafx.graphics) because the module javafx.graphics com.sun.javafx.scene.input not exported into an unnamed module solve with --add-exports javafx.graphicss/com.sun.javafx.scene.input=ALL-UNNAMED>

Configuration[Bearbeiten]

Installation on the expecco Computer[Bearbeiten]

When installing expecco, make sure that the Java plugin is selected as the component to be installed.

If the application to be tested for the development of test sequences is executed on the same computer, start expecco and under "Extras" → "Settings" → "Plugins" → "Java Bridge" set the local path to a Java Development Kit 1.8 or higher.

The mandatory setting here is JDK Installation Path which is used for the main connection. Java Installation Path is an alternative setting for Groovy which only requires a JRE. For local connections, the Java Agent is automatically started with these settings.

JDKPfadEinstellungen.png

Installation on Test Application Computer[Bearbeiten]

You have to copy the javaBin folder of the expecco bridge framework to the test computer. It is in the expecco installation directory at:

...\exept\bridgeFramework\javaBridge\javaBin


expecco GUI Browser[Bearbeiten]

The expecco GUI-Browser is an additional tool which offers the possibility to analyze running applications and to develop test sequences. Then you can use the information, such as names and properties of individual elements, to perform actions with the function library or to interact with individual elements.

Connecting[Bearbeiten]

The following is a short series of pictures that can be used as a guide when setting up a connection

JavaSwing GUI Browser.png]

First open the GUI Browser (black circle) and in the tab Connect select the option Java (red circle). In the opening dialog you can now choose between 3 options.

  • Start Application on the Local Machine
provides a convenient way to start a local Java application via command line command
  • Connect to an already running Application on the Local machine
Allows connection to locally running Java applications. The Java Agent is automatically started with the Java version you specified in the expecco settings.
  • Connect to an already running Application on a Remote Machine
Allows you to connect to an already started Java Agent on another machine. This will then connect to the Java application running there.


JavaSwing Connection Window.png]

A search for Java applications lists all running Java virtual machines on the target system (in the example: localhost). A selection of the individual entries lists further information about the respective application.



JavaSwing Connection Connected.png]

If a connection has been successfully established, it will automatically be entered in the Expecco configuration list. There you can also see the GUI structure of the application as a hierarchical tree. Information on how to proceed can be found here: GUI Test Reference



JavaSwing Connection Reconnect.png]

Closed connections stay in the GUI browser. If the application is still running, you can reestablish the connection. To do this, right-click on the entry and select Connect from the context menu. If the connection settings have changed, you must reconfigure the connection. This can happen if you have restarted the application in the meantime. When using a remote system, this also applies to the agent.


Connection to Remote Systems[Bearbeiten]

JavaSwing Connection RemoteSetup.png]

To establish a connection remotely, the Java Agent must first be started on the target computer. To do this, navigate to the directory ...\exept\bridgeFramework\javaBridge\javaBin on the computer. There is a script which automatically detects the Java version in JAVA_HOME and starts the correct agent.

  • Windows users start startAgentLoader.bar
  • UNIX users start startAgentLoader.sh

These scripts can be provided with parameters via the command line as shown in the picture.

  • -ip <HostnameOderIP> gives the agent a special IP to wait for a connection. Useful for specific network masks.
Default host is 0.0.0.0.
  • -port >PortNumber gives the agent a specific port to wait for connections from Expecco.
Default port is 56784.

Warnings[Bearbeiten]

JavaSwing Connection Warnings.png

If any problems occur with the applications in this list, as can be seen in the picture above, the connection dialog automatically returns a suggested solution.
If the error that occurs would make a connection impossible, the corresponding entry is automatically marked as invalid.
The following error messages may occur and can be easily corrected:

JAVA VERSION MISMATCH As you can see in the picture, there may be Java version conflicts between the agent and the application.
In this case it is easiest to adjust the Expecco settings for Java Bridge.
A remote connection would have to start the program manually with the desired Java version instead.
The Java Agent, if called via the startAgentLoader script, selects the version Based on JAVA_HOME on the remote system
32 BIT - 64 BIT CONFLICT The 32 and 64 bit versions of Java are not compatible with each other.
Both the agent and the application must be started with the same "bit version" of Java.
UNABLE TO DETERMINE VERSION The agent cannot determine which Java version the application is using.
A connection may be possible, but there may be a potential version conflict.

Cross-Technology Connections[Bearbeiten]

If an application uses multiple Java technologies, you only need to establish one connection and then use the blocks from the library according to the technology of the element to be addressed.

Embedded JavaFX in Java Swing[Bearbeiten]

If JavaFX is embedded in a Swing application, it contains a JFXPanel element. In the GUI browser, the JavaFX elements are displayed below this panel. For the FX blocks to find these embedded FX elements, the block Set FX Context To Panel from the Swing Library with the path to the JFXPanel must be executed at the beginning.

WebView in JavaFX[Bearbeiten]

If a WebView is included in JavaFX, its elements are displayed in the GUI browser below the WebView element. For these elements there are separate blocks in the JavaFX library, which are combined in the folder Embedded WebView. In order for the elements to be found in the test, the block Set WebView Context must first be executed on the element WebView.

Embedded Java Swing in JavaFX[Bearbeiten]

If Java Swing is embedded in a JavaFX application, it contains a SwingNode element. In the GUI browser, its content is still displayed parallel to the FX content. The modules of the Swing library can be used directly with these elements.

JavaSwingLibrary[Bearbeiten]

Example[Bearbeiten]

FAQ[Bearbeiten]

The tree in the GUI browser does not show all elements of my application[Bearbeiten]

An application consists of many different elements. Some of them are not interactive, i.e. they are not directly visible to the user and are only used for formatting, such as panels.

If many such elements are present, the tree can become very large and very deep. As these elements are usually uninteresting for automation, they can be hidden in expecco by default. If you need to access one of those elements, or need it to create a unique path, that behavior should be turned off.

The JavaSwingLibrary contains the Set Skip Mode block for this purpose. On of the following modes can be selected:

INTERACTIVE Collect only interactive elements
ALL Collect all elements
INTERACTIVE_HYBRID like INTERACTIVE, but with the fallback to ALL if a path cannot be resolved
ALL_HYBRID like ALL, but with the fallback to INTERACTIVE if a path cannot be resolved
Execution of the block changes the behavior for the current connection. It refers to what is displayed in the tree as well as how the paths on the blocks are handled. Since expecco 19.1 the default is ALL_HYBRID and in earlier versions it is INTERACTIVE.

I cannot connect, but all settings are correct[Bearbeiten]

Even though this should not happen in general, here are a few more aspects which affect the connection:

  • Firewall
    The firewall can interfere with the Java Agent's communication with the application.
    Either set up an exception rule for the agent or deactivate the firewall for the duration of the test.
  • Socket in use
    It can happen, especially when debugging, that a previous instance of a Java agent was not closed correctly. This can lead to it occupying the socket and rejecting other connections.
    Try "Extras" → "Debugging" → "Close all bridge connections / Close all socket connections".
    Be warned that this will also close all other existing (local) Expecco connections. In the case of remote connection, a restart of the agent and possibly of the application may help.



Copyright © 2014-2024 eXept Software AG