10 min read time

Execute your UFT Pro (LeanFT) tests in Docker

by   in DevOps Cloud

(This post was written by Dror Saaroni,  LeanFT R&D Manager)

Introduction

UFT Pro (LeanFT) is a functional test automation solution that enables automating applications of common technologies, including Web applications. LeanFT is a cross-browser and cross-platform solution that allow developers and dev-testers to create and execute functional tests on their chosen environment.

Docker is a software container platform that simplifies the creation, management and deployment of applications by utilizing containers. Using containers, it is easier to package the application with all its libraries and dependencies and run it the same manner regardless of where it is deployed.

In LeanFT 14.01, we provide an integration between LeanFT and Docker. Specifically, we are providing our customers with a number of Docker images that they can use in order to execute their tests in a Docker environment. We want to make your functional testing as easy—and effective—as possible; adding this container integration allows us to do this.

In this blog, we will cover the benefits for using LeanFT inside a Docker container, the different modes for executing the LeanFT containers and we will drill down a bit into the implementation details.

 

Why use Docker?

There are a few questions you may be asking yourself: Why should I use Docker to execute my tests? What are the benefits that I can gain if I add Docker to the game?

There are couple of reasons why you would decide to use LeanFT’s Docker integration:

  • Zero Installation – The Docker image contains everything that is needed in order to execute the test.
  • Background Execution – The Docker container is running in the background and launches the browser in the container, so it won’t interfere with the user working on the machine.
  • Execution Box – The Docker images can execute the test by itself, so everything is happening in the container and the container is stopped once the test finishes.
  • CI/CD Readiness – CI/CD environments offer support for execution of Docker containers. This integration fits perfectly with Dockerizing the CI process.

From LeanFT 14.01, you can use LeanFT with Docker and enjoy all the benefits listed above. The LeanFT images contain everything needed in order to easily execute your LeanFT tests.

 

Using the LeanFT-Docker Integration

In the LeanFT- Docker integration, we provide three Docker images that you can run in order to execute your tests. We provide the leanft, leanft-chrome and leanft-firefox images. Later on, we will see how to run these images and create container out of them.

There are two core modes that you can use the LeanFT – Docker Integration: as a standalone or as an execution box.

In the standalone mode, the LeanFT container will be started and will launch the LeanFT engine. Once the engine is launched, it will wait for commands. The user will need to execute his test on his machine and make sure the SDK is configured to run against the Docker container. When the test is run by the user, all the commands will be executed inside the Docker container. This mode is exactly like working against a remote machine. In this mode, the user is responsible for running the Docker container and stopping it when it is no longer needed. This mode eliminates the need to install the LeanFT engine on the client machine and the execution does not interfere with the client’s environment.

In the “execution box” mode, the LeanFT container will be started and will execute the test by itself. The tests itself will be executed inside the container. Once the test is finished the container will be stopped. This mode is like working on the user’s machine where the test and the engine are executed in the same environment. The user doesn’t need to worry about stopping the container because it stops automatically once the test is finished.

The LeanFT containers offering has a VNC server inside. The VNC allows the user to connect to the container and see what is going on inside. This capability allows the user to connect to the container using a VNC client and see what happens inside the container, and can simplify a debugging session when needed.

So now that we know what the different modes are, let’s drill down to how we can use the LeanFT container.

 

Standalone mode 

The command below should be run from the command line in order to execute the LeanFT container in a standalone mode. This mode will launch the LeanFT engine and will wait for tests to connect to it.

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

 

Let’s go over the command and explain each element.

docker run – this is docker CLI which runs a container

-it – executes the container in the foreground

-p 5095:5095 - maps the host’s port 5095 to the container’s 5095 port. This port is used for the LeanFT engine.

-p 5900:5900 - maps the port 5900 to the container’s 5900 port. This port is used for the VNC.

--add-host=license-server:xx.xx.xx.xx  - instructs the container which IP to use for the license server (you need to replace the xx.xx.xx.xx with the license server IP)

leanft-chrome   - the LeanFT image. This image contains the LeanFT and the chrome browser 

 

And now in plain English. In the above command we tell the Docker to create a new container from the leanft-chrome image. We tell it to be executed in the foreground so we can track the output of the container and can stop it using Ctrl C. We are mapping the 5095 port so when we connect to 5095 (the default LeanFT engine port) it will go to the 5095 port of the container and will connect to the engine. Same thing is with the 5900 port, the VNC port. The last thing is the license server. The container uses a license server so we need to tell the container where the license server is located.

When running the command from the command line, this is what you will see:

1.png

When you run a test against the container, the test will connect to the engine that is located inside the container and all the commands will be executed inside the container (i.e. the browser will be launched inside the container). Once the test finishes, the run results will be located in the regular location and you will be able to see that the operating system is actually Docker.2.png

 

Execution box

The below commands should be run from the command line in order to execute the LeanFT container in an execution box mode. This mode will launch the LeanFT engine and will execute the tests. Once the test is done, the container will finish as well.

The LeanFT Images which are based on Linux containers support executing LeanFT JavaScript based tests and Java based Tests. We will now see two examples of how to execute a Mocha test and a JUnit test.

The command line will execute a LeanFT JavaScript based test.

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-chrome

In this case, we don’t need to map the LeanFT engine port (5095) as everything is executed inside the container. The only port that we exposed is the 5900 in case we want to connect to the container using a VNC client.

-v <full path on the host’s machine to JavaScript project>:/tests - we map the host’s tests to the /tests directory inside the container

-w /tests - indicates that the working directory on the container will be /tests (this is the directory that we mapped our tests ). The container will use the working directory in order to look for the tests.

Plain English: we tell the Docker to execute a new container based on the leanft-chrome. We are mapping the local host path to the /tests directory and tells the container to start from this directory.
Once the container starts, it will look for a package.json file in the directory, and if it exists, the container will execute “npm test”.

When running the command from the command line, this is what you will see:

3.png

The command line below will execute a LeanFT Junit-based test in an execution box mode.

docker run -it  -p 5900:5900 --add-host=license-server:16.60.133.93 -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

-v < full path on the host’s machine to java jars>:/tests - we map the host’s tests to the /tests directory inside the container

-w /tests - Indicates that the working directory on the container will be /tests (this is the directory that we mapped our tests ).

-e RUN_MODE=junit - We indicate that this is a JUnit test

-e RUN_CMD="com.company.LeanFtTest" - We tell the container to execute the joint and use the “com.company.LeanFtTest” class

Plain English: We tell the Docker to execute a new container based on the leanft-chrome image. We map the local host path to the /tests directory and tell the container to start from this directory.
Once the container starts, as there is a RUN_CMD environment variable indicating this is a JUnit test, it will use RUN_CMD in order to execute the tests that are in the “com.company.LeanFtTest” class.

Both commands mentioned above will execute the test inside the container. Once the tests finish, the report will be generated in the same directory as it was executed from (i.e. /tests). Because the directory is mapped, you will be able to access it from the host as well. So even though the test was executed inside the container, the test itself and the generated results are located on the host machine and are easily accessible.

 

Avialable Images

As part of the LeanFT-Docker integration we provide three Docker images: leanft, leanft-chrome and leanft-firefox.

The leanft image is the basic image which contains the engine and the capabilities to execute LeanFT’s tests.

The leanft-chrome and the leanft-firefox are images that were built on top of the base leanft image and in addition to the engine they contain also the Chrome and Firefox browsers.
This structure of images enables the user to create his own leanft-chrome / leanft-firefox images in case he would like a new version of chrome or Firefox to be in his repository. Take a look in the hub in order to see how you can get the Dockerfile to build your own leanft-chrome or leanft-firefox.

The images are located in the Docker hub under the functionaltesting organization (i.e. https://hub.docker.com/r/functionaltesting/leanft/)

In order to get the images you can use the command:

docker pull functionaltesting/leanft

 

Summary

In this blog we reviewed the new LeanFT – Docker integration, the different execution modes and their benefits, the different images, how to create containers from these images and some actual commands.

Docker provides many capabilities and can be executed in different modes, you can take LeanFT images and use them based on your experience and your development processes.

Happy testing in containers.

 

About UFT Pro (LeanFT)

 UFT Pro (LeanFT) is a powerful test automation solution that was built specifically for continuous testing and continuous integration. It enables advanced automation engineers and dev-testers in agile teams to leverage the standard development IDEs for test automation.

LeanFT provides a comprehensive automation SDK (available for Java, C# and JavaScript) that can be used to automate applications of all the common technologies (desktop, web and mobile). It provides plugins for Visual Studio, Eclipse, and IntelliJ, which contains powerful tools like the Object Identification Center, Application models, and much more.

You can find more information about LeanFT, in the LeanFT Help Center.

 

 

 

Labels:

Functional Testing