tests: functional: Handle click failure when waiting for page update

When a click fails because the element is obscured or out of scroll port, the
fails with ElementClickInterceptedException. This normally fails the test
properly. However, when waiting for a page update, the wait loop silently
swallows the error causing the click failure to be ignored. This later leads to
a timeout waiting for page to be updated.

Handling this error separately and re-raising it ensures that the test fails
with the correct error allowing us to fix the problem.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2024-07-25 12:18:20 -07:00 committed by James Valleroy
parent df55ba8c61
commit 170685c806
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -15,7 +15,8 @@ from contextlib import contextmanager
import pytest import pytest
import requests import requests
from selenium.common.exceptions import (StaleElementReferenceException, from selenium.common.exceptions import (ElementClickInterceptedException,
StaleElementReferenceException,
WebDriverException) WebDriverException)
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
@ -131,6 +132,10 @@ def wait_for_page_update(browser, timeout=300, expected_url=None):
page_body = browser.find_by_tag('body').first page_body = browser.find_by_tag('body').first
try: try:
yield yield
except ElementClickInterceptedException:
# When a element that is not visible is clicked, the click is ignored
# and we can't expect a page update.
raise
except WebDriverException: except WebDriverException:
# ignore a connection failure which may happen after web server restart # ignore a connection failure which may happen after web server restart
pass pass