Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set up selenium grid using docker on windows?

Steps I have taken already
1. Downloaded and installed Docker Toolbox for windows
2. Open Docker Quickstart terminal
3. Entered the below commands to pull the docker images from dockerhub and run them
docker pull selenium/hub
docker pull selenium/node-chrome
docker pull selenium/node-firefox
docker run -d -P \--name hub selenium/hub
docker run -d --link hub:hub -P \--name chrome selenium/node-chrome
docker run -d --link hub:hub -P \--name firefox selenium/node-firefox

It appears to be running when I type docker logs hub but I am unable to route my tests to the hub's address on the virtualbox VM using seleniumAddress in my conf.js file or see it using http://ipAddress:4444/grid/console .

Ideally I would like to use this set up to expand the amount of parallel test instances I can run.

like image 455
sonhu Avatar asked Apr 21 '16 14:04

sonhu


People also ask

What is a docker in selenium grid?

Docker compose is the tool using which you can Selenium Grid on multiple containers. You can deploy Selenium Grid with hub and nodes for parallel execution. Docker-compose uses YAML file to configure the application services like a hub, chrome and Firefox will be the services in this case. Create a docker-compose.

How do I create a docker file in selenium?

Deploy Selenium Grid by running Selenium Hub and then separate nodes for Chrome/Firefox combinations. These nodes would be connected to Selenium Grid. Create Docker image which would contain everything necessary for running tests (rvm, ruby) Run that image as a docker container and copy over content of our tests.


2 Answers

Unfortunately the selenium docker image might be broken since 4 days ago but you can try my alternative one:

  1. Pull the image and run as many containers as you need

    docker pull elgalu/selenium
    
    docker run -d --name=grid4 -p 4444:24444 -p 5904:25900 \
        -v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium
    
    docker run -d --name=grid5 -p 4445:24444 -p 5905:25900 \
        -v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium
    
    docker run -d --name=grid6 -p 4446:24444 -p 5906:25900 \
        -v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium
    
  2. Wait until the all the grids started properly before starting the tests (Optional but recommended)

    docker exec grid4 wait_all_done 30s
    docker exec grid5 wait_all_done 30s
    docker exec grid6 wait_all_done 30s
    

After this, Selenium should be up and running at http://localhost:4444/wd/hub. Open the url in your browser to confirm it is running. If you are using Mac (OSX) or Microsoft Windows localhost won't work! Find out the correct IP through boot2docker ip or docker-machine ip default.

So set the selenium port accordingly for each of your test:

  • 1st test should connect to http://ipAddress:4444/wd/hub
  • 2nd test to http://ipAddress:4445/wd/hub
  • 3rd test to http://ipAddress:4446/wd/hub

You can run as many as your hardware can take.

like image 56
Leo Gallucci Avatar answered Oct 26 '22 12:10

Leo Gallucci


Take a look at the Protractor Cookbook w/ Docker. The instructions are listed step-by-step using selenium-grid and docker compose. Docker-selenium issue #208 has been fixed.

So you'll need to pull down the latest images*:

docker pull selenium/hub:latest
docker pull selenium/node-chrome-debug:latest

Start the selenium grid:

docker run -d -p 4444:4444 --name selenium-hub selenium/hub:latest

Then add selenium nodes. I like to use the chrome-debug and firefox-debug versions to VNC to watch the tests.

docker run -d -p <port>:5900 --link selenium-hub:hub selenium/node-chrome-debug:latest

After linking your selenium grid, this should be enough to run your Protractor test using the seleniumAddress: 'http://localhost:4444/wd/hub'.

For debugging, find the VNC port for the container with:

docker port <container-name or container-id> 5900

and access it via VNC Viewer.

Note:

  • At the time of this writing, 'latest' appears to be tied to a ~2.53.1 version of selenium server. As of Protractor 4.0.11 (the latest version of Protractor), this is the supported version that should be used. Note that the instructions on the Selenium-docker GitHub appear to be for tailored for selenium server 3.0.1.
like image 22
cnishina Avatar answered Oct 26 '22 12:10

cnishina