Setting up a Continuous Testing Environment With Selenium-Grid, Docker and Jenkins Part-2

Ahmet Yasin Türkyılmaz
3 min readFeb 4, 2020

--

Part-2 Testing Inside a Docker Container

Part 1 link: https://medium.com/@turkyilmazah/setting-up-a-continuous-testing-environment-with-selenium-grid-docker-and-jenkins-part-1-367b93f41f93

In the previous part we did the RemoteWebDriver configurations. If you are an impatience person or you have a deadline tomorrow and you tried to run the script without reading this part, you would get this error:

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

This is because we set up RemoteWebDriver and driver could not reached the URL we gave it to it. To make it reachable we must set up the Selenium Grid, and of course the Nodes. To do that you need the Selenium Standalone Server. You can do that by old fashion hard working way, which is downloading the jar file from the Selenium Website You must set up the nodes afterwards. Or you can make a single .yaml file and just run the

docker-compose up

to set up Hub and the Nodes as much as you want. Here is the docker-compose.yaml file where we set up 1 Hub and 1 Chrome and 1 Firefox Node as container.

version: "3"
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
firefox:
image: selenium/node-firefox
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444

you can find this file in this repository where I put the rest of the code.

git@github.com:ahmetturkyilmaz/SeleniumGridProject.git

After the successful installation of “docker-compose up” you’ll see

Selenium grid is up and running. Now you can integrate the code in part-1 and run it smoothly. And if you go to terminal and just type docker ps, you’ll see something like this:

And yes I have installed the Jenkins as a docker container. And there is a problem with that. If I just download the Jenkins jar file and create a pipeline, the browser settings in part-1 could work. Because the grid was going to try connecting 127.0.0.1:4444 I mean the localhost:4444. And If we assume everything went right It would probably be successful. But in a docker container it won’t work as a jar file. Networks in a docker container and your machine is not bridged. So you can’t connect by using localhost. You have to use the container name to connect Jenkins.

We will get to details of this issue on part-3

Part-3 link: https://medium.com/@ahmet.turkyilmaz/setting-up-a-continuous-testing-environment-with-selenium-grid-docker-and-jenkins-part-3-ad1f82b06e09

--

--

Ahmet Yasin Türkyılmaz

I am a Software Engineer studying Electronic Engineering in Gebze Technical University. And also working at Continuous Software.