From 9e31e9cbd95b76d58688c943302b4202e353aba0 Mon Sep 17 00:00:00 2001
From: lewa <lene.wasskog@nibio.no>
Date: Wed, 3 Jan 2024 09:33:43 +0100
Subject: [PATCH] test: Add tests for users and forecasts

---
 selenium/Makefile               |  2 +-
 selenium/tests/test_selenium.py | 23 ++++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/selenium/Makefile b/selenium/Makefile
index 46afaa45..265c5102 100644
--- a/selenium/Makefile
+++ b/selenium/Makefile
@@ -6,7 +6,7 @@ venv/touchfile: requirements.txt
 	touch .venv/touchfile
 
 test: venv 
-	@echo 'Running Django application locally'
+	@echo 'Run selenium tests'
 	. .venv/bin/activate \
 	&& pytest
 
diff --git a/selenium/tests/test_selenium.py b/selenium/tests/test_selenium.py
index b589dc78..d9104ded 100644
--- a/selenium/tests/test_selenium.py
+++ b/selenium/tests/test_selenium.py
@@ -10,7 +10,8 @@ from selenium.webdriver.support import expected_conditions as EC
 @pytest.fixture
 def browser():
     chrome_options = webdriver.ChromeOptions()
-    chrome_options.add_argument("--headless")
+    # Uncomment line below to prevent Chrome from opening
+    # chrome_options.add_argument("--headless")
     driver = webdriver.Chrome(options=chrome_options)
 
     driver.get("http://localhost/index.html")
@@ -72,3 +73,23 @@ def test_admin_apple_fruit_moth(browser):
     assert link.get_attribute("href") == "http://localhost/applefruitmoth"
     link.click()
     assert browser.title == "Rognebærmøllstasjoner"
+
+
+def test_admin_users(browser):
+    browser.find_element(By.XPATH, '//a[text()="Admin"]').click()
+    link = WebDriverWait(browser, 20).until(
+        EC.element_to_be_clickable((By.XPATH, '//a[text()="Users"]'))
+    )
+    assert link.get_attribute("href") == "http://localhost/user"
+    link.click()
+    assert browser.title == "Users"
+
+
+def test_admin_forecasts(browser):
+    browser.find_element(By.XPATH, '//a[text()="Admin"]').click()
+    link = WebDriverWait(browser, 20).until(
+        EC.element_to_be_clickable((By.XPATH, '//a[text()="Forecasts"]'))
+    )
+    assert link.get_attribute("href") == "http://localhost/forecastConfiguration"
+    link.click()
+    assert browser.title == "Forecasts"
-- 
GitLab