How to run Cucumber tests in Parallel using Docker for Windows, Selenium Hub, and Jenkins
Before trying to get this Docker solution running, I highly reccomend you run through the Docker getting started guide located here
Note: You might have to run through the getting started guide to get Hyper-V configured correctly
Note: In the getting started guide, when it comes to the docker-machine part, you might have to follow the instructions here for getting Docker Machine to work on Windows
- clone this repo,
git clone https://github.com/ah0y/parallel_cucumber.git - open up an administrator version of hyper-v and powershell (then
cdinto the directory you've downloaded this repo to with powershell) - create 2 docker-machine vms (like in step 4 of the geting started guide)
docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" --hyperv-memory "4096" myvm1docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" --hyperv-memory "2048" myvm2- Note: You might have to clean up the vms you've created from the getting started guide with
docker-machine rm <vm-name> -f
- run
docker-machine lsand note your myvm1 ip address - run
docker-machine ssh myvm1 "docker swarm init --advertise-addr <myvm1 ip>"to initialize your swam and get your docker swarm join command - run
docker-machine ssh myvm2 "<docker swarm join command>"filling in the docker-swarm command with the output you've received in step 5. Make sure to change the port number on the very end of the join swarm command from 2376 to 2377 when joining a worker to a swarm- Note: The docker swarm join command needs to be in quotes
- run
docker-machine ssh myvm1 "docker node ls"to verify you've succesfully built the swarm - run
& "C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe" env myvm1 | Invoke-Expressionto configure powershell to execute commands on myvm1 - run
docker stack deploy -c docker-compose.yml parallel_cucumberto build the stack - Voila! Docker Swarm is now setup
- visit
<myvm1 ip>:8080to access Jenkins (might take a minute to load) - visit
<myvm1 ip>:4444/grid/consoleto access the Selenium Grid
- visit
- after you've set up your Docker Swarm, scale chrome with
docker service scale parallel_cucumber_chrome=10(You should see the number of Chrome instances on the Selenium Grid increase)
- visit
<myvm1 ip>:8080to access Jenkins - run
docker container ls - note the container id (column on the far left) of the jenkins-docker image
- run
docker exec -it <container id of jenkins-docker image>to access the Jenkins container - run
cd /var/jenkins_home/secrets/ - run
cat initialAdminPasswordto recieve the password to unlock Jenkins - copy the password you've recieved in step 6 into Jenkins and hit continue
- install the suggested plugins
- after the plugins are installed, continue as admin or setup an account. doesn't really matter
- Voila! Jenkins is now setup
- on the Jenkins main menu, hit 'New Item' on the left hand side
- enter in 'parallel_cucumber' for the item name
- select 'Freestyle project' and hit 'Ok'
- on the General tab (should be the default tab Jenkins takes you to), hit 'git' under 'Source Code Management'
- copy the url for this repo into the 'Repository Url' field (https://github.com/ah0y/parallel_cucumber.git)
- under build hit 'Add build step' and select 'Execute shell'
- in the 'Command' text field, paste in
docker build --build-arg GRID_IP=http://<myvm1 ip>:4444/wd/hub --build-arg NODES=10 -t parallel_cucumber .replacing myvm1 ip with your myvm1 ip- Note: 'http://' is required when specifying the IP for the docker build command
- Note: Don't forget the '.' at the very end!
- hit 'Save'
- on the left hand side, hit 'Build Now' to build the test suite
- Voila! You have now successfully run a test suite in parallel using Docker, Selenium Hub, and Jenkins
- To add different physical machines to the docker swarm, just install docker on the additional machines and run step 3 and 6 from part 1 on each additional machine