Automate e2e test with selenium of Django app in gitlab cicd -Error: selenium.common.exceptions.WebDriverException: neterror?e=dnsNotFound

This is the output of my cicd pipline which is failing

base/tests/e2e_tests/test_register.py F                                  [100%]
=================================== FAILURES ===================================
_____________ TestRegistrationPage.test_register_valid_credentials _____________
self = <test_register.TestRegistrationPage testMethod=test_register_valid_credentials>
    def test_register_valid_credentials(self):
        """
        Test whether the registration process works flawlessly.
        This method asserts that after sucessful redirect url equals home.
        """
>       self.driver.get("http://secprog:8080/")

FAILED base/tests/e2e_tests/test_register.py::TestRegistrationPage::test_register_valid_credentials - selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=dnsNotFound&u=http%3A//secprog%3A8080/&c=UTF-8&d=We%20can%E2%80%99t%20connect%20to%20the%20server%20at%20secprog.
Stacktrace:
RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8
WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:193:5
UnknownError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:832:5
checkReadyState@chrome://remote/content/marionette/navigate.sys.mjs:58:24
onNavigation@chrome://remote/content/marionette/navigate.sys.mjs:330:39
emit@resource://gre/modules/EventEmitter.sys.mjs:148:20
receiveMessage@chrome://remote/content/marionette/actors/MarionetteEventsParent.sys.mjs:33:25

This is my Dockerfile:


# Stage 1: Build stage
FROM python:3.12.0b2-alpine3.17

RUN apk update


WORKDIR /app
COPY . .

EXPOSE 8080

CMD ["python", "manage.py", "runserver", "0.0.0:8080"]

This is my .gitlab-ci.yml. in my build stage everything works fine and it gets passed. The problem is in my run_e2e_test. I don’t know where my error is. I assume that there is a problem with how i define the alias for the services, but i don’t know how the to services can communicate with each other:


stages:
    - unit_tests
    - build
    - integration_tests
    - static_code_analysis
    - start_server
    - sec_vuln_assessment
    - e2e_tests


run_build:
    stage: build
    image: docker:20.10.16
    services: 
        - docker:20.10.16-dind
    variables:
        DOCKER_TLS_CERTDIR: "/certs"
    before_script:
        # login working, but -p is unsecure. try --password-stdin
        - docker login registry.mygit.th-deg.de -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
    script:
        - docker build -t registry.mygit.th-deg.de/pk27532/secprog .
        - docker push registry.mygit.th-deg.de/pk27532/secprog

run_e2e_tests:
    stage: e2e_tests
    image: docker:20.10.16
    services:
        - name: selenium/standalone-firefox:latest
          alias: selenium
        - name: registry.mygit.th-deg.de/pk27532/secprog
          alias: secprog
    variables:
        FF_NETWORK_PER_BUILD: 1
    before_script:
        - apk update
        - apk add python3 
        - python3 -m ensurepip
        - pip3 install -r requirements.txt
    script:
        - python3 -m pytest base/tests/e2e_tests/test_register.py

This is my Testfile: As soon as my code gets executed in the gitlab cicd pipeline the e2e tests fails:


import os
import time
import subprocess
import socket
from dotenv import load_dotenv
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from django.test import LiveServerTestCase

load_dotenv()
valid_registration_username = os.getenv("VALID_REGISTRATION_USERNAME")
valid_registration_email = os.getenv("VALID_REGISTRATION_EMAIL")
valid_registration_email_pwd = os.getenv("VALID_REGISTRATION_EMAIL_PWD")
valid_registration_test_pwd = os.getenv("VALID_REGISTRATION_TEST_PWD")


class TestRegistrationPage(LiveServerTestCase):
    """
    Class for testing the registration process.
    This class inherits from Django's LiveServerTestCase to run tests against a live server.
    """

    def setUp(self):
        """
        This method is called before each test case to set up the Selenium WebDriver.
        """
        super().setUp()
        if "CI" in os.environ.keys():
            options = webdriver.FirefoxOptions()
            self.driver = webdriver.Remote(
                command_executor="http://selenium:4444", options=options
            )
        else:
            subprocess.Popen(["python", "manage.py", "runserver"])
            time.sleep(5)
            self.driver = webdriver.Firefox()

    def tearDown(self):
        """
        This method is called after each test case to quit the Selenium WebDriver.
        """
        self.driver.quit()
        super().tearDown()

    def test_register_valid_credentials(self):
        """
        Test whether the registration process works flawlessly.
        This method asserts that after sucessful redirect url equals home.
        """
        self.driver.get("http://secprog:8080/")
        self.assertIn("secProg", self.driver.title)

I tried several different ways but still cant get it work. Locally, the selenium tests work perfectly fine but I cant get them automated in my pipeline.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật