In the previous post, we learned how to integrate Selenium tests with Docker. In this tutorial, we will take a look at how to integrate VNC Viewer with Docker and debug Selenium tests in Docker using VNC Viewer. We will also learn why it’s important to run tests through VNC Viewer as well.
Why run Selenium tests in Docker using VNC viewer?
Originally, when I was preparing this post, I was going to name the title “View Selenium Tests in Docker using VNC Viewer”. Because I thought the goal is to be able to view the tests running in VNC.
However, the main reason we want to view tests in VNC viewer is to be able to debug any test issues that are happening inside the Docker. Typically, when tests are being triggered inside Docker container, you are not able to see anything that’s happening inside. But, with the help of the VNC viewer, you get a visual representation of exactly what’s going on inside Docker which makes it easier to debug your test issues.
Prerequisite
- Install a VNC client: the one I am using in this tutorial is the RealVNC
- Use Selenium Debug images: to be able to see what’s going inside the Docker container, you will need to use an image that has a VNC server installed. Any image that ends with
-debug
will have a VNC server installed - Map external VNC port to the Docker VNC port (5900): when you will run the docker image you will need to map the local VNC port to Docker VNC port (5900)
Run Selenium Standalone Debug Docker image
Let’s run the selenium/standalone-chrome-debug image and map the VNC port with it —
docker run -d -p 4444:4444 -p 5900:5900 --shm-size=2g selenium/standalone-chrome-debug:3.141.59-20210607
- -p 4444:4444 is the port for your local machine mapping to Docker Selenium server port 4444
- -p 5900:5900 is the port for your local VNC server mapping to Docker VNC server
Open Real VNC client
Now that we have a docker image running mapped to port 5900, we can open that port in VNC viewer. To do that, open up the RealVNC client and type in the URL — 127.0.0.1:5900, and hit Enter.
When prompted for a password, type secret and continue.
Run tests in Docker
Now it’s time to run tests in Docker, make sure your tests are pointed to port 4444 as that is what we have set up for our docker container (you can check out my previous post to learn more about that).
Once you will run your tests, you will notice the tests can be viewable in the VNC viewer. ??
Check out the video below to learn more about how to execute Selenium tests in Docker and view it in VNC Viewer–
In the next tutorial, I will show you how to set up Selenium Grid and run it in Docker.
Thanks for reading.