From 3be73bad59984d836d961a71cee370d45f3d6976 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 23 Feb 2026 22:18:18 -0800 Subject: [PATCH] tests: functional: Fix reloading error page during install/uninstall - When an error page is shown during installation/uninstallation, no automatic refresh of the page happens. Fix this by reloading the page when error is shown. - When error page is shown, the document.readyState is "interactive" (meaning that page load is completed but other resources such as images are being loaded). So, checking for error page is never happening. - Also when reloading an error page, WebDriverException may happen so use the wait_for_page_update() utility to perform the page reloads. Tests: - Run functional tests for bepasty. When installing the app, stop apache web server. Let an error page be shown. Then start the server again. Without the patch, the error page is never reloaded. With the patch, the error page is reloaded and tests succeed. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/tests/functional/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index 4bbd4005d..2b89ed6e3 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -208,6 +208,12 @@ def wait_for_page_update(browser, timeout=300, expected_url=None): WebDriverWait(browser, timeout).until(_PageLoaded(page_body, expected_url)) +def page_reload(browser): + """Reload the page.""" + with wait_for_page_update(browser): + browser.visit(browser.url) + + def _get_site_url(site_name): if site_name.startswith('share'): site_name = site_name.replace('_', '/') @@ -457,10 +463,10 @@ def install(browser, app_name): script = 'return (document.readyState == "complete") && ' \ '(!Boolean(document.querySelector(".app-operation"))) &&' \ '(!Boolean(document.querySelector(".app-just-installed")));' - if not browser.execute_script(script): + if browser.is_element_present_by_css('.neterror'): + page_reload(browser) + elif not browser.execute_script(script): time.sleep(0.1) - elif browser.is_element_present_by_css('.neterror'): - browser.visit(browser.url) elif browser.is_element_present_by_css('.alert-danger'): break elif (browser.is_element_present_by_css('.app-checking-availability') @@ -500,10 +506,10 @@ def uninstall(browser, app_name): while True: script = 'return (document.readyState == "complete") && ' \ '(!Boolean(document.querySelector(".app-operation")));' - if not browser.execute_script(script): + if browser.is_element_present_by_css('.neterror'): + page_reload(browser) + elif not browser.execute_script(script): time.sleep(0.1) - elif browser.is_element_present_by_css('.neterror'): - browser.visit(browser.url) elif browser.is_element_present_by_css('.alert-danger'): raise RuntimeError('Uninstall failed') else: