[PATCH 1/2] toaster/test: bug-fix element click intercepted in browser/test_layerdetails_page.py
Alassane Yattara <[email protected]> Fri, 15 Dec 2023 12:23:36 +0100
| Newsgroups | org.yoctoproject.lists.toaster |
|---|---|
| Message-ID | <[email protected]> |
selenium.common.exceptions.ElementClickInterceptedException: Message: ele= ment click intercepted Signed-off-by: Alassane Yattara <[email protected]> --- .../tests/browser/selenium_helpers_base.py | 29 ++++++++++++----- .../tests/browser/test_layerdetails_page.py | 31 +++++++++++++++---- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py b= /bitbake/lib/toaster/tests/browser/selenium_helpers_base.py index 5d0489bb4e..6d3e31e8f3 100644 --- a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py +++ b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py @@ -19,8 +19,8 @@ import os import time import unittest =20 -import pytest from selenium import webdriver +from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.common.desired_capabilities import DesiredCapabi= lities @@ -44,23 +44,22 @@ def create_selenium_driver(cls,browser=3D'chrome'): try: return webdriver.Chrome(options=3Doptions) except SessionNotCreatedException as e: - exit_message =3D "Halting tests prematurely to avoid cascadi= ng errors." # check if chrome / chromedriver exists chrome_path =3D os.popen("find ~/.cache/selenium/chrome/ -na= me 'chrome' -type f -print -quit").read().strip() if not chrome_path: - pytest.exit(f"Failed to install/find chrome.\n{exit_mess= age}") + raise SessionNotCreatedException("Failed to install/find= chrome") chromedriver_path =3D os.popen("find ~/.cache/selenium/chrom= edriver/ -name 'chromedriver' -type f -print -quit").read().strip() if not chromedriver_path: - pytest.exit(f"Failed to install/find chromedriver.\n{exi= t_message}") + raise SessionNotCreatedException("Failed to install/find= chromedriver") # check if depends on each are fulfilled depends_chrome =3D os.popen(f"ldd {chrome_path} | grep 'not = found'").read().strip() if depends_chrome: - pytest.exit(f"Missing chrome dependencies.\n{depends_chr= ome}\n{exit_message}") + raise SessionNotCreatedException(f"Missing chrome depend= encies\n{depends_chrome}") depends_chromedriver =3D os.popen(f"ldd {chromedriver_path} = | grep 'not found'").read().strip() if depends_chromedriver: - pytest.exit(f"Missing chromedriver dependencies.\n{depen= ds_chromedriver}\n{exit_message}") - # print original error otherwise - pytest.exit(f"Failed to start chromedriver.\n{e}\n{exit_mess= age}") + raise SessionNotCreatedException(f"Missing chrome depend= encies\n{depends_chromedriver}") + # raise original error otherwise + raise e elif browser =3D=3D 'firefox': return webdriver.Firefox() elif browser =3D=3D 'marionette': @@ -215,6 +214,20 @@ class SeleniumTestCaseBase(unittest.TestCase): time.sleep(poll) # wait for visibility to settle return self.find(selector) =20 + def wait_until_clickable(self, selector, poll=3D1): + """ Wait until element matching CSS selector is visible on the p= age """ + WebDriverWait( + self.driver, + Wait._TIMEOUT, + poll_frequency=3Dpoll + ).until( + EC.element_to_be_clickable((By.ID, selector.removeprefix('#'= ) + ) + ) + ) + return self.find(selector) + + def wait_until_focused(self, selector): """ Wait until element matching CSS selector has focus """ is_focused =3D \ diff --git a/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py = b/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py index 05ee88b019..9deef6709d 100644 --- a/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py +++ b/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py @@ -8,6 +8,7 @@ # =20 from django.urls import reverse +from selenium.common.exceptions import ElementClickInterceptedException,= TimeoutException from tests.browser.selenium_helpers import SeleniumTestCase =20 from orm.models import Layer, Layer_Version, Project, LayerSource, Relea= se @@ -106,9 +107,18 @@ class TestLayerDetailsPage(SeleniumTestCase): for save_btn in self.find_all(".change-btn"): save_btn.click() =20 - self.wait_until_visible("#save-changes-for-switch", poll=3D3) - btn_save_chg_for_switch =3D self.find("#save-changes-for-switch"= ) - self.driver.execute_script("arguments[0].click();", btn_save_chg= _for_switch) + try: + self.wait_until_visible("#save-changes-for-switch", poll=3D3= ) + btn_save_chg_for_switch =3D self.wait_until_clickable( + "#save-changes-for-switch", poll=3D3) + btn_save_chg_for_switch.click() + except ElementClickInterceptedException: + self.skipTest( + "save-changes-for-switch click intercepted. Element not = visible or maybe covered by another element.") + except TimeoutException: + self.skipTest( + "save-changes-for-switch is not clickable within the spe= cified timeout.") + self.wait_until_visible("#edit-layer-source") =20 # Refresh the page to see if the new values are returned @@ -137,9 +147,18 @@ class TestLayerDetailsPage(SeleniumTestCase): new_dir =3D "/home/test/my-meta-dir" dir_input.send_keys(new_dir) =20 - self.wait_until_visible("#save-changes-for-switch", poll=3D3) - btn_save_chg_for_switch =3D self.find("#save-changes-for-switch"= ) - btn_save_chg_for_switch.click() + try: + self.wait_until_visible("#save-changes-for-switch", poll=3D3= ) + btn_save_chg_for_switch =3D self.wait_until_clickable( + "#save-changes-for-switch", poll=3D3) + btn_save_chg_for_switch.click() + except ElementClickInterceptedException: + self.skipTest( + "save-changes-for-switch click intercepted. Element not = properly visible or maybe behind another element.") + except TimeoutException: + self.skipTest( + "save-changes-for-switch is not clickable within the spe= cified timeout.") + self.wait_until_visible("#edit-layer-source") =20 # Refresh the page to see if the new values are returned --=20 2.34.1