Skip to content

Commit

Permalink
tests(disclosures): Improves DisclosureReactLoadTest reliability with…
Browse files Browse the repository at this point in the history
… explicit waits
  • Loading branch information
ERosendo committed Jan 24, 2025
1 parent 038a142 commit 36da5e1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cl/disclosures/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.urls import reverse
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from timeout_decorator import timeout_decorator

from cl.disclosures.factories import (
Expand Down Expand Up @@ -288,6 +290,7 @@ def tearDown(self) -> None:
@timeout_decorator.timeout(SELENIUM_TIMEOUT)
def test_disclosure_homepage(self) -> None:
"""Can we load disclosure homepage?"""
wait = WebDriverWait(self.browser, 3)
self.browser.get(self.live_server_url)
dropdown = self.browser.find_element(By.ID, "navbar-fd")
dropdown.click()
Expand All @@ -298,14 +301,17 @@ def test_disclosure_homepage(self) -> None:
self.assertIn(
"Judicial Financial Disclosures Database", self.browser.title
)
search_bar = self.browser.find_element(By.ID, "main-query-box")
search_bar = wait.until(
EC.visibility_of_element_located((By.ID, "main-query-box"))
)
self.assertTrue(
search_bar.is_displayed(), msg="React-root failed to load"
)

@timeout_decorator.timeout(SELENIUM_TIMEOUT)
def test_disclosure_search(self) -> None:
"""Can we search for judges?"""
wait = WebDriverWait(self.browser, 3)
self.browser.get(self.live_server_url)
self.browser.implicitly_wait(2)
self.browser.find_element(By.ID, "navbar-fd").click()
Expand All @@ -315,14 +321,17 @@ def test_disclosure_search(self) -> None:
self.assertIn(
"Judicial Financial Disclosures Database", self.browser.title
)
search_bar = self.browser.find_element(By.ID, "id_disclosures_search")
search_bar = wait.until(
EC.visibility_of_element_located((By.ID, "main-query-box"))
)
self.assertTrue(
search_bar.is_displayed(), msg="React-root failed to load"
)

with self.assertRaises(NoSuchElementException):
self.browser.find_element(By.CSS_SELECTOR, ".tr-results")

search_bar = self.browser.find_element(By.ID, "id_disclosures_search")
search_bar.send_keys("Judith")
results = self.browser.find_elements(By.CSS_SELECTOR, ".tr-results")
self.assertEqual(len(results), 1, msg="Incorrect results displayed")

0 comments on commit 36da5e1

Please sign in to comment.