diff --git a/functional_tests/test_feedback_creation.py b/functional_tests/test_feedback_creation.py index 667d7a48116b370d12b35a9559064a2fa9393bc1..042700d286848d7aa4f2388176dc5c36058d39f6 100644 --- a/functional_tests/test_feedback_creation.py +++ b/functional_tests/test_feedback_creation.py @@ -54,8 +54,8 @@ class UntestedParent: # stage can be 'initial', 'validate', or 'conflict' def _go_to_subscription(self, stage='initial', sub_type=None): + WebDriverWait(self.browser, 10).until(subscriptions_loaded_cond(self.browser)) tasks = self.browser.find_element_by_name('subscription-list') - WebDriverWait(self.browser, 10).until(subscriptions_loaded_cond(tasks)) tab = tasks.find_element_by_xpath(f'//*[contains(text(), "{stage}")]') tab.click() sub_type = sub_type if sub_type is not None else self.sub_type diff --git a/functional_tests/test_front_pages.py b/functional_tests/test_front_pages.py index c24400e29d7914342fc2c602b0b0d61a7aaf9730..742aacfdb6cda885ae225f6d26d320abf1216e03 100644 --- a/functional_tests/test_front_pages.py +++ b/functional_tests/test_front_pages.py @@ -47,10 +47,10 @@ class UntestedParent: def test_available_tasks_are_shown(self): self._login() + WebDriverWait(self.browser, 10).until(subscriptions_loaded_cond(self.browser)) tasks = self.browser.find_element_by_name('subscription-list') title = tasks.find_element_by_class_name('v-toolbar__title') self.assertEqual('Tasks', title.text) - WebDriverWait(self.browser, 10).until(subscriptions_loaded_cond(tasks)) subscription_links = extract_hrefs_hashes( tasks.find_elements_by_tag_name('a') ) diff --git a/functional_tests/util.py b/functional_tests/util.py index 7a45ec5a684255ea8d02ede80af4ecaa8f1287a3..2abaa2482f6e0921f318b1c2c172729a84999373 100644 --- a/functional_tests/util.py +++ b/functional_tests/util.py @@ -8,6 +8,7 @@ from selenium.webdriver.firefox.options import Options from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.support.ui import WebDriverWait +from selenium.common.exceptions import StaleElementReferenceException def create_browser() -> webdriver.Firefox: @@ -47,11 +48,17 @@ def extract_hrefs_hashes(web_elements: Sequence[WebElement]): for el in web_elements if el.get_attribute('href')] -# A function that takes the element corresponding to the tasks -# component and return a function that can be used as a condition for +# A function that takes the a browser client +# and returns a function that can be used as a condition for # WebDriverWait -def subscriptions_loaded_cond(tasks_el): +def subscriptions_loaded_cond(browser): def loaded(*args): - sub_links = tasks_el.find_elements_by_tag_name('a') - return any((link != '/home' for link in extract_hrefs_hashes(sub_links))) + for i in range(2): + try: + tasks_el = browser.find_element_by_name('subscription-list') + sub_links = tasks_el.find_elements_by_tag_name('a') + return any((link != '/home' for link in extract_hrefs_hashes(sub_links))) + except StaleElementReferenceException: + pass + return False return loaded