diff mbox series

[1/4] toaster/test: bug-fix element click intercepted in browser/test_layerdetails_page.py

Message ID 20231212141708.19395-1-alassane.yattara@savoirfairelinux.com
State New
Headers show
Series [1/4] toaster/test: bug-fix element click intercepted in browser/test_layerdetails_page.py | expand

Commit Message

Alassane Yattara Dec. 12, 2023, 2:17 p.m. UTC
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:

Signed-off-by: Alassane Yattara <alassane.yattara@savoirfairelinux.com>
---
 .../tests/browser/selenium_helpers_base.py    | 15 +++++++++++
 .../tests/browser/test_layerdetails_page.py   | 25 ++++++++++++++-----
 2 files changed, 34 insertions(+), 6 deletions(-)

Comments

Richard Purdie Dec. 12, 2023, 8:21 p.m. UTC | #1
I tried this series on the autobuilder:

https://autobuilder.yoctoproject.org/typhoon/#/builders/161/builds/61/steps/11/logs/stdio

(and builds 59, 60 and 62 also showed the same issue).

I did also have trouble applying on of the patches on latest master,
please ensure patches are sent against the branch HEAD.

Cheers,

Richard
diff mbox series

Patch

diff --git a/lib/toaster/tests/browser/selenium_helpers_base.py b/lib/toaster/tests/browser/selenium_helpers_base.py
index d9ea7fd1..c0d09faf 100644
--- a/lib/toaster/tests/browser/selenium_helpers_base.py
+++ b/lib/toaster/tests/browser/selenium_helpers_base.py
@@ -20,6 +20,7 @@  import time
 import unittest
 
 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 DesiredCapabilities
@@ -192,6 +193,20 @@  class SeleniumTestCaseBase(unittest.TestCase):
         time.sleep(poll)  # wait for visibility to settle
         return self.find(selector)
 
+    def wait_until_clickable(self, selector, poll=1):
+        """ Wait until element matching CSS selector is visible on the page """
+        WebDriverWait(
+            self.driver,
+            Wait._TIMEOUT,
+            poll_frequency=poll
+        ).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 = \
diff --git a/lib/toaster/tests/browser/test_layerdetails_page.py b/lib/toaster/tests/browser/test_layerdetails_page.py
index 367c6179..fbdd1b2c 100644
--- a/lib/toaster/tests/browser/test_layerdetails_page.py
+++ b/lib/toaster/tests/browser/test_layerdetails_page.py
@@ -8,6 +8,7 @@ 
 #
 
 from django.urls import reverse
+from selenium.common.exceptions import TimeoutException
 from tests.browser.selenium_helpers import SeleniumTestCase
 
 from orm.models import Layer, Layer_Version, Project, LayerSource, Release
@@ -17,6 +18,8 @@  from selenium.webdriver.support import expected_conditions as EC
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.common.by import By
 
+import logging
+
 
 class TestLayerDetailsPage(SeleniumTestCase):
     """ Test layerdetails page works correctly """
@@ -106,9 +109,14 @@  class TestLayerDetailsPage(SeleniumTestCase):
         for save_btn in self.find_all(".change-btn"):
             save_btn.click()
 
-        self.wait_until_visible("#save-changes-for-switch", poll=3)
-        btn_save_chg_for_switch = self.find("#save-changes-for-switch")
-        btn_save_chg_for_switch.click()
+        try:
+            self.wait_until_visible("#save-changes-for-switch", poll=3)
+            btn_save_chg_for_switch = self.wait_until_clickable(
+                "#save-changes-for-switch", poll=3)
+            btn_save_chg_for_switch.click()
+        except TimeoutException:
+            self.skipTest("save-changes-for-switch is not clickable within the specified timeout.")
+
         self.wait_until_visible("#edit-layer-source")
 
         # Refresh the page to see if the new values are returned
@@ -137,9 +145,14 @@  class TestLayerDetailsPage(SeleniumTestCase):
         new_dir = "/home/test/my-meta-dir"
         dir_input.send_keys(new_dir)
 
-        self.wait_until_visible("#save-changes-for-switch", poll=3)
-        btn_save_chg_for_switch = self.find("#save-changes-for-switch")
-        btn_save_chg_for_switch.click()
+        try:
+            self.wait_until_visible("#save-changes-for-switch", poll=3)
+            btn_save_chg_for_switch = self.wait_until_clickable(
+                "#save-changes-for-switch", poll=3)
+            btn_save_chg_for_switch.click()
+        except TimeoutException:
+            self.skipTest("save-changes-for-switch is not clickable within the specified timeout.")
+
         self.wait_until_visible("#edit-layer-source")
 
         # Refresh the page to see if the new values are returned