FeaturesPluginsDocs & SupportCommunityPartners

Applet Testing Features

Look here for general tips.

Jemmy does not have anything now for applet testing support. However, it can be used for this. Below are some approaches how to do it. Part of the code used in examples would probably be moved into Jemmy someday.

Jemmy has been designed for java applications testing. Because of that applet testing has some serious requirements for browser which can be used for applet testing. If your browser does not satisfy that requirements (most of browsers do not), you can allways use appletviewer application from the appropriate java version. No metter what, there is a way to test applet with no browser, so you can use it instead.

So, about restrictions.

java.awt.Robot

For applet containing AWT components it's necessary for browser to use Java having java.awt.Robot class implemented, because this is the only way for Jemmy to operate with AWT components. java.awt.Robot class was first bundled with Java 2 SDK, v 1.3, so you can use appletviewer from 1.3 java or later.

If applet based on javax.swing component, it's not necessary for browser to meet this requrement.

Security restriction

To be able to run Jemmy for applet testing you have to give the test full permissions. It order to use appletviewer, put next lines into your $HOME/.java.policy file:
grant codeBase "file:<your particular filesystem>/-" {
   permission java.security.AllPermission;
};
    
Whatever browser you use, you have to have the applet on you local drive - browsers do not allow to give permissions to an applet loaded through HTTP protocol.

Testing approaches

All examples are created for the very simple applet. Take a look how it's working. Here is the part of html text executing applet:
<applet code=MyApplet.class width=300 height=200></applet>
    
MyTest test for this applet can be executed using some different approaches.

To run these examples, you'll have to
1. Download and unpack applet examples archive on you local disk.
2. Download Jemmy (if necessary) and put jemmy.jar into the directory where examples archive was unpacked.
3. Run build.sh script with no parameters to compile everything.

Applet changing

First approach consists in applet code changing, so test will be executed from applet. Indeed, you don't even have to change your applet (although it's possible). The cheepest way is to create an SubclassTestExecutor applet - superclass of yours which runs the test from start() method.

Then, you have to change your html by adding jemmy.jar and replacing applet class name. You can see it test_by_subclass.html file:
<applet code=SubclassTestExecutor.class archive=jemmy.jar width=300 height=200></applet>
    
Then, you can open page by an appropriate browser and see test working.

To run example by appletviewer use build.sh subclass command.

Running test from another applet in the same AppletContext

This can be done by executing of one more applet - ContextTestExecutor from the same html file as showed in test_by_context.html:
<applet code=ContextTestExecutor.class archive=jemmy.jar width=300 height=200></applet>
<applet code=MyApplet.class width=300 height=200></applet>
    
To run example by appletviewer use build.sh context command.

Testing applet as a component

Last approach consist in putting the applet onto Frame (JApplet on JFrame) as regular component and test it there. FrameTestExecutor shows it.

To run example use build.sh frame command.


Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by