sonhu
sonhu

Reputation: 961

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.

Upvotes: 12

Views: 9032

Answers (3)

Shubham Jain
Shubham Jain

Reputation: 17553

You can use below compose file to setup grid and access via VNC

**# To execute this docker-compose yml file use docker-compose -f up

**# Add the "-d" flag at the end for deattached execution****

version: '2'
services:
  firefoxnode:
    image: selenium/node-firefox-debug
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      HUB_HOST: hub
    ports:
      - "32772:5900"

  chromenode:
    image: selenium/node-chrome-debug
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      HUB_HOST: hub
    ports:
      - "32773:5900"

  hub:
    image: selenium/hub
    ports:
      - "4444:4444"

command I use:

 docker-compose -f .\docker-compose.yml up -d

Source :

https://github.com/SeleniumHQ/docker-selenium

Upvotes: -1

Leo Gallucci
Leo Gallucci

Reputation: 16722

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.

Upvotes: 6

craig
craig

Reputation: 5016

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.

Upvotes: 4

Related Questions