Harrington Web

Docker Compose a Selenium Grid

Wednesday, March 16, 2016
There are times when you would like to Selenium Grid quickly so that it can scale to whatever testing goal is you want to achieve.
To start out you will need to get Docker you can goto Docker.com to find out more information on installing.

Create a docker-compose.yml

Make a new directory and name a file docker-compose.yml inside that directory. The contents are below.
  image: selenium/hub
    - "4444:4444"
  image: selenium/node-chrome
    - hub
    - "5555"
  image: selenium/node-firefox
    - hub
    - "5555"
Once you have created your file goto that directory in your command line. This will create your instances and download necessary files.
$ docker-compose build
To run your instances you can run the following and it will start your servers.
$ docker-compose up
At this point you can now point your test code to as the selenium server. You will notice at this point that you are running only 1 Chrome and 1 Firefox container on your grid. Scaling is very simple. With your servers running you just need to run an additional command to scale to your needs. For instance lets say we want to scale up to 10 Chrome instances.
$ docker-compose scale chrome 10
Voila! you now have 10 chrome containers running on your machine. Scaling works very simple, however keep in mind that memory and processors play a big role in how many you can run on a single machine. With the Chrome container memory is very important. I find that I generally want 1gb of physical memory per Chrome container that I need. Firefox seems to be less and can tolerate 512mb most the time.

No comments :

Post a Comment