Automating applications loaded via Java Web Start

Last edited on

Overview

There are basically two ways to automate an application started via Java Web Start:

Set a suitable Maximum Startup Time

If your application normally requires at least 60 seconds to start up you need to inform Squish so that it will wait long enough. To do this, begin by clicking Edit→Server Settings.

Navigate to the Squish item's Application Behavior subitem and change the Maximum Startup Time setting to the time your application normally needs plus, say, an extra 30 seconds to allow for temporary extra demand on the machine. So, for a normal 60 second startup, set the time to 90 seconds.

Set a suitable Maximum Post-Mortem Wait Time

This value should be set to twice the time (in milliseconds) between the appearance of the Java Web Start splash screen and the appearance of the application. For example if that time is 5 seconds, then this value should be set to 10000:

When this value is set too low, the application may not appear and replaying/recording may fail with an error.

Start via web browser

For this Squish for Web should be used to automate the web browser to perform the steps that cause the Web Start application to start.

The Web Start application should get hooked automatically by Squish and every user interaction with it should be recorded.

Please note that this introduces a new ApplicationContext for the Web Start application, so you need to know about these. Please see the Squish manual and Related information for information about application contexts.

Here is a sample recording for starting the "Dynamic Tree Demo" at Deploying a Java Web Start Application :

import names

def main():
    startBrowser("https://download.oracle.com/javase/tutorial/deployment/webstart/deploying.html")
    clickLink(waitForObject(names._A))
    mouseClick(waitForObject(names.Opening_dynamictree-webstart_jnlp_Window"), 299, 282, MouseButton.LeftButton)
    ctx_1 = waitForApplicationLaunch()
    expand(waitForObjectItem(names.JTree, "Root Node"))
    expand(waitForObjectItem(names.JTree, "Root Node.Parent 1"))
    expand(waitForObjectItem(names.JTree, "Root Node.Parent 2"))

The above recording was done with Firefox 4 (on Windows) which was configured to show the following dialog when opening JNLP files:

For clicking on the OK button Squish recorded this command:

mouseClick(waitForObject(names.Openingdynamictree-webstart_jnlp_Window), 299, 282, MouseButton.LeftButton)

There is a problem with this dialog however: It is a native Windows dialog, and unless you have a Squish for Windows license you cannot automate it via a mouse click. But fortunately you can use the function nativeType() to send key presses to this dialog (actually to the window that currently has input focus). So the revised script would look like this:

import names

def main():
    startBrowser("https://download.oracle.com/javase/tutorial/deployment/webstart/deploying.html")
    clickLink(waitForObject(names._A))

    #mouseClick(waitForObject(names.Openingdynamictree-webstart_jnlp_Window"), 299, 282, MouseButton.LeftButton)
    snooze(3)
    nativeType("<Return>")

    ctx_1 = waitForApplicationLaunch()
    expand(waitForObjectItem(names.JTree, "Root Node"))
    expand(waitForObjectItem(names.JTree, "Root Node.Parent 1"))
    expand(waitForObjectItem(names.JTree, "Root Node.Parent 2"))

Note the following:

It is important to note that nativeType() sends key press to the currently focused window. So if the dialog would require more than 3 seconds to show up, the Return key press would be sent to the browser and the dialog would show up without being closed, and then the test script would wait indefinitely for the Java application to start up in the waitForApplicationLaunch() function.

To avoid this problem one could choose to not show the above dialog anymore (check Do this automatically for files like this from now on.).

Start via the tool javaws

You can configure the tool javaws (which is responsible for starting Web Start applications and which is included in typical JRE (Java Runtime Environment) installations) as AUT and pass the URL to your Web Start application to it. This can be done in the test suite settings.