Skip to content
Snippets Groups Projects
Commit 9466d729 authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Fix StaleElementException when waiting for loading of Subscriptions

parent f8004073
Branches
Tags 0.3.4
1 merge request!156Fix StaleElementException when waiting for loading of Subscriptions
Pipeline #91905 passed
......@@ -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
......
......@@ -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')
)
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment