3

I have this job in my ci runner. It works if I use Selenium-Standalone-Chrome. But Was trying to get Hubs and Nodes working so I can test more browsers. But I'm having trouble getting the services to connect to each other.

verify_last_chrome_func:
  image: python:2.7
  stage: test_integration
  variables:
    # Grid Options
    GRID_TIMEOUT: '300000'
    SHM_SIZE: '512MB'
    GRID_BROWSER_TIMEOUT: '300000'
    GRID_NEW_SESSION_WAIT_TIMEOUT: '300000'
    GRID_MAX_SESSION: '20'
    # Node Options
    HUB_PORT_4444_TCP_ADDR: 'selenium_hub'
    # HUB_PORT_4444_TCP_ADDR: '172.17.0.4' # This works if I can guess what the address will be. 
    HUB_PORT_4444_TCP_PORT: '4444'
  services:
    - name: selenium/hub:3.9.1-actinium
      alias: selenium_hub
    - name: selenium/node-chrome:3.9.1-actinium
      alias: current_chrome_node
  script:
    - SELENIUM_HUB_ADRESS="http://selenium_hub:4444/wd/hub" python /example_test.py

From their docs it really seems like I should be able to network to the hub with selenium_hub or selenium-hub or by setting the alias to something other than selenium_hub and using that name. But none of those seem to be working for HUB_PORT_4444_TCP_ADDR which the node needs to attach to the hub, instead it errors with Registering the node to the hub: http://selenium_hub:4444/grid/register Couldn't register this node: Error sending the registration request: selenium_hub: Name or service not known Couldn't register this node: The hub is down or not responding: selenium_hub: Name or service not known

And then I would need it for the example environmental variable SELENIUM_HUB_ADRESS="http://selenium_hub:4444/wd/hub" in the command/script option is running.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Cynic
  • 6,779
  • 2
  • 30
  • 49
  • Have you try it without an alias name an just request for `http://selenium-hub:4444/grid/register`? – Markus Mar 09 '18 at 17:40
  • I have tried with without alias names using `selenium-hub` and `selenium_hub`. Should be noted that mostly testing with` `gitlab-runner exec docker verify_last_chrome_func ` command. – Cynic Mar 09 '18 at 18:04
  • I have the same problem and also tried different aliases and the REMOTE_HOST option to no avail. – jnns Apr 30 '18 at 12:45

1 Answers1

2

By default Gitlab uses the old linking of containers for networking, this means that only the build container can access the service containers.

You can use the network per build feature flag in your case your yaml would look like this:

verify_last_chrome_func:
  image: python:2.7
  stage: test_integration
  variables:
    # Enable network connection between services
    FF_NETWORK_PER_BUILD: 1
    # Grid Options
    GRID_TIMEOUT: '300000'
    SHM_SIZE: '512MB'
    GRID_BROWSER_TIMEOUT: '300000'
    GRID_NEW_SESSION_WAIT_TIMEOUT: '300000'
    GRID_MAX_SESSION: '20'
    # Node Options
    HUB_PORT_4444_TCP_ADDR: 'selenium_hub'
    # HUB_PORT_4444_TCP_ADDR: '172.17.0.4' # This works if I can guess what the address will be. 
    HUB_PORT_4444_TCP_PORT: '4444'
  services:
    - name: selenium/hub:3.9.1-actinium
      alias: selenium_hub
    - name: selenium/node-chrome:3.9.1-actinium
      alias: current_chrome_node
  script:
    - SELENIUM_HUB_ADRESS="http://selenium_hub:4444/wd/hub" python /example_test.py
Rwky
  • 2,116
  • 1
  • 18
  • 22
  • Do you know if this would still work if you spin up a new container using docker-compose up and need it to be able connect to the services? – Tim Oct 13 '20 at 19:11
  • gitlab-ci creates the network when it runs the tests and the name is random, so any container you create with docker compose won't be able to connect since it won't be in the same network. – Rwky Oct 14 '20 at 20:20