Use the Wizard to create a custom Activity - Java

Relevant for: API testing only

This task describes how to create a new activity using Java code, and deploy it in UFT.

Prerequisite

Make sure you have a JAVA_HOME environment variable defined on your machine indicating the parent JDK folder.

Back to top

Run the Activity Wizard

  1. Open the Activity Wizard from the product's start menu (Start > All Programs > Micro Focus >Micro Focus Unified Functional Testing > Tools >Activity Wizard or <UFT installation folder>\bin\ActivityWizard.exe).

  2. In the wizard's General Properties pane, select the Java as the Language.

  3. Follow the steps of the wizard to create your activity.

Back to top

Edit the code

  1. On the final screen of the wizard, click Open Folder to open the <Activity Name> folder, corresponding to the activity name you specified in the wizard. Navigate to the <Activity Name>\hp\st\ext\java subfolder and locate the MyLogic.java file.

    Caution: Do not close the Activity Wizard after this step.

  2. Edit the ExecuteLogic function inside the MyLogic.java file. Make sure to keep the Properties definition.

    public Properties Props = new Properties();
    public ExecutionResult ExecuteLogic()
    {
        try{
        //**************************
        // Execution code goes here 
        //**************************
        return ExecutionResult.Success;
        }
    ...

Back to top

Add Logger code - optional

In the MyLogic.java file, add information for the log using the Logger.LogInfo, Logger.LogDebug, or Logger.LogError statements. For example:

    try{
    ...
        Logger.LogInfo("Log Message 1");
        Logger.LogDebug("Log Message 2");
        Logger.LogError("Log Message 3");
    ...
    return ExecutionResult.Success;
    }

Back to top

Add a Report statement - optional

In the MyLogic.java file, add a Report statement, Reporter.Report, using key value combinations. For example:

    try{
    ...
        Reporter.Report{"Name","John");
    ...
    return ExecutionResult.Success;
    }

Back to top

Compile the Java into a class

  1. In your design IDE, add the ServiceTestCall.jar file to the build path.

  2. In UFT, run the CompileJavaFiles batch file in the <Activity Name>\hp\custom\java\activity folder to compile all java files into a class. This utility only compiles the files in its folder.

Back to top

Deploy the activity

  1. In the final wizard screen, click Deploy in UFT.

  2. Click Finish to close the wizard and restart UFT.

Back to top

Set up your environment for a Java Activity SDK

To set up your environment for using a Java activity SDK, do the following:

  1. Collect all necessary .jar libraries. Create new folder in the UFT installation directory, and copy all of the .jar libraries you collected into the new folder.

    For example: <UFT installation folder>\MQLibs

  2. Browse to the <UFT installation folder>\dat folder, and open the InternalJavaClasspath.dat file in a text editor.

  3. Add the paths to all the .jar files that you collected to the end of the InternalJavaClasspath.dat file.
  4. Launch UFT and use your custom JMS activity to send or receive messages.

Back to top