Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run Selenium tests in a docker container with a visible browser?

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?
like image 350
Antonis Christofides Avatar asked May 25 '20 22:05

Antonis Christofides


2 Answers

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

like image 128
nischay goyal Avatar answered Oct 05 '22 00:10

nischay goyal


Docker

Docker is a software containership platform that provides virtualization from the os. 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.
    • You can set up a Selenium Grid using Docker Compose. Zalenium is widely used in this area as it provides a flexible and scalable container based Selenium Grid with video recording, live preview, basic auth & dashboard.
    • You can also set up Selenium Grid in Kubernetes. You can find a detailed documentation in Run Selenium UI tests in Docker containers

Outro

How To Run Selenium WebDriver With Docker?

like image 24
undetected Selenium Avatar answered Oct 05 '22 02:10

undetected Selenium