Abbot framework for automated testing of Java GUI components and programs
All materials Copyright © 2002 Timothy Wall, All Rights Reserved

This version 0.9.0 (030527)

Getting Started with the Abbot Java GUI Test Framework

The Abbot framework is a Java library that provides methods to reproduce user actions and examine the state of GUI components. Improving upon the very rudimentary functions provided by the java.awt.Robot class (A Better 'Bot). The framework may be invoked directly from Java code or accessed without programming through the use of scripts. It is suitable for use both by developers for unit tests and QA for functional testing.

The framework may also be used to create a demo or tutorial for an application. It can play back a prerecorded sequence of events, with optional annotations.

If you haven't done so yet, download the abbot package [tgz] [zip] (which includes source). Simply unpack and refer to the Quick Start information below.

The overview of the Abbot system will give you an idea of the different system components and how it is used. There is also some background concerning the issues involved with Java GUI testing. JUnit is used as the controlling harness for running tests and suites of tests, but scripts can easily be wrapped to run in other environments. To use Abbot directly in Java code (unit tests), see the tutorial links below, the framework tests in the test subdirectory, and the API documentation for the ComponentTester and Robot classes.

For latest changes, see the release notes. Abbot is provided under this license.

Please direct all questions and help requests to the help forum.

View Larger Image
Screenshot
Webstart Me!

(Get Webstart here)

There are two ways of using this framework. One is to write the tests directly in Java code (see Tutorial 1 or Tutorial 2 for an example). The other is to use a script to control the event playback and testing. A script editor is provided to facilitate this form of test.

Quick Start

  1. Launch the script editor.
    java -jar lib/abbot.jar
    NOTE: Under some 1.3 VMs using X11, the splash screen may trigger a VM bug. If this is the case, invoke as "java -cp lib/abbot.jar abbot.editor.ScriptEditor" instead.

  2. Create a new script.
    Select File->New Script from the menu bar to get a new script with default launch and terminate steps (you will first be prompted for a file to save it in). Launch defines a class and method to invoke to launch your GUI. Terminate disposes of all GUI components generated by the launch step.

  3. Launch the GUI.
    Edit the launch line to launch some sample code. For example, to invoke the main(String[] args) method in class example.MyCode with no arguments, you would edit the launch step to look like this:
    In the interest of keeping scripts self-contained, it is recommended that you specify the classpath in the script rather than depending on the VM classpath argument or the environment classpath. See the Launch step for usage details. Now you can use Test->Launch to display the GUI under test. The example code will display a frame with a variety of sample components.

  4. Record some user actions.
    Select Capture->All Actions (or shift+F2), and perform some user actions in the GUI. If you haven't already launched the GUI, the editor will launch it for you. The editor will detect as many high-level semantic events as it can and insert raw mouse motion and button events for what it doesn't recognize. When you get the GUI to a point that you want to make some tests of its state, press shift+F2 or activate the editor window to suspend recording. The recording so far will be inserted into the script as a sequence of steps.

  5. Add some assertions.
    Move the mouse over the component in your GUI for which you'd like to add a test and press shift+F1. That component will be selected in the component browser tree in the bottom half of the script editor. The hierarchy view presents the full hierarchy of components that have been created. Once you've selected a component, its associated properties will appear in the pane to the right. Select a property ("Text" on a JButton, for instance), then click the Assert equals button to insert an assertion into the test. Repeat as necessary for other components, or press shift+F2 to continue recording actions.

  6. Run the script.
    The script editor also allows you to run the script, recording any test failures or errors. Each step will be highlighted as it is played back, with failures and errors highlighed in red.

When you've generated several tests and want to incorporate them into a JUnit suite, you will want to derive from ScriptFixture to provide a custom ScriptTestSuite which will identify which scripts belong in the suite. ScriptFixture is a simple JUnit test case wrapper around an Abbot test script. The only thing you really need to do is return an inner ScriptTestSuite instance in the static "suite" method.

Tutorials

See also Satadip Dutta's Abbot article in the Java Developer's Journal

Examples

You can watch Abbot do its thing by running one of the prepared example test suites (as they would appear if run from the JUnit test runner). You may want to add "-Dabbot.robot.auto_delay=100" to make it look like a real person is running the tests:
java -cp lib/example.jar:lib/abbot.jar example.FontChooserTest
java -cp lib/example.jar:lib/abbot.jar example.MyCodeTest
java -cp lib/example.jar:lib/abbot.jar junit.extensions.abbot.ScriptFixture src/example/applet.xml

The second example is intended to report a failed assertion, so you can see what a failed test looks like.

Note that the last example passes an Abbot script as an argument to the ScriptFixture class to run the script as a JUnit test. For a more complete description of the framework, see the overview document.

Questions, Help, Support and Contributions

To obtain help, read the FAQ or go to the help forum on sourceforge. That way your discoveries will be available to others who might share your question.

The home page for Abbot code development may be found here. Developers are welcome; after you've submitted a few acceptable patches you may be added to the developer's group with privileges to make changes directly to the code base.

If you are looking for additional support for Abbot or test integration services, please send email and we'll point you in the right direction.

License

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

View the full license.


  This project generously hosted by
SourceForge Logo
 

Click to subscribe to java-gui-testing