Run UFT tests in a Windows Docker container

Use a UFT Docker image to speed up UFT maintenance and test runs.

  • UFT's Docker image enables you to run mobile tests in a Windows Docker environment, using UFT Mobile and UFT automation scripts.
  • The UFT 15.0.1 docker image also supports running API tests in a Windows Docker environment.

This topic assumes some knowledge in Docker management and does not describe the Docker management steps in detail.

Overview

To run UFT tests in a docker container, you must perform the following steps, which are described in more detail below:

  1. Pull the UFT docker image from the Docker hub
  2. Create a container based on that docker image
  3. Install a concurrent UFT license on the container.
  4. Run your UFT tests in the docker containers.

You must install a UFT license on each UFT docker container that you use. You can handle this in one of the following ways:

  • After installing the UFT license, you can commit this container to a new image. Then, create all subsequent containers based on the new image, an avoid additional license installations.

  • After installing the UFT license, use the same container for subsequent runs, stopping and starting the container as needed.

  • Use a docker command that creates a new container, installs the concurrent license, and then runs the tests.

Back to top

Set up the UFT Windows Docker container

Prerequisite

Install and set up Docker Desktop on your computer so it can pull Docker images from the Docker Hub. This means your computer is now a docker host.

For details on setting up Docker, see the Docker documentation.

Pull the UFT Docker image

In a command window on the host computer, run the following command:

docker pull functionaltesting/uft[:tag]

where functionaltesting/uft is the UFT Docker image name and [:tag] is an optional flag to add for a specific UFT image version. By default the tag value is latest.

Create the Docker Windows container from the UFT Docker image

In a command window on the host computer, run the following command:

docker run -it --name <container name> functionaltesting/uft[:tag] "cmd.exe"

This command creates the container and also opens a command window that belongs to the container. Use this window in the next step to install a UFT license.

Note: The UFT Docker image is based on Windows 10. If you use a docker host with a different OS, you may encounter a message about OS incompatibility. Consult the Docker documentation to mitigate this issue. For example, adding --isolation=hyperv to the command may solve the problem.

Install a UFT concurrent license in the Docker container

UFT's Docker image is supported for concurrent licenses only, a license being consumed from the server each time a docker container uses UFT.

In a command window for your docker container, install a concurrent UFT license on the container. For details, see Manage licenses with the command line.

Back to top

Run mobile tests in your docker container

After installing and configuring your docker container, set up the UFT-UFT Mobile integration, create UFT automation scripts, and then run the scripts in the docker container.

Configure UFT's integration with UFT Mobile

To run tests on mobile devices, make sure that UFT Mobile and your applications are set up for the integration. For details, see Set up UFT Mobile to integrate with UFT.

The UFT automation scripts that you create in the next step set up the connection to UFT Mobile.

Create a UFT automation script with UFT Mobile

Running UFT tests on your Docker container is done via a UFT automation script that contains the specific steps required to run your tests in UFT Mobile.

Your script should include the following parts:

  • Launch UFT.
  • Use the MCConnection Options object to configure the UFT's connection to UFT Mobile.
  • Use Launch methods to start your application.
  • Run your UFT test.
  • Close the test.
  • Close UFT.

The following is a sample script used to run a specific test in UFT Mobile.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True
qtApp.Options.MCConnection.Server = "<UFT Mobile server>"
qtApp.Options.MCConnection.Port = "<UFT Mobile server port>"
qtApp.Options.MCConnection.Username = "<UFT Mobile server user name>"
qtApp.Options.MCConnection.Password = "<UFT Mobile server user password>"
qtApp.Options.MCConnection.UseSSL = false
qtApp.Options.MCConnection.SharedSpace = "<UFT Mobile server TenantID>"
qtApp.Options.MCConnection.WorkSpace = "<UFT Mobile server workspace ID>"
qtApp.Options.MCConnection.ShowRemoteWndOnRun = true
qtApp.Open "<UFT script path>", True
Set qtMobileLauncher = qtApp.Test.Settings.Launchers("Mobile")
qtMobileLauncher.Lab = "MobileCenter"
qtMobileLauncher.Device.OS = "<Device OS Type>"
qtMobileLauncher.Device.ID = "<Device UDID>"
Set launchApp = qtMobileLauncher.LaunchOnStart
launchApp.IsPackaged = True
launchApp.Counter = 1
qtMobileLauncher.InstallApps = true
qtMobileLauncher.RestartApps = true
qtMobileLauncher.UninstallApps = false
qtMobileLauncher.TrackCPUMetric = true
qtMobileLauncher.TrackMemoryMetric = true
qtMobileLauncher.TrackFreeMemoryMetric = true
qtMobileLauncher.TrackLogs = true
Set qtpResultsOpt = CreateObject("QuickTest.RunResultsOptions") 'create the run Results Options object
qtpResultsOpt.ResultsLocation = “<HTML report path>”
qtApp.Test.Run qtpResultsOpt ' Run the test
qtApp.Test.Close
qtApp.Quit

Note: If you copy this text for use in your automation script, make sure to replace the placeholders for the UFT Mobile server connection details with the values from your UFT Mobile server.

For more details, see:

Run your UFT automation script in the Docker container

In a command window on the host computer, run the following command:

docker run -it --name <container-name> -v <host-directory>:<container-directory> functionaltesting/uft[:tag] cmd //Add [:tag] to specify a UFT image version. Default is 'latest'.

Install a concurrent UFT license on the container. See Manage licenses with the command line.

cd <container-directory>

<script-name>.vbs //Run the AOM script

where:

Parameter name Description

<container-name>

The name of your Docker container. Use a unique container name to create a new container.
<host-directory>

The full path to the host directory on the machine where the automation script is stored.

This directory is mounted to the <container-directory> location on your Docker container.

<container-directory> The full path to the directory on your Docker container where the <host-directory> is mounted.
<script-name> The name of the UFT automation script configured to run your UFT tests.

Note: Include the optional [:tag] for a specific UFT image version. By default, the tag value is latest.

Your tests are run as configured.

Back to top

Run a UFT API test in a Docker container

Supported on UFT versions 15.0.1 and later

Run your API test in one of the ways described below.

Prerequisites

  • Set up a UFT Docker container as described above.
  • On the host computer, create a local directory for your API tests and store the test folders there. Docker will mount this directory to a directory in your Docker container.

To run the tests in a new container based on an image you created with the UFT license installed

In a command window on the host computer run the following command:

docker run -v <host-test-directory >:<container-test-directory> --name <container-name> <image-with-licensed-uft> "<UFT installation folder>\bin\HP.ST.Fwk.InternalExecuter.exe" -test <container-test-directory> -reportPath <report-directory-path>

where:

Parameter name Description

<container-name>

The name of the Docker container to create for this run.

Use a unique container name to create a new container.

<host-test-directory>

The full path to the API test on the host computer.

This directory is mounted to the <container-test-directory> location on your Docker container.

Example: C:\DockerProject\tests\apitest, where C:\DockerProject\tests is the local directory you created for your tests and apitest is the name of the test you stored there.

Note: The test-name part of this path is case sensitive.

<image-with-licensed-uft> The image that you committed after installing the UFT license. This image is used to generate the new container that runs your test.
<container-test-directory> The full path to the directory on your Docker container where the <host-test-directory> is mounted.
<report-directory-path>

(Optional) The path to the directory in which to store the test results. Provide a relative path, relative to the <container-test-directory>.

By default, the results are saved under the test folder, overwriting the results of any previous runs.

For example if your host test directory was C:\DockerProject\tests and the test name is apitest, the command would look like this:

docker run -v C:\DockerProject\tests\apitest:C:\tests\apitest --name apirun functionaltesting/uft:latest "C:\Program Files (x86)\Micro Focus\Unified Functional Testing\bin\HP.ST.Fwk.InternalExecuter.exe" -test C:\tests\apitest

To run test on an existing container

In a command window on the host computer run the following command:

docker exec -it <container-name> "<UFT installation folder>\bin\HP.ST.Fwk.InternalExecuter.exe" -test <container-test-directory> -reportPath <report-directory-path>

where:

Parameter name Description

<container-name>

The name of the existing Docker container to use for this run.

Tip: Make sure the container is running before you run this command.

<container-test-directory> The full path to the directory on your Docker container where the <host-test-directory> is mounted.
<report-directory-path>

(Optional) The path to the directory in which to store the test results. Provide a relative path, relative to the <container-test-directory>.

By default, the results are saved under the test folder, overwriting the results of any previous runs.

For example if your container name is apirun, the host test directory was C:\DockerProject\tests and the test name is apitest, the command would look like this:

docker exec -it apirun "C:\Program Files (x86)\Micro Focus\Unified Functional Testing\bin\HP.ST.Fwk.InternalExecuter.exe" -test C:\tests\apitest -reportPath result1

Back to top

Use Jenkins to trigger a UFT API test run in Docker

Supported on UFT versions 15.0.1 and later

After setting up your Docker container, you can use Jenkins to trigger the UFT API test run:

  1. On the host computer, create a local directory for your API test and store the test there.

  2. Add the Docker container as a slave in Jenkins.

  3. Add a build step and select “Execute Windows batch command”.

  4. In the step, insert the command to trigger the test. Do one of the following: 

    • Create a new container based on a UFT Docker image that was committed after installing a license and then run the API tests.

      docker run -v <host-test-directory >:<container-test-directory> --name <container-name> <image-with-licensed-uft> "<UFT installation folder>\bin\HP.ST.Fwk.InternalExecuter.exe" -test <container-test-directory> -reportPath <report-directory-path>

    • Create a new container based on the downloaded UFT image, install a concurrent license on the container, and then run the API tests:

      docker run -dit --name <container-name> -v <host-test-directory >:<container-test-directory> functionaltesting/uft[:tag] cmd.exe /C " " <UFT installation folder>/bin/HP.UFT.LicenseInstall.exe" concurrent <license ID> <license version> <primary server name/address>:<port> & "<UFT installation folder>/bin\HP.ST.Fwk.InternalExecuter.exe" -test <container-test-directory> -reportPath <report-directory-path>

    For details on this command, see Run a UFT API test in a Docker container

Back to top

See also: