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 /src folder within the PointOfSaleTests project has been selected.

As this illustrates, the popup menu contains two entries:

Let's suppose that you now activate your Swing application and that it includes a call to SwingcorderMain.activate() 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 and Record 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:

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 Stop 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 progress.

The two newly enabled buttons are:

Pressing the Stop button will cause the script's entry to be updated as shown below, and the Edit, Remove, and Play 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:

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 scripts extend UserSimulation 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 replay script:

  1. The method must be annotated with @SwingcorderScript as shown in the generated script example.
  2. The method signature must not specify any parameter values.
  3. The method must be static or be defined in a class that implicitly or explicitly supports a no-argument constructor.

Adding Scripts To the Table

A newly recorded script is automatically added to the plugin table until removed using the Remove 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.