Using TestRecorder in Java Applications

  February 25, 2007

TestRecorder is a set of libraries that can be integrated in your applications and provide  recording functionality like the point and click recorder in TestComplete. The recorded file can then be converted with TestComplete to any supported script code: VBScript, JScript, DelphiScript, C++Script or C#Script. TestRecorder can be used in C#, Visual Basic, Visual C++, Delphi, C++Builder and other applications.

The TestRecorder package can also be used in Java, if you use a workaround. It doesn't include components that provide direct integration with Java's IDE, but the package does include an ActiveX component, that provides access to the TestRecorder engine via COM and that you can use in your Java applications.

However, Java does not include standard features for working with COM objects and this causes a problem. As a solution, and a way to use TestRecorder, you can to create a class that will use specific third-party libraries that provide support for ActiveX and COM technologies. For example, you can use the JACOB library (JAva-COm Bridge) that you can download from http://sourceforge.net/projects/jacob-project/.

Below is a sample class that connects to and works with the TestRecorder engine via COM.

The sample class contains the following methods:

Method Description
getRecorderObject Returns a reference to the TestRecorder object.
getRecorderDispatch Returns a reference to the IDispatch interface implemented by the TestRecorder object.
TestRecorder The class's constructor.
InitRecorder Initializes the connection to the TestRecorder engine via COM. The method connected to the TestRecorder engine using the TestRecorder.TestRecorder program id.
FreeRecorder Finalizes the connection to the TestRecorder engine.
getState Returns the current state of TestRecorder.
Start, Pause, Resume, Stop Use these methods to start, pause, resume or stop recording.
SaveDataToFile Saves the recorded actions to a specified file. You can then import this file into your TestComplete project by opening the file using TestComplete's File | Import | TestRecorder Data menu item.

The TRInJavaSample.zip archive contains the sources of the sample application that demonstrates how you can use TestRecorder in Java applications. The archive contains the following files:

  • TestRecorder.java - The source code of the Java class described above.
  • TestRecorderSampleFrame.java - Source code of the application's form.
  • Build.bat - The .bat file used to compile the application.

To use the TestRecorder class, the jacob.dll module (part of the JACOB package) should reside in the same folder, where your project resides, and the path to the jacob.jar file should be listed in the CLASSPATH environment variable.