End to End Testing Angular with Protractor/Selenium in Containers

Problem: I wanted to perform end-to-end testing on an Angular application that was running in containers. I decided to use Protractor which rides on Selenium.

Solution: Using the docker-compose.yml below, I was able to run end-to-end testing on the Angular application.

services:
app:
...
depends_on:
- test-server-hub
  selenium-hub:
image: selenium/hub:latest
depends_on:
- selenium-node
- test-app
selenium-node:
image: selenium/node-chrome:latest
test-app: # hack to allow selenium hub to reach app
... # nearly identical configurations as app service

Nested Problem/Solution: After setting up the selenium hub and node, the selenium service needed to reach a running Angular application. Usually, when the docker-compose’s default network takes care of this, but I needed the depends_on: selenium-hub to ensure that the selenium-hub service is running when I run the tests manually from within the container using it’s shell. The depends_on setting seems to allow app to reach selenium-hub, but not the other way around. Adding depends_on: app to selenium-hub, would create a circular dependency. So the hack was to create another container that is running the identical Angular application, test-app service, for the selenium-hub selenium service to test against.

Notes: