PreetS avatar image
PreetS asked udaya answered

HOW TO Test Java applets using the Swing application in iTest 3.2

Although we officially do not support Java applet testing, there is a way (or work around as you may call it) to test applets using the 'Swing' application in iTest. 


There are a few restrictions and requirements though.  



  • The applet must be written using Swing. (Most applets are, but there are some old applets which use primitive AWT controls, which we can see in the Swing application, but can not perform complex actions on)
  • The applet must be stand-alone, i.e. independent of the web page that is hosting the applet. The applet should not be dependent on data avialble on the HTML content of the page or on some javascript method.
  • The URL of the page that his hosting the applet must be directly accessible. For example, it does not  take you first to the login page when you enter credentials and only then can you access that page. 
  • The machine that is running iTest must have Java JDK (5.0 or later) installed. Note that this is JDK, not JRE. Once we officially support applets in iTest, we might add all the JDK libraries and programs required into the built in JRE we ship with iTest. But, for now the machine needs to have JDK installed. 
First thing to do is to create a .bat file, or a .sh file on Linux. (In this example I will assume you are on Windows) This bat file will launch the appletViewer (that comes with the JDK) and you can pass in the URL of the page hosting the applet as an argument.
You will also need to configure the JVM arguments  so that iTest can connect to the applet under test. These JVM arguments are the same for configuring any Swing application to make it work with iTest. The two JVM arguments that iTest needs are "-javaagent" and "-Xbootclasspath".
The .bat file you create should look like this:

"{JDK home folder}\bin\appletviewer.exe" -J-javaagent:"{Swing resource folder}\SwingTestHarness.jar" -J-Xbootclasspath/a:"{Swing resource folder}\SwingTestHarnessInterfaces.jar;{Swing resource folder}\SwingTestHarness.jar;{Swing resource folder}\xmlwriter-2.2.jar" %1

 {Swing resource folder} is the path to the Swing resource plugin folder. This is the folder that is named "" in the plugins folder where iTest is installed. 

As an example, on my machine, the .bat file looks like:  

"c:\Program Files\Java\jdk1.6.0_06\bin\appletviewer.exe" -J-javaagent:"C:\Program Files\Fanfare\iTest 3.2\plugins\\SwingTestHarness.jar" -J-Xbootclasspath/a:"C:\Program Files\Fanfare\iTest 3.2\plugins\\SwingTestHarnessInterfaces.jar;C:\Program Files\Fanfare\iTest 3.2\plugins\\SwingTestHarness.jar;C:\Program Files\Fanfare\iTest 3.2\plugins\\xmlwriter-2.2.jar" %1


Note that you need to create this batch file only once, and you can just pass in different URLs in the session profile to launch different applets.


Now that we have a batch file, we are ready. Open up iTest to create a new Swing session profile. 

Select the radio button that says "Launch a custom application"

In the "Command to launch application", browse to the .bat file that you just created.  

In the "Additional command line options" type in the URL of the page that contains the applet.


You are all set. Now you can just start the Swing session, and you will  see the AppletViewer load up. Note that it will take more time to load the applet in applet viewer than it would normally take on a web page.  


I have attached a sample session profile and test case that loads the applet version of the "SwingSet" Java application most  people are familiar with. The applet is hosted on a remote site on the internet, so that just proves that we can test remote applets locally using this setup. My .bat file  that i call the appletLauncher is also included in the zip attachment. 

(To run the attached ecample, don't forget to update the session profile and .bat file to fit in with your machine's install location)

iTestGUI Testing(Web-Java Swing-etc)applet
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

udaya avatar image
udaya answered
You need to use a policy file if you are hitting (JAVA)security issues to access the controls on the application. Please refer KB SOL11295 for the details [link text][1] [1]:
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.