Debug Selenium Tests in Docker using VNC Viewer
Tags: docker, javascript, testing, webdev
Published: 2021-07-01 12:04:32

In the [previous post](https://dev.to/dilpreetjohal/selenium-docker-tutorial-4dkg), 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. 
VNC server pointed to port 5900

![realvnc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xm3fb6feimdjb8wvhz2d.png)
  
---

### 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. 🙌🏼

![run tests in docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m37ib9b6fslp3prfti7c.gif)

---

#### Check out the video below to learn more about how to execute Selenium tests in Docker and view it in VNC Viewer –

{% youtube SCHs3XMf1yY %}

---

📧 Subscribe to my [mailing list] (https://bit.ly/sdet-u-mailing-list) to get access to more content like this as well as free access to a Private Facebook community

👍 You can follow my content here as well - 
- [Twitter](https://bit.ly/sdet-u-twitter)
- [LinkedIn](https://bit.ly/sdet-u-linkedin)

...

I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

<a href="https://www.buymeacoffee.com/dilpreetjohal">![Buy me a coffee](https://dev-to-uploads.s3.amazonaws.com/i/4aw2ub3f4qkyjk0ivwt4.png)</a>

You can also support me by liking and sharing this content.

---

#### Enjoyed this read? Discover more insightful articles on software testing and development on my [blog](https://sdetunicorns.com/blog). 🌐