16

If I want to run Selenium tests inside a Docker container with a visible (not headless) browser, what are my options?

  • Do I need to use a remote display viewer such as VNC?
  • Is it possible to use a browser on the host? (I.e. a browser that is not in the Docker container). How does this work?
  • Any other option?
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Antonis Christofides
  • 6,990
  • 2
  • 39
  • 57
  • You can go for https://aerokube.com/selenoid/ or Zalenium as mentioned in answer. We are using Selenoid (50 + containers) https://aerokube.com/selenoid/latest/ . It's serving well..If you are going to use Selenium Grid 4 then use https://github.com/SeleniumHQ/selenium/wiki/Selenium-Grid-4#using-docker – Rahul L Jun 22 '20 at 08:23

5 Answers5

5

Please consider using Zalenium (https://opensource.zalando.com/zalenium/). The headline of Zalenium is - A flexible and scalable container based Selenium Grid with video recording, live preview, basic auth & dashboard.

As mentioned above, you can check the live preview of your test cases running on the browser.

P.S.:- Zalenium is a wrapper built on top of Selenium Grid

nischay goyal
  • 3,206
  • 12
  • 23
5

Docker

Docker is a software containership platform that provides virtualization from the . In Docker, all software parts are organised as containers which includes the operating system, software, dependencies, environment variables, etc. Containers can be shared among different users, enabling quick installation and running of software and services which makes Docker user-friendly for automation testing, as the relevant container can just be downloaded and run as part of the automated test. Docker is also secure because it runs as an isolated process on the host machine.

It is to be noted that, Docker is isolated, secure and portable. However, there is no GUI and it does not run in bare metal speed.


The prerequisites

  • Python, binded with Selenium WebDriver
  • A testing framework e.g. PyTest, Nose or JUnit.
  • ChromeDriver, GeckoDriver
  • Docker (from the installation location)
  • CI tool, e.g. Jenkins or TeamCity.
  • Optional plugins, e.g. GitHub for the repository connection, Allure for reporting or BlazeMeter for performance testing, etc.

Answering your questions:

  • Do I need to use a remote display viewer such as VNC?: As per the article GUIdock-VNC: using a graphical desktop sharing system to provide a browser-based interface for containerized software Docker can run natively on Linux hosts, while a small Linux VM is necessary to provide the virtualization services on Mac OS and Windows systems. On non-Linux systems, a single Docker container consists of a mini-VM, the Docker software layer, and the software container. But recently, support for OS-level virtualization has been added to Windows and Mac OS. Beta versions of Docker for both Windows and Mac OS are now available that allow Docker to run natively.

  • Is it possible to use a browser on the host?: No, because there is no UI. But then to have a visual view of your test execution you can install X Server Display.

    With that you can see the results:

docker_tests

To view the results in a visual manner you can use the Allure report which looks like:

allure_report

  • Any other option?: There a couple of other options available as well.

Outro

How To Run Selenium WebDriver With Docker?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

My conclusion is that the canonical way of doing this is to run X with a lightweight desktop environment such as LXDE on the Docker container. Then you can connect to it with a VNC client. Using a browser on the host is not possible.

For other options, see the other answers.

Antonis Christofides
  • 6,990
  • 2
  • 39
  • 57
0
  1. You can do this:

Google Chrome Developer Tools (or DevTools) front-end is implemented as an HTML + CSS + JavaScript web application. It uses a serialized message channel in order to communicate with the inspected page. Originally, we were working on establishing this serialized asynchronous interaction in order to bring DevTools front-end out of the inspected page process. But once it was done, we could take it even further and run DevTools front-end outside the browser. Here is how you can give it a try: Run the Chrome instance that you will be debugging remotely with the remote debugging command line switch: chrome.exe --remote-debugging-port=9222 --user-data-dir=remote-profile. It is essential that you use a different instance of Chrome for the remote session and that is why we run it with the --user-data-dir argument. Navigate to the pages you intend to debug. Now run a regular (client) Chrome instance and navigate to http://localhost:9222 there. You will see a number of links that will bring you to the remote debugging sessions for the corresponding pages. Click them and enjoy debugging your Chrome pages over the wire

source

What this means is you just launch a headless chrome with it's debug port open, then you can connect to that headless chrome from another chrome browser!

This is sort of cheating since your just connecting your host browser to the headless browser in the docker-machine, but the effect is the same.

  1. For a different example of how to do this with a rails app, see this article:

https://avdi.codes/run-rails-6-system-tests-in-docker-using-a-host-browser/

The steps can be recreated with an arbitrary language/framework.

But this does actually allow your dockerized app to control your host browser.

0

Do I need to use a remote display viewer such as VNC?

Yes.

Is it possible to use a browser on the host? (I.e. a browser that is not in the Docker container). How does this work?

No

I want to run Selenium tests inside a Docker container with a visible (not headless) browser, what are my options?

You can describe such an environment using Docker-Compose. In short:

  • Selenium tests run in docker container
  • browser runs in docker container having VNC server accessible via published port to Docker host.
  • website runs in a docker container.
  • Selenium tests access the website using host name mapped to the website container.

See this for working demo.

rok
  • 9,403
  • 17
  • 70
  • 126