From dd6b865de6544f2827f599ab1bebc8bd0d71d2cf Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 25 Jul 2024 12:22:28 -0700 Subject: [PATCH] tests: functional: Handle obscured elements when submitting forms In some cases in the backup page, when trying to restore a backup, the button is obscured and trying to click it fails. Handle such situations by scrolling the element into view first and try to click on the element again. Ensure that our navigation header does not obscure the element when scrolling it into view. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/tests/functional/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plinth/tests/functional/__init__.py b/plinth/tests/functional/__init__.py index dfe2c70c1..bca95b2ac 100644 --- a/plinth/tests/functional/__init__.py +++ b/plinth/tests/functional/__init__.py @@ -203,6 +203,17 @@ def download_file_outside_browser(url): ########################### # Form handling utilities # ########################### +def click(browser, element): + """Click an element after scrolling it into view considering header.""" + try: + element.click() + except ElementClickInterceptedException: + script = 'arguments[0].style.scrollMarginTop = "4.3125rem";' \ + 'arguments[0].scrollIntoView(true);' + browser.execute_script(script, element._element) + element.click() + + def submit(browser, element=None, form_class=None, expected_url=None): """Submit a specific form in the current page and wait for page change.""" if not (element or form_class): @@ -210,7 +221,7 @@ def submit(browser, element=None, form_class=None, expected_url=None): with wait_for_page_update(browser, expected_url=expected_url): if element: - element.click() + click(browser, element) elif form_class: browser.find_by_css( '.{} input[type=submit]'.format(form_class)).click()