I'm trying to setup a CI environment where I can test my Django application with selenium where both are running in docker.
My test is setup with the following:
from time import sleep
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.remote.webdriver import WebDriver
class MySeleniumTests(StaticLiveServerTestCase):
port = 8000
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.selenium = WebDriver("http://selenium:4444", desired_capabilities={'browserName': 'chrome'})
cls.selenium.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
def test_login(self):
self.selenium.get('%s:%s%s' % ('http://web', self.port, '/'))
greeting = self.selenium.find_element_by_id("greeting")
self.assertEqual(greeting.text, 'hello world')
I then try to run this on gitlab with this CI setup in my .gitlab-ci.yml:
image:
name: docker/compose:1.26.2
entrypoint: ['/bin/sh', '-c']
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
stages:
- test
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
build:
stage: test
script:
- docker build --tag django .
- docker network create selenium-net
- docker run -d --network selenium-net --name selenium selenium/standalone-chrome:4.0.0-alpha-6-20200730
- docker run --network selenium-net --name web --expose 8000 django dindselenium/manage.py test myapp
On my local machine the connection WebDriver setup succeeds but then Selenium fails to connect to the web app. On the CI environment I can't even connect to Selenium from the web app.
I've setup an example repo here: https://gitlab.com/oskarpersson/dind-selenium/, and an example of a failing job: https://gitlab.com/oskarpersson/dind-selenium/-/jobs/705523165