Create a call to a Java class

Relevant for: API testing only

The Call Java Class activity lets you to add Java steps to your test script. This feature enables you to incorporate existing Java code into your test.

Implement the UFT API Java interface

Open the <installation_folder>\addins\ServiceTest\JavaCall\Java Interface\src\hp\st\ext\java folder and create an implementation for the java interface. For an example, see the sample subfolder.

This interface includes the essential information for the Java call, such as input properties, output properties, and a point of entry. The following methods are included:

  • getInputProperties. Returns a mapping of the input property names and their Java class.

  • getOutputProperties. Returns a mapping of the output property names and their Java class.

  • Execute. A method that receives the mapping of the input property names and their actual values i.e. their object instance. In this method, you process input properties and delegate them to your own Java artifacts. Afterward you process the output properties and send their mappings and their actual values as the method's output.

Back to top

Compile the Java source code

In your IDE, compile the java files located in the <installation_folder>\addins\ServiceTest\JavaCall\Java Interface\src\hp\st\ext\java folder.

Tip: To determine which JDK to use for, check the version of Java JRE installed with UFT. Open the <installation_folder>/jre/bin folder and right-click the java.exe file. Select Properties and open the Version tab.

Package your custom step - optional

Package your java classes into a .jar file.

Set up the Java environment - optional

  1. In the canvas, select a Start or End step.

  2. In the Properties pane, open the Test Settings tab in the Properties pane. In the Test Settings tab, set the values for the VM and JMS properties.

  3. In the Toolbox pane, expand the JMS node in the Toolbox pane and drag a JMS activity onto the canvas.

  4. In the Input/Checkpoints tab of the Properties pane, set the step's properties.

    You must enter a value for the following properties:

    • Queue

    • Subscription

    • Topic name

  5. If you are using a Send activity, specify a message.

  6. If you are using a Receive activity, in the Checkpoints section of the Input/Checkpoints tab, select the output properties you want to validate and specify the expectd values.

Back to top

Add a Call Java Class activity

In the toolbox pane, expand the Java node, and drag the Call Java Class activity onto the canvas.

Back to top

Set the Java step property values

  1. In the canvas, select the Java step.

  2. In the Properties, open the Input/Checkpoints tab .

  3. In the Input/Checkpoints tab, click the Java Class button to open the Java Class Dialog Box.

  4. In the Java Class dialog box, do the following:

    1. Provide a classpath. If you packaged your Java step, click the Browse button adjacent to the Jar field and point to a .jar file. Alternatively, click the Browse button adjacent to the Package root field and point to a package root folder.

      Note: To embed the jar file and save it with the test, select Embed Jar in Test. Due to a technological limitation, if you intend to specify a class file, you must select the Embed Jar in Test option before you browse for the class file.

    2. For the Class file field, click the Browse button adjacent to the Class file field to locate the class within the .jar file or the folder. Make sure it is a class that implements the ServiceTestCall interface.

    3. To provide additional classpaths, click the Jar or Folder buttons in the Additional Classpaths section and browse to a .jar file or classpath folder. Click Add to move the contents into the list.

    4. Click OK to save the Java Call settings.

    Back to top