From b1c0813347562d73f4d6259e05450a1e0a963318 Mon Sep 17 00:00:00 2001 From: Restioson Date: Thu, 17 Oct 2024 15:44:31 +0200 Subject: [PATCH] test(frontend): add basic Selenium testing So far, this just checks that the main pages (as listed in the navigation bar) do not 404, have a Django ProgrammingError page displayed, etc. The test uses the Chromium webdriver because it is more complex to set up one test to run with two different webdrivers in sequence. It also opts for emulating the common _desktop_ resolution of 1080p (future tests could check that the navbar expander, etc., work properly, but this is out of scope for test #1). --- Dockerfile-dev | 2 +- app/general/tests/test_frontend.py | 64 ++++++++++++++++++++++++++++++ requirements-test.txt | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/general/tests/test_frontend.py diff --git a/Dockerfile-dev b/Dockerfile-dev index a59cdeba..468ce882 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -18,7 +18,7 @@ RUN < - Search' + try: + wait = WebDriverWait(self.driver, timeout=WAIT_TIMEOUT) + wait.until(lambda d: link_text in self.driver.title) + except TimeoutException: + assert link_text in self.driver.title, ( + f"Expected title for page {link_text} to have {link_text};" + f" was {self.driver.title}" + ) + self.assert_current_page_not_error() + + def assert_current_page_not_error(self): + assert not self.driver.title.startswith("Error"), f"Actual title was {self.driver.title}" + assert not self.driver.title.startswith( + "ProgrammingError" + ), f"Actual title was {self.driver.title}" + assert not self.driver.find_element(By.ID, "error-block").is_displayed() diff --git a/requirements-test.txt b/requirements-test.txt index bfe3dc05..a5743332 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -3,3 +3,4 @@ django-debug-toolbar django-extensions faker ruff +selenium==4.25.0