How To Automate JNLP Based Swing Application In Java

Share and Enjoy !

Last few days I was trying some research on JNLP based application and I was about to automate the JNLP application by using java.

Is it simple to to automate a JNLP based application?  Let us see ..
JNLP is a java file that runs on the JVM of the operating system but again it got registered as a process of operating system. Some javaw if you open and check task manager. So memory allocation for such application is bit complex. When a JNLP based application is running it is using JRE of JVM. For this Operating system treats it a process and allocate separate area in the memory. Again when I try to develop something I will be using local SDK of java. And Operating system treat this as a separate process and allocate memory to JVM which in term assign memory to my automated script./programing.

Due to pointer unavailability the second JVM can not access the first program running on first JVM. Operating system treat them differently.   

While googling about the same I got some reference about JNA [Java Native Access] which is helpful to automate JNLP based application.By using JNA we can access all the native method present in operating system.
From stackoverflow i got some reference about Window and how to find child window.

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.examples.win32.W32API.HWND;
import com.sun.jna.examples.win32.W32API.LPARAM;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public class IterateChildWindows {
public static final int WM_LBUTTONUP = 514;
public static final int WM_LBUTTONDOWN = 513;
public static final int WM_LBUTTONDBLCLK = 0x203;
static int WM_CLOSE = 0x10;
static String wText;
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.
loadLibrary("user32", User32.class, W32APIOptions.DEFAULT_OPTIONS);
HWND FindWindow(String lpClassName, String lpWindowName);
int GetWindowRect(HWND handle, int[] rect);
int SendMessage(HWND hWnd, int msg, int wParam, byte[] lParam);
HWND FindWindowEx(HWND parent, HWND child, String className, String window);
boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer arg);
boolean EnumChildWindows(HWND parent, WNDENUMPROC callback, LPARAM info);
interface WNDENUMPROC extends StdCallCallback {
boolean callback(HWND hWnd, Pointer arg);
int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount);
long GetWindowLong(HWND hWnd, int index);
int GetClassNameA(HWND in, byte[] lpString, int size);
void SetForegroundWindow(HWND hWnd);
public static void main(String[] args) {
User32.INSTANCE.EnumWindows(new User32.WNDENUMPROC() {
int count;
public boolean callback(HWND hWnd, Pointer userData) {
// this will be called for each parent window found by EnumWindows().
//the hWnd parameter is the HWND of the window that was found.
byte[] textBuffer = new byte[512];
User32.INSTANCE.GetWindowTextA(hWnd, textBuffer, 512);
wText = Native.toString(textBuffer);
wText = (wText.isEmpty()) ? "" : "; text: " + wText;
if (wText.contains("Notepad")){
System.out.println("Found window " + hWnd + ", total " + ++count + wText);
// System.out.println("Window found: " + wText);
// now call EnumChildWindows() giving the previously found parent 
//window as the first parameter
User32.INSTANCE.EnumChildWindows(hWnd, new User32.WNDENUMPROC() {
public boolean callback(HWND hWnd, Pointer userData) { 
// this is called for each child window that EnumChildWindows()
//finds - just like before with EnumWindows().
byte[] textBuffer = new byte[512];
User32.INSTANCE.GetClassNameA(hWnd, textBuffer, 512);
System.out.println(" - Found sub window /+
control class: " + new String(textBuffer).trim());
return true;
}, null);
return true;

}, null);


But this useful to find the window open ,activate putting in the foreground and to find all child window of the activated/parent window.But still i am struggling to get access the child element of the window.
Later during evaluation of different tools, we found few more.

  1. Java Robot 
  2. Abbot
  3. FEST(Fixtures for easy Software Testing)
See also  Class NoSuchFieldError in Java

While reading more we got a webpage on Java World. (

I downloaded the jar file and started writing wrappers . It resolved my issues. I was able to automate java swing,awt and applet based applications.

Little bit about FEST-
It is a very effective tool to automate java based oracle forms and java applet.It is having lots of APIs for testing java based applications.FEST allows users to simulate actual user gestures at OS level. It is also capable of taking screenshots of desktops.It supports easy assertions.It supports Junit4 and TestNG.

few examples what I took for making wrappers are written here-

Share and Enjoy !

2 thoughts on “How To Automate JNLP Based Swing Application In Java

  1. Just curious, did you make any further progress with this? I am working on automating some very simple interaction with a jnlp, and it has been a challenge to say the least.

  2. Actually this approach did not work. So what we are doing is trying to use few opensource tool that will activate the JNLP based application. One good option is FEST or else marathon. FEST can be handy if you know the class details.

Leave a Reply

Your email address will not be published. Required fields are marked *