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

Fix StaleElementException when waiting for loading of Subscriptions

parent 96b2ff31
No related branches found
No related tags found
No related merge requests found
Pipeline #91903 canceled
This commit is part of merge request !156. Comments created here will be created in the context of that merge request.
...@@ -54,8 +54,8 @@ class UntestedParent: ...@@ -54,8 +54,8 @@ class UntestedParent:
# stage can be 'initial', 'validate', or 'conflict' # stage can be 'initial', 'validate', or 'conflict'
def _go_to_subscription(self, stage='initial', sub_type=None): 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') 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 = tasks.find_element_by_xpath(f'//*[contains(text(), "{stage}")]')
tab.click() tab.click()
sub_type = sub_type if sub_type is not None else self.sub_type sub_type = sub_type if sub_type is not None else self.sub_type
......
...@@ -47,10 +47,10 @@ class UntestedParent: ...@@ -47,10 +47,10 @@ class UntestedParent:
def test_available_tasks_are_shown(self): def test_available_tasks_are_shown(self):
self._login() self._login()
WebDriverWait(self.browser, 10).until(subscriptions_loaded_cond(self.browser))
tasks = self.browser.find_element_by_name('subscription-list') tasks = self.browser.find_element_by_name('subscription-list')
title = tasks.find_element_by_class_name('v-toolbar__title') title = tasks.find_element_by_class_name('v-toolbar__title')
self.assertEqual('Tasks', title.text) self.assertEqual('Tasks', title.text)
WebDriverWait(self.browser, 10).until(subscriptions_loaded_cond(tasks))
subscription_links = extract_hrefs_hashes( subscription_links = extract_hrefs_hashes(
tasks.find_elements_by_tag_name('a') tasks.find_elements_by_tag_name('a')
) )
......
...@@ -8,6 +8,7 @@ from selenium.webdriver.firefox.options import Options ...@@ -8,6 +8,7 @@ from selenium.webdriver.firefox.options import Options
from selenium.webdriver.remote.webelement import WebElement from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as ec from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
def create_browser() -> webdriver.Firefox: def create_browser() -> webdriver.Firefox:
...@@ -47,11 +48,17 @@ def extract_hrefs_hashes(web_elements: Sequence[WebElement]): ...@@ -47,11 +48,17 @@ def extract_hrefs_hashes(web_elements: Sequence[WebElement]):
for el in web_elements if el.get_attribute('href')] for el in web_elements if el.get_attribute('href')]
# A function that takes the element corresponding to the tasks # A function that takes the a browser client
# component and return a function that can be used as a condition for # and returns a function that can be used as a condition for
# WebDriverWait # WebDriverWait
def subscriptions_loaded_cond(tasks_el): def subscriptions_loaded_cond(browser):
def loaded(*args): def loaded(*args):
sub_links = tasks_el.find_elements_by_tag_name('a') for i in range(2):
return any((link != '/home' for link in extract_hrefs_hashes(sub_links))) 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 return loaded
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment