Dockerizing Ranorex Webtestit


In the Executing tests on Selenium Grid within docker containers part of our Docker How-to series, we saw the benefits of having it all in one place - Selenium grid with Google Chrome and Mozilla Firefox nodes.

Thanks to docker and Ranorex Webtestit you can execute cross-browser and cross-platform tests with ease. But what if you want to containerize the whole thing?
In this part, we will go even further with our docker workflow and build our docker image from the scratch, from which we can then build containers packed with the latest version of Ranorex Webtestit and our java-demoshop project ready to be executed.

We will run Ranorex Webtestit from a docker container, built from a Ranorex Webtestit docker image, and run a test from within a container using our Selenium Grid. All you need for making this happen is to have a working docker installation and an internet connection :slight_smile:

Building a Ranorex Webtestit Docker Image

We will build an image locally using Dockerfile.
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.
In this example, we will use the latest Ubuntu as our base image, install the required dependencies needed to run Ranorex Webtestit in CLI mode together with the Mozzila Firefox browser, and Git client.

We can containerize the Ranorex Webtestit app in two ways:

  • Having the .deb file downloaded in the folder containing the docker file and copying the .deb file from our local system (which is the faster way
  • Downloading the .deb file directly from our server which could take some time depending on your internet connection.

In this example, we will go with the first approach. The content of our docker file looks like this:

# use the latest ubuntu image
FROM ubuntu:latest

# create the /docker folder for the root user
WORKDIR ../docker
USER root

MAINTAINER Ranorex Webtestit <[email protected]>

# define shell and setup env path mappings
SHELL ["/bin/bash", "-c"]

# speed up dpkg installations by disabling dpkg from calling sync() and the like between every package.
RUN ( \
    echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/02apt-speedup && \
    echo 'DSELECT::Clean "always";' > /etc/apt/apt.conf.d/99AutomaticClean ; \

# make sure to update before apt installations
RUN ( \
    apt-get -y update \
# install the requirements    
RUN ( \
    apt-get -y update \ 
    && apt-get install -y --no-install-recommends \
        bzip2 \
        xvfb \
        libgtk-3-dev \
        libxss-dev \
        libssl-dev \
        wget \
        curl \
        gnupg \
        kmod \
        libappindicator3-1 \
        fonts-liberation \
        xdg-utils \
        fuse \
        nano \
        python3 \
        python3-venv \
        python3-pip \
        openjdk-11-jdk \
        libsecret-1-0 \
	firefox \
        git \
        gconf2 \
	nodejs \
        gconf-service \
        libnotify4 \
        libappindicator1 \
        desktop-file-utils; \

# start the xvfb server -> server side headless UI client simulator (necessary for both Electron and the actual Browser)
RUN (Xvfb :99.0 -ac &)
RUN export DISPLAY=:99.0

# ---------------------------------------------------------------------------------------------------------------------------------------
# If you want to download webtestit from the original source uncomment the following and comment the next
# ---------------------------------------------------------------------------------------------------------------------------------------
# RUN ( \
#     wget -qO - | apt-key add - \
#     && echo 'deb [arch=amd64] bionic main' | tee /etc/apt/sources.list.d/webtestit.list \
#     && apt-get update \
#     && apt-get install -y --no-install-recommends webtestit; \
#     )
# ---------------------------------------------------------------------------------------------------------------------------------------

# ---------------------------------------------------------------------------------------------------------------------------------------
# If you don't want to download and use a local webtestit.deb instead, make sure it's lying next to where you build/run the container
# ---------------------------------------------------------------------------------------------------------------------------------------

COPY webtestit.deb ./ 
RUN dpkg -i webtestit.deb || true
RUN git clone ./java-demoshop

# print out the current path
RUN pwd
# list directories contents for demo purposes
RUN touch /docker/java-demoshop/default.endpoints.json
RUN ls -la

# Create the preconfigured default.endpoint.json file
RUN printf "{\n\
  \"endpoints\": [\n\
      \"active\": true,\n\
      \"capabilities\": {\n\
       \"applicationName\": \"\",\n\
        \"maxInstances\": 1,\n\
        \"moz:firefoxOptions\": {\n\
          \"log\": {\n\
            \"level\": \"info\"\n\
    \"platformName\": \"LINUX\",\n\
        \"seleniumProtocol\": \"WebDriver\",\n\
        \"server:CONFIG_UUID\": \"0e227eb5-f71f-41f9-8b0c-e47ee3e27059\"\n\
      \"gridUrl\": \"http://localhost:4444/wd/hub\",\n\
      \"id\": \"0479bdf9-4184-efed-d1d9-4db93c519eb3\",\n\
      \"info\": \"LINUX/MozillaFirefoxv72.0.1\",\n\
      \"name\": \"Firefox-Dockerized\",\n\
      \"platform\": \"LINUX\",\n\
      \"type\": \"seleniumgrid\",\n\
      \"version\": \"72.0.1\",\n\
      \"browserName\": \"firefox\"\n\
}" >>  /docker/java-demoshop/default.endpoints.json

# inside the folder where your project and webtestit.deb (if no download) are, build the container with:
# docker build -t webtestit .
# where -t defines a tag named webtestit and the dot is the current path

# now in another terminal connect to the docker conatiner using
# docker run -ti webtestit bash
# inside the bash run webtestit using xvfb:
# xvfb-run -a -s "-screen 0 1280x800x16" webtestit run ./java-demoshop

To recap, we are using a Ubuntu base image and installing the required dependencies as well as Ranorex Webtestit itself.
Next, we are pulling our java-demoshop project from our git repository which we will run on our also dockerized selenium grid containers. In order to start the execution we need to specify the remote endpoints (docker containers) on which our tests will be run, so we are creating the default.endpoints.json file too.

Starting the execution

To run our demo project on the predefined selenium-grid endpoint, follow the instructions from the first part and start the selenium grid and chrome node containers.

After the image has been built, we can create and run a container with the terminal interface flag:

docker run -ti  --network host webtestit bash

From the container execute the following comman:thinking:d to start our java-demoshop docker project:

xvfb-run -a -s "-screen 0 1280x800x16" webtestit run ./java-demoshop

And that’s it. The test has been successfully executed :slight_smile:

But, what about the reports :thinking:
As always, Ranorex Webtest has your back. Starting from version 1.11.0, we introduced the report-server feature which lets you upload and share your test reports directly from the app, or using CLI like in this case.
All you have to do is to start the report server on your local machine and the result will be uploaded from your docker container directly :sunglasses:

To start the report server enter the following command in your CMD/Terminal:

[path to local Ranorex Webtestit app] server

//  example :

/Applications/Ranorex\\ Webtestit server

By default, the port 8888 of your localhost is used. The default credentials are: USERNAME:password, which you can of course modify. Find out more about this feature here

Now what is left is to add the report server parameters to the run command and that’s it! From your docker container add the parameters and run the test. The complete run command would look something like this:

xvfb-run -a -s "-screen 0 1280x800x16" webtestit run  --report-server-host "hostIPAdress" --report-server-username "USERNAME"  --report-server-password "password"  ./java-demoshop

Watch the test execution and auto report upload on the video below:


Using docker containers can bring you a lot of benefits. While using continuous integration systems, software teams push code to production multiple times a day. Continuous testing is an important part of effective continuous integration systems.

Today, Docker allows you to run your tests in containers as well as isolate your tests in development and deployment. Combined with Ranorex Webtestit, which makes creating automated test suites easy as 1,2,3, you now have a simple way to make the testing process faster while saving your resources on the way.
Using docker with Ranorex Webtestit gives you the confidence that when something works on your machine it will also work for other team members and your customers and improves your continuous integration process overall.

Speaking of that, you may be interested in our Running Ranorex Webtestit in TFS/VSTS for Continuous Integration and Running Ranorex Webtestit in Jenkins for Continuous Integration articles :sunglasses:
Happy testing!

Questions regarding report server
Release notes v1.11.0