Using the Plugin
The Swingcorder plugin allows you to control script recording and playback from within your Integrated Development
Environment (IDE) through a user interface that displays a list of available Swing applications and a list of scripts.
An example of how the plugin appears is shown below:
To begin creating new scripts, you should first identify the source folder within a Java project into which newly
created scripts are to be written. If you do not explicitly select a location, the first source folder in the first Java
project in your workstation will be used. To change the location from the default value, open the Swingcorder popup and
use the Script Source menu to select the project and then a source folder within
that project where new scripts created by Swingcorder should be written. In the following example, the
folder within the PointOfSaleTests project has been selected.
As this illustrates, the popup menu contains two entries:
- Script Source: Allows you to specify the project and source folder within
the project where new scripts created by Swingcorder are added. This value defaults to the first source folder
in the first Java project in your workstation
- Retroactive Recording: When checked, indicates that a newly created script
recording should include all activity that occurred since Swingcorder was activated for your Swing application.
That is, the recording should be retroactive to point in time when Swingcorder was activated. This value is
deselected by default, which indicates that a new recording should only include recreate user input that occurred
since the recording was started.
Let's suppose that you now activate your Swing application and that it includes a call to
to activate Swingcorder's functionality within the application. In that case, an entry will now appear in the combo box
labeled "Application:" as shown below, and the Show
buttons will now be enabled.
The application name is automatically generated by Swingcorder and is intended to make it easy to distinguish one
application from another in case you're running more than one Swing application simultaneously while recording and
replaying scripts. It's derived from the entry point ("main") class used to start your application and the time at
which Swingcorder was activated within the virtual machine in which the application is running.
The two buttons enabled are:
- Show: Pressing this button will cause Swingcorder to attempt to bring the
selected application's window to the "front" so that it has the input focus.
- Record: Pressing this button starts a new recording session for the currently
selected / displayed application.
Pressing the Record
button will cause a new entry to be added to the script table
as shown below, along with enabling the Suspend
and disabling Record
. This reflects the
fact that a new recording is active that can be suspended or stopped and that only a single recording can be in
The two newly enabled buttons are:
- Suspend: Suspends / disables recording of user input for the selected
recording session but does not end the session. In other words, user input that occurs while a session is
suspended will not be included in the script that's generated when the session is stopped. The
Resume button can be used to enable recording for the session.
- Stop: Stops recording for the selected session and generates a Swingcorder
script containing code that can be used to recreate the input that was recorded.
Pressing the Stop
button will cause the script's entry to be updated as shown
below, and the Edit
buttons to become enabled:
The newly populated "Script" column identifies the name of the class and method into which the newly generated script
was written. That script will contain code that, when executed, will recreate the user input that was recorded. In
addition, the newly enabled buttons that can be used are:
- Edit: Opens the script in the IDE's editor.
- Remove: Removes the script from the plugin table but does not delete its
corresponding source code.
- Play: Executes a script in the currently selected application.
Clicking the Edit
button will display the script as shown below:
Notice that the newly created script generates compiler errors. This indicates that the Swingcorder library has not
been added to the class path of the project in which the script was created. That library is needed because generated
and use its methods, so address this problem simply add the Swingcorder JAR to the project's class path.
Finally, click the Play button to replay the script in the selected application.
Swingcorder always creates valid scripts that can be replayed, but if you customize an existing script or create a new
one manually, be aware that a method must satisfy all three of the following conditions before it can be executed as a
- The method must be annotated with
as shown in the generated script example.
- The method signature must not specify any parameter values.
- The method must be static or be defined in a class that implicitly or explicitly supports a no-argument
Adding Scripts To the Table
A newly recorded script is automatically added to the plugin table until removed using the
button. However, you can also add existing scripts to the table using the
Swingcorder > Add Annotated Methods To Script Table
context menu item as shown
below by right-clicking on a class.
Finally, the plugin also supports a preferences page that you can use to identify the location of your product license
and customize where newly generated scripts are to be written by the plugin. Specifically, you can specify the package
into which scripts are written and whether to create a new file / class for each script or to append generated scripts
to a single specific class. To view this preferences page you must select the
Window / Preferences menu item in Eclipse and then click on the
Swingcorder node of the preferences tree.