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.