我发现FEST-Swing能够自动化Java applet上的UI操作.
FEST-Swing can also test desktop applications as well as applets (in a
viewer and in-browser.)
我试图准备一个脚本来查看它的功能,但我无法弄清楚如何将一个applet源加载到FEST来采取行动.
如何将Java Applet加载到FEST中?具体来说,我想了解如何将以下applet加载到FEST中的示例.
http://java.sun.com/applets/jdk/1.4/demo/applets/GraphicsTest/example1.html
我在脚本中想要的只是单击“下一个”和“上一个”按钮.
解决方法:
如何将Applet加载到FramFixture中描述了here.为了使这个运行,您需要将Next-Button的类型从Button更改为JButton,因为FEST仅适用于SWING组件而不适用于AWT组件.另外,您必须设置Button的名称,以便FEST可以识别测试用例中的按钮.为此,请添加以下行:
JButton nextButton = new JButton("next");//sets the visible Label
nextButton.setName("nextButton");//sets a name invisible for the User.
现在你可以在测试用例中找到你的Button.我使用了这个TestCase,效果很好:
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();
}
}