wrapped most helper functions in functional_tests.base in the new @wait decorator, including wait_for() itself; all UTs & FTs passing
This commit is contained in:
@@ -8,6 +8,21 @@ from selenium.webdriver.common.by import By
|
||||
|
||||
MAX_WAIT = 5
|
||||
|
||||
|
||||
# Decorator fns
|
||||
def wait(fn):
|
||||
def modified_fn(*args, **kwargs):
|
||||
start_time = time.time()
|
||||
while True:
|
||||
try:
|
||||
return fn(*args, **kwargs)
|
||||
except (AssertionError, WebDriverException) as e:
|
||||
if time.time() - start_time > MAX_WAIT:
|
||||
raise e
|
||||
time.sleep(0.5)
|
||||
return modified_fn
|
||||
|
||||
|
||||
class FunctionalTest(StaticLiveServerTestCase):
|
||||
# Helper methods
|
||||
def setUp(self):
|
||||
@@ -18,42 +33,26 @@ class FunctionalTest(StaticLiveServerTestCase):
|
||||
def tearDown(self):
|
||||
self.browser.quit()
|
||||
|
||||
@wait
|
||||
def wait_for(self, fn):
|
||||
start_time = time.time()
|
||||
while True:
|
||||
try:
|
||||
return fn()
|
||||
except (AssertionError, WebDriverException):
|
||||
if time.time() - start_time > MAX_WAIT:
|
||||
raise
|
||||
time.sleep(0.5)
|
||||
|
||||
def wait_for_row_in_list_table(self, row_text):
|
||||
start_time = time.time()
|
||||
while True:
|
||||
try:
|
||||
table = self.browser.find_element(By.ID, 'id_list_table')
|
||||
rows = table.find_elements(By.TAG_NAME, 'tr')
|
||||
self.assertIn(row_text, [row.text for row in rows])
|
||||
return
|
||||
except (AssertionError, WebDriverException):
|
||||
if time.time() - start_time > MAX_WAIT:
|
||||
raise
|
||||
time.sleep(0.5)
|
||||
return fn()
|
||||
|
||||
def get_item_input_box(self):
|
||||
return self.browser.find_element(By.ID, "id_text")
|
||||
|
||||
@wait
|
||||
def wait_for_row_in_list_table(self, row_text):
|
||||
rows = self.browser.find_elements(By.CSS_SELECTOR, "#id_list_table tr")
|
||||
self.assertIn(row_text, [row.text for row in rows])
|
||||
|
||||
@wait
|
||||
def wait_to_be_logged_in(self, email):
|
||||
self.wait_for(
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "#id_logout"),
|
||||
)
|
||||
self.browser.find_element(By.CSS_SELECTOR, "#id_logout"),
|
||||
navbar = self.browser.find_element(By.CSS_SELECTOR, ".navbar")
|
||||
self.assertIn(email, navbar.text)
|
||||
|
||||
@wait
|
||||
def wait_to_be_logged_out(self, email):
|
||||
self.wait_for(
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "input[name=email]"),
|
||||
)
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "input[name=email]"),
|
||||
navbar = self.browser.find_element(By.CSS_SELECTOR, ".navbar")
|
||||
self.assertNotIn(email, navbar.text)
|
||||
|
||||
Reference in New Issue
Block a user