Run tests in Docker containers

Docker is a software container platform. It is designed to make it easier to create, deploy, and run applications by using containers.

Containers include everything required to make software run. They do not bundle a full operating system (like VMs do), only libraries and settings, which make them efficient, lightweight, self-contained systems.

Note: This topic is aimed at people familiar with Docker. If you are new to Docker and would like to learn more, we recommend that you visit the Docker website.

LeanFT and Docker

LeanFT provides Docker images enabling you to run your tests in Docker containers.

Using Docker containers has major benefits for developers, DevOps, and the enterprise:

  • Zero installation. Run LeanFT tests without having LeanFT installed on your machine.
  • Background execution. Run your tests in the background and continue to work without distraction.
  • Execution box. Use a single command to run the Docker image, the test, and close the container when the test is done.

Back to top

LeanFT Docker images

There are three LeanFT docker images:

  • functionaltesting/leanft. The basic LeanFT image, which contains the engine and the capabilities to run LeanFT tests.
  • functionaltesting/leanft-chrome. The basic LeanFT image with a Chrome browser.
  • functionaltesting/leanft-firefox. The basic LeanFT image with a Firefox browser.

You can use the basic functionaltesting/leanft image that we supply and create a customized image that runs a different browser version. For instructions refer to the Docker Hub website.

Tip: To find out which version of Chrome or Firefox browsers are include with the image, add the following to the end of the docker command (described in Run the Docker image):

Chrome: google-chrome --version

Firefox: firefox --version

Back to top

Standalone mode vs. execution box mode

You can run LeanFT tests in two modes: standalone or as an execution box.

Standalone

This mode is like running tests remotely.

In this mode, you start the LeanFT container which launches the LeanFT engine. The engine then waits for commands. You run the test separately, on your machine. The test must include the Docker address (IP or host name) for connecting to the Docker image. When you run the test, the commands are executed within the Docker container. You need to stop the container when you are done.

Execution box

This mode is like running the LeanFT engine and the test on the same machine.

In this mode, you run the LeanFT container, which launches the test within the container and closes the container when the test completes.

Back to top

License usage

LeanFT Docker integration is supported only for concurrent licenses. For more details on license types, see LeanFT license types.

When you run the LeanFT image, you need to indicate which license server to use. You can do that in one of two ways:

  • Using --add-host=license-server:<enter your license address>
  • Using the LFT_LIC_SERVER environment variable. For more details, see License.

Back to top

Download the LeanFT image to your registry

Before you begin you must first have Docker installed on your machine.

Download the functionaltesting/leanft/functionaltesting/leanft-chrome/functionaltesting/leanft-firefox images to your machine using the pull command from a command line. For example:

docker pull functionaltesting/leanft

Back to top

Run the Docker image

Decide in which mode you want to run the Docker image standalone mode or execution box. For details, see Standalone mode vs. execution box mode.

To run the Docker image in standalone mode

Run the following from a command line:

docker run -it -p 5095:5095 -p 5900:5900 --add-host=license-server:xx.xx.xx.xx <leanft container>

What does this command do?

docker run The Docker CLI command for running the container.
-it Instructs the Docker to run in the foreground so that you can track the output of the container. You can use Ctrl+C to stop the container.
-p 5095:5095

Maps the host's 5095 port (the LeanFT default port) to the container's 5095 port, to connect to the LeanFT engine.

-p 5900:5900

Optional. Maps port 5900 to the container's 5900 port, to connect to a VNC.

Use this option if you would like to see the Docker container. For example, for debugging purposes.

When you connect to the VNC client, use the password: PASSWORD

--add-host=license-server:xx.xx.xx.xx Instructs the container which IP address to use for the LeanFT license server. Replace xx.xx.xx.xx with your license server IP address.
<leanft container> Instructs Docker to create a container. Possible values: functionaltesting/leanft, functionaltesting/leanft-chrome, functionaltesting/leanft-firefox.

To run the Docker image as an execution box

This mode is supported for both Java and JavaScript. Following are both options.

Java

Run the following from a command line:

docker run -it -p 5900:5900 --add-host=license-server:xx.xx.xx.xx -e RUN_MODE=junit -e RUN_CMD="com.company.LeanFtTest" -v < full path on the host’s machine to java jars>:/tests -w /tests leanft-chrome

What does this command do?

docker run The Docker CLI command for running the container.
-it Instructs the Docker to run in the foreground so that you can track the output of the container. You can use Ctrl+C to stop the container.
-p 5900:5900

Optional. Maps port 5900 to the container's 5900 port, to connect to a VNC.

Use this option if you would like to see the Docker container. For example, for debugging purposes.

When you connect to the VNC client, use the password: PASSWORD

--add-host=license-server:xx.xx.xx.xx Instructs the container which IP address to use for the LeanFT license server. Replace xx.xx.xx.xx with your license server IP address.
-e RUN_MODE=junit

Indicates that this is a Junit test.

-e RUN_CMD="com.company.LeanFtTest" Instructs the container to run the Junit using the com.company.LeanFtTest class.
-v < full path on the host’s machine to java jars>:/tests

Maps the host’s test directory to the container's /tests directory.

After the test report is generated you will be able to access it from the your machine.

-w /tests Indicates that the working directory on the container will be /tests. This is where the tests reports will be generated.
<leanft container> Instructs Docker to create a container. Possible values: functionaltesting/leanft, functionaltesting/leanft-chrome, functionaltesting/leanft-firefox.

JavaScript

docker run -it -p 5900:5900 --add-host=license-server:xx.xx.xx.xx -v <full path on the host’s machine to javascript mocha project>:/tests -w /tests <leanft container>

What does this command do?

docker run

The Docker CLI command for running the container.

Note: This command runs npm test, which runs the test script in the package.json file. Make sure that the test script is defined correctly in the file. For example:

"scripts": {
"test": "jasmine plutoE2e.js"
}
-it Instructs the Docker to run in the foreground so that you can track the output of the container. You can use Ctrl+C to stop the container.
-p 5900:5900

Optional. Maps port 5900 to the container's 5900 port, to connect to a VNC.

Use this option if you would like to see the Docker container. For example, for debugging purposes.

When you connect to the VNC client, use the password: PASSWORD

--add-host=license-server:xx.xx.xx.xx Instructs the container which IP address to use for the LeanFT license server. Replace xx.xx.xx.xx with your license server IP address.
-v <full path on the host’s machine to javascript project>:/tests

Maps the host’s test directory to the container's /tests directory.

After the test report is generated you will be able to access it from the your machine.

-w /tests Indicates that the working directory on the container will be /tests. This is where the tests reports will be generated.
<leanft container> Instructs Docker to create a container. Possible values: functionaltesting/leanft, functionaltesting/leanft-chrome, functionaltesting/leanft-firefox.

Back to top

Run the LeanFT image with environment variables

Run the LeanFT image with various environment variables to control how the container runs.

Prefix each variable that you run with -e. For example: 

docker run -it -p 5900:5900 --add-host=license-server:xx.xx.xx.xx -e RUN_MODE=junit -e RUN_CMD="com.company.LeanFtTest" -v < full path on the host’s machine to java jars>:/tests -w /tests functionaltesting/leanft-chrome

The following table includes the environment variables, their description, and possible values.

Run commands

RUN_MODE Determines how to run the container.

junit: runs a junit test using RUN_CMD s/sa/standalone: runs the container in standalone mode.

c/custom: runs the command in RUN_CMD. Use along with RUN_CMD when you want to run a custom command.

RUN_CMD Runs a command.

The command to run.

Use this option when you want to run a custom command.

VERBOSE Determines whether to print debug information. true
LFT_SAPUI5_ADDIN Indicates loading the SAPUI addin. true
NOVNC

Indicates disabling the VNC session.

The default is false.

true
USER_UID If you run docker on Linux , we recommend that you pass your user ID in order to manage the test results files. Your user ID
USER_GID (Optional) If you run docker on Linux , pass your group ID to provide group permissions. Your group ID

License

LFT_LIC_SERVER

The license server IP address or host name.

Can be used instead of --add-host=license-server:xx.xx.xx.xx

The license server IP address or host name.
LFT_LIC_ID The license ID that you want to use. The default is 20524. license number
LFT_LIC_ID_VERSION

The license ID version.

The default is 1.

version number

Mobile Center

You must use all three environment variables.

LFT_HPEMC_ADDRESS Use this variable along with LFT_HPEMC_USER and LFT_HPEMC_PASS to run Mobile Center in the container. The Mobile Center IP address or host name.
LFT_HPEMC_USER The Mobile Center user name used for logging on. The Mobile Center user name.
LFT_HPEMC_PASS The Mobile Center password used for logging on.

An encrypted password using the docker container machine encryption. For example:

docker run -it leanft /opt/leanft/Tools/password-encoder -me <password>

Proxy

Use these variables if you are running behind a proxy server.

http_proxy Your organization's http proxy. Host name or IP address and port
https_proxy Your organization's https proxy. Host name or IP address and port
no_proxy Any address that does not require a proxy, such as you local host. Host name or IP address and port

The following is an example of running a Chrome LeanFT image with Mobile Center, phantomjs, a license server, and proxy.

docker run --rm VERBOSE=true -e LFT_LIC_SERVER=leanftserverlic.domain-name.net -e LFT_HPEMC_ADDRESS=http://xx.xx.xx.xx:8080 -e LFT_HPEMC_USER=example@domain-name.com -e LFT_HPEMC_PASS=ecaae557993048276e -e http_proxy=http://proxy.mycorp.net:8080 -e https_proxy=http://proxy.mycorp.net:8080 -e no_proxy=127.0.0.1 -p 5095:5095 -p 5900:5900 -it functionaltesting/leanft-chrome

Back to top

See also: