From fc9b2c36b844de1498c4d2b55813fe9fe24e5994 Mon Sep 17 00:00:00 2001 From: lewa <lene.wasskog@nibio.no> Date: Wed, 3 Jan 2024 10:12:33 +0100 Subject: [PATCH] test: Add firefox driver, wait for visibility before checking page title --- selenium/tests/test_selenium.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/selenium/tests/test_selenium.py b/selenium/tests/test_selenium.py index d9104ded..4d5804bf 100644 --- a/selenium/tests/test_selenium.py +++ b/selenium/tests/test_selenium.py @@ -6,15 +6,25 @@ from selenium.webdriver.support import expected_conditions as EC # https://github.com/SeleniumHQ/seleniumhq.github.io/blob/trunk/examples/python/README.md +# BROWSER = 'chrome' +BROWSER = "firefox" + @pytest.fixture def browser(): - chrome_options = webdriver.ChromeOptions() - # Uncomment line below to prevent Chrome from opening - # chrome_options.add_argument("--headless") - driver = webdriver.Chrome(options=chrome_options) + if BROWSER == "chrome": + chrome_options = webdriver.ChromeOptions() + chrome_options.add_argument("--headless") + driver = webdriver.Chrome(options=chrome_options) + elif BROWSER == "firefox": + firefox_options = webdriver.FirefoxOptions() + firefox_options.headless = False + driver = webdriver.Firefox(options=firefox_options) + else: + raise Exception("Browser must be set to either chrome or firefox") driver.get("http://localhost/index.html") + assert driver.title == "Please log in" driver.implicitly_wait(0.5) driver.find_element(by=By.NAME, value="username").send_keys("seleniumtest") @@ -82,6 +92,9 @@ def test_admin_users(browser): ) assert link.get_attribute("href") == "http://localhost/user" link.click() + WebDriverWait(browser, 20).until( + EC.visibility_of_element_located((By.XPATH, "//h1[text()='Users']")) + ) assert browser.title == "Users" @@ -92,4 +105,7 @@ def test_admin_forecasts(browser): ) assert link.get_attribute("href") == "http://localhost/forecastConfiguration" link.click() + WebDriverWait(browser, 20).until( + EC.visibility_of_element_located((By.XPATH, "//h1[text()='Forecasts']")) + ) assert browser.title == "Forecasts" -- GitLab