Adding Java and JavaFX Applications to the List of Tested Applications

Applies to TestComplete 14.30, last modified on November 21, 2019

If you are testing Java or JavaFX applications, you may want to add the tested application to the Tested Applications collection of your project.

Adding Java and JavaFX Applications From the TestComplete IDE

  1. If your project does not have the Tested Applications collection, add it:

    Add the Tested Apps collection to your project

    Click the image to enlarge it.

  2. Right-click somewhere within the Tested Apps editor and select Add Application from the context menu. This will invoke the Add Tested Application wizard.

  3. On the first page of the wizard, choose Java application.

  4. On the next page of the wizard, select Generic Java Application.

  5. On the next page of the wizard, specify the launch parameters of the desired Java application:

    • Select the desired runtime environment version from the Java Virtual Machine to use box. You can either select the desired Java launcher from the drop-down list, or you can manually enter the path to the java.exe or javaw.exe executable.

    • Then you should specify how to launch your application. You can use one of the two possible ways:

      • Specify the path to the application’s .jar file in the Specify application’s .jar file box. Note that the .jar file must be created with the Main-Class header in the manifest, otherwise your application will fail to run.

      • Specify the name of the main class, which is the application’s entry point, in the Specify application’s entry point box. If you use this option, you should also specify the path to the .jar or .class file that holds the main entry point routine in the Class paths box.

    • If needed, specify the command-line options that will be passed to the Java Virtual Machine in the Environment options box and a working folder for the run in the Working folder box.

    • You can specify the parameters that will be passed to the Java application in the Command-line argument box.

    • In the Class paths box, specify the paths to Java classes used in the application. If you launch your application using its entry point, you should also add the path to the .jar or .class file that holds the entry point routine to this list.

  6. Click Finish to close the wizard. TestComplete will add the specified Java application to the list of tested applications and will use the specified parameters when launching it.

Adding Java and JavaFX Tested Applications From Tests

Instead of manual configuring of TestedApps before running tests, you can add a Java application to TestedApps from your tests. For this purpose, use the TestedApps.AddJavaApp method:

TestedApps.AddJavaApp()

The method takes no parameters. It returns the index of the new item added to the Tested Applications collection. You can then use the TestedApps.Items(Index) property to get the JavaTestedApp object corresponding to the added Java application. This object lets you specify launch parameters for the Java application as well as to run it.

The following sample script demonstrates how you can use the TestedApps.AddJavaApp method.

JavaScript, JScript

function Test()
{
  // Add a Java application to the project
  var ind = TestedApps.AddJavaApp();
  var app = TestedApps.Items(ind);

  // Specify Java application's launch parameters
  app.RunAsJar = true;
  app.JVMExecutable = "C:\\Program Files\\Java\\jre7\\Bin\\java.exe";
  app.JarFileName = "C:\\JavaApps\\SampleApp.jar";
  app.WorkFolder = "C:\\JavaApps";
  app.ApplicationArguments = "in data.txt";
  app.Options = "-verbose:class";

  // Launches the Java application
  app.Run();
  // Test the application
  …

  app.Close();
}

Python

def Test():
  # Add a Java application to the project
  ind = TestedApps.AddJavaApp();
  app = TestedApps.Items(ind);

  # Specify Java application's launch parameters
  app.RunAsJar = True;
  app.JVMExecutable = "C:\\Program Files\\Java\\jre7\\Bin\\java.exe";
  app.JarFileName = "C:\\JavaApps\\SampleApp.jar";
  app.WorkFolder = "C:\\JavaApps";
  app.ApplicationArguments = "in data.txt";
  app.Options = "-verbose:class";

  # Launches the Java application
  app.Run();
  # Test the application
  # ...

  app.Close();

VBScript

Sub Test
  ' Add a Java application to the project
  ind = TestedApps.AddJavaApp
  Set app = TestedApps.Items(ind)

  ' Specify Java application's launch parameters
  app.RunAsJar = true
  app.JVMExecutable = "C:\Program Files\Java\jre7\Bin\java.exe"
  app.JarFileName = "C:\JavaApps\SampleApp.jar"
  app.WorkFolder = "C:\JavaApps"
  app.ApplicationArguments = "in data.txt"
  app.Options = "-verbose:class"

  ' Launches the Java application
  app.Run
  ' Test the application
  …

  app.Close
End Sub

DelphiScript

procedure Test();
var ind, app;
begin
  // Add a Java application to the project
  ind := TestedApps.AddJavaApp();
  app := TestedApps.Items(ind);

  // Specify Java application's launch parameters
  app.RunAsJar := true;
  app.JVMExecutable := 'C:\Program Files\Java\jre7\Bin\java.exe';
  app.JarFileName := 'C:\JavaApps\SampleApp.jar';
  app.WorkFolder := 'C:\JavaApps';
  app.ApplicationArguments := 'in data.txt';
  app.Options := '-verbose:class';

  // Launches the Java application
  app.Run;
  // Test the application
  …

  app.Close;
end;

C++Script, C#Script

function Test()
{
  // Add a Java application to the project
  var ind = TestedApps["AddJavaApp"]();
  var app = TestedApps["Items"](ind);

  // Specify Java application's launch parameters
  app["RunAsJar"] = true;
  app["JVMExecutable"] = "C:\\Program Files\\Java\\jre7\\Bin\\java.exe";
  app["JarFileName"] = "C:\\JavaApps\\SampleApp.jar";
  app["WorkFolder"] = "C:\\JavaApps";
  app["ApplicationArguments"] = "in data.txt";
  app["Options"] = "-verbose:class";

  // Launches the Java application
  app["Run"]();
  // Test the application
  …

  app["Close"]();
}

See Also

About Tested Applications
Defining Applications to Test
About TestedApps Editor
Adding Java Web Start Applications to the List of Tested Applications

Highlight search results