Skip to content

Instantly share code, notes, and snippets.

@bjvta
Created January 21, 2025 15:01
Show Gist options
  • Save bjvta/72a219ec16374df0c8fce0b1d27adb12 to your computer and use it in GitHub Desktop.
Save bjvta/72a219ec16374df0c8fce0b1d27adb12 to your computer and use it in GitHub Desktop.
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.conf import settings
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.support import expected_conditions as EC
import time
from unittest import skip
class HomePageTestCase(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.driver = webdriver.Chrome()
cls.driver.implicitly_wait(10) # Wait for elements to load
@classmethod
def tearDownClass(cls):
cls.driver.quit()
super().tearDownClass()
# @skip("Skipping this entire test case")
def test_home_page_loads(self):
"""Verify that the home page loads successfully and contains expected elements."""
self.driver.get(f"{self.live_server_url}/")
# Check the page title
self.assertIn(
"trendig",
self.driver.title.lower(),
"Page title does not contain 'trendig'",
)
# Verify the header is present
header = self.driver.find_element(By.CSS_SELECTOR, ".trendig-header")
self.assertTrue(
header.is_displayed(), "Header is not displayed on the home page"
)
# Verify the navbar is present
navbar = self.driver.find_element(By.CSS_SELECTOR, ".navbar")
self.assertTrue(
navbar.is_displayed(), "Navbar is not displayed on the home page"
)
# Optional Debug: Print HTML source or screenshot
# print(self.driver.page_source)
# self.driver.save_screenshot("homepage_test_screenshot.png")
def test_registration_process(self):
"""Test the registration process end-to-end."""
driver = self.driver
driver.get(f"{self.live_server_url}/training/schulung/")
time.sleep(3)
driver.execute_script("""$("#usercentrics-root").remove()""")
istqb_link = driver.find_element(
By.CSS_SELECTOR, 'a[href="/training/istqb-software-testing/"]'
)
istqb_link.click()
driver.execute_script("""$("#usercentrics-root").remove()""")
driver.execute_script("window.scrollTo(0,200)")
ctfl_link = driver.find_element(
By.CSS_SELECTOR,
'a[href="/training/schulung/istqb-certified-tester-foundation-level/"]',
)
ctfl_link.click()
driver.execute_script("""$("#usercentrics-root").remove()""")
driver.execute_script("window.scrollTo(0,900)")
buchen_link = driver.find_element(
By.XPATH,
"//a[contains(@href, '/training/schulung/istqb-certified-tester-foundation-level/2108/')]",
)
buchen_link.click()
driver.execute_script("""$("#usercentrics-root").remove()""")
driver.execute_script("window.scrollTo(0,900)")
time.sleep(1)
# 4. Fill attendee details
Select(
driver.find_element(By.ID, "id_attendees-0-title")
).select_by_visible_text("Dr.")
driver.find_element(By.ID, "id_attendees-0-first_name").send_keys("Brandon")
driver.find_element(By.ID, "id_attendees-0-last_name").send_keys("Valle")
driver.find_element(By.ID, "id_attendees-0-email").send_keys(
"[email protected]"
)
driver.find_element(By.ID, "id_attendees-0-telephone").send_keys("12345656788")
driver.find_element(By.ID, "id_attendees-0-job_title").send_keys("test")
# 5. Fill billing details
driver.find_element(By.ID, "id_billing-company").send_keys("trendig technology")
driver.find_element(By.ID, "id_billing-department").send_keys("test")
Select(driver.find_element(By.ID, "id_billing-title")).select_by_visible_text(
"Dr."
)
driver.find_element(By.ID, "id_billing-first_name").send_keys("Brandon")
driver.find_element(By.ID, "id_billing-last_name").send_keys("Valle")
driver.find_element(By.ID, "id_billing-email").send_keys(
"[email protected]"
)
driver.find_element(By.ID, "id_billing-address").send_keys("test")
driver.find_element(By.ID, "id_billing-zip").send_keys("test")
driver.find_element(By.ID, "id_billing-city").send_keys("Berlin")
Select(driver.find_element(By.ID, "id_billing-country")).select_by_visible_text(
"Deutschland"
)
driver.find_element(By.ID, "id_billing-telephone").send_keys("12343454546")
driver.find_element(By.ID, "id_billing-vatid").send_keys("DE123456789")
Select(
driver.find_element(By.ID, "id_billing-how_heard_about_us")
).select_by_visible_text("Suchmaschine")
driver.find_element(By.CSS_SELECTOR, ".checkbox-label > .checkmark").click()
driver.execute_script("window.scrollTo(0,1600)")
# 6. Submit the form
driver.find_element(By.CSS_SELECTOR, ".button-pink").click()
# 7. Verify successful registration
driver.execute_script("""$("#usercentrics-root").remove()""")
assert (
"Anmeldung Erfolgreich" in driver.page_source
), "❌ Registration failed: Success message not found."
print("✅ Registration test passed successfully.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment