3

I am trying to get my e2e tests to run against a selenium grid and a chrome node that I have setup in docker containers linked together like so:

So far I have managed to get the containers running via docker-compose

version: '2'
services:
  hub:
    image: selenium/hub:latest
    ports:
      - 4444:4444

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

I am then running ng e2e from my working directory on my host machine (so not in using docker for building/serving app), I see my app is built and launched on a dev server and then protractor kicks in and uses my selenium server:

enter image description here

However as can be seen I get an error saying that Angular cannot be found on the page, referencing the localhost:49158 address that the dev server assigns.

If I VNC into my container where the chrome node is running, I can see the browser is launched at the point the test attempts to run, but fails to find my app running on my host machine.

enter image description here

Do I need to map localhost on my chromenode back to my host machine ip address in my docker-compose file?

Thanks

Update So I came across the network_mode: "host" docker compose config option, which I thought I needed but it made no difference after trying it and I read somewhere that it may not work on mac OSX which I am on (High Sierra)

mindparse
  • 6,115
  • 27
  • 90
  • 191
  • Are the logs from the hub or the node? – Ohmen Nov 26 '18 at 10:30
  • Neither, the logs are from my local dev pc from where I issue the protractor command – mindparse Nov 26 '18 at 12:23
  • ok. Does protractor try to connect to the chrome node? – Ohmen Nov 27 '18 at 13:20
  • Yes it does via the grid instance I have running in another container. I see chrome launch on the node successfully, it just cannot run my app running on localhost on my local machine – mindparse Nov 27 '18 at 14:08
  • You then have to explicitly set the port where the chrome node exposes the app and pass this port via another port entry in your compose file to localhost – Ohmen Nov 27 '18 at 16:29
  • Ok, well if you want to suggest an answer, and it helps me, I will award you the bounty :) – mindparse Nov 27 '18 at 17:34
  • @Ohmen - I just read what you said again in your last comment. My chrome node is not serving or exposing the app. My host machine is running the app and also where I issue the protractor command from. So protractor connects to my selenium-grid running on my hub node, which then connects to my chrome node. So my chrome node is now trying to reach the app thats running on my host machine. Does that make sense? – mindparse Nov 27 '18 at 20:00
  • Hi, this makes some sense. Would you mind drawing a small diagram which shows which component is calling which other? https://www.draw.io/ is easy to use and web only. – Ohmen Nov 27 '18 at 20:08
  • Your Selenium server is a container, so it is on a different private network than your host where you have your angular app. When Selenium calls "localhost" it will try to talk with itself. To fix this you have 2 option: 1- Use docker-compose to run your angular application and call it with its service name from selenium. 2- (never tried it) use the node IP between your docker network and your host with some port mapping to reach the Angular app. I hope this helps and I haven't missed anything :-) – sys0dm1n Nov 30 '18 at 06:43

0 Answers0