Using FEST-Swing with a Java applet

2.2k Views Asked by At

I found that FEST-Swing has the capability to automate UI actions on Java applets.

FEST-Swing can also test desktop applications as well as applets (in a viewer and in-browser.)

I tried to prepare a script to see its capabilities, but I could not figure out how to load an applet source to FEST to take actions.

How can I load a Java Applet into FEST? Specifically, I would like an example on how to load the below applet in to FEST. http://java.sun.com/applets/jdk/1.4/demo/applets/GraphicsTest/example1.html

All I want in the script is to click on Next and Previous buttons.

1

There are 1 best solutions below

2
On

how to load an Applet to a FramFixture is described here. To get this running you need to change the type of the Next-Button from Button to JButton because FEST works only on SWING Components and not on AWT Components. Additional you have to set the Name of the Button, so that FEST can identity the button in the testcase. To do this, add this line:

JButton nextButton = new JButton("next");//sets the visible Label
nextButton.setName("nextButton");//sets a name invisible for the User.

now you can find your Button in the testcase. I used this TestCase and it worked well:

public class FestTestApplet extends TestCase{

    private AppletViewer viewer;
    private FrameFixture applet;

    @Override
    public void setUp() {
      final Applet app = new GraphicsTest();
      viewer = AppletLauncher.applet(app).start();
      applet = new FrameFixture(viewer);
      applet.show();
    }

    public void testNextButtonClick() {
      applet.button("nextButton").click();//finds the button by the name
      applet.robot.waitForIdle();//give the GUI time to update
      //start your asserts
    }

    @Override
    public void tearDown() {
      viewer.unloadApplet();
      applet.cleanUp();
    }
}