Tuesday, February 6, 2018

Selenium - debug your tests in docker container

Do you have UI selenium tests running in a docker container? And if something fails, how easy it is to find the problem?

Here is something that works nicely:

1. I am using VirtualBox and I have an Ubuntu Linux machine with UI with docker and docker-compose installed.
2. Create a docker-compose.yml file:

version: '2'
services:
  hub:
    image: selenium/hub:3.8.1
    ports:
      - "4444:4444"

  firefox:
    image: selenium/node-firefox-debug:3.8.1
    volumes:
      - /dev/shm:/dev/shm
    privileged: true
    dns:
      - <your dns IP>
    environment:
      - TZ=DE
      - HUB_PORT_4444_TCP_ADDR=hub
      - HUB_PORT_4444_TCP_PORT=4444
    depends_on:
      - hub
    ports:

      - 5900

3. Open a terminal at the location of your docker-compose.yml file and deploy the selenium hub and firefox node locally, using following command:
docker-compose up


4. Check the Selenium hub and the Firefox node have started:
docker ps -a


5. Go to the VirtualBox VM Settings -> Network -> Advanced -> Port Forwarding -> and create a new rule so that you can access the container ports highlighted in green in previous image ()both Firefox node and Selenium Hub.


6. Install VNC Viewer:

7. Go to Chrome apps and start it: chrome://apps/

8. Enter localhost:5900 -> Connect -> Password is: secret


9. Here is your container.


10. Last thing you have to do is add this line to your testng.xml (I am using testng). On your local machine project in IntelliJ.

<parameter name="hubUrl" value="http://localhost:4444/wd/hub"/>


From here on you can run and debug your tests inside a local container and see what is happening.

I got this hint from a colleague and it was really helpful. I hope it helps you too :)