From patchwork Thu Dec 14 22:11:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alassane Yattara X-Patchwork-Id: 36275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5696C4167B for ; Thu, 14 Dec 2023 22:11:52 +0000 (UTC) Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by mx.groups.io with SMTP id smtpd.web11.41700.1702591904792623747 for ; Thu, 14 Dec 2023 14:11:44 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@savoirfairelinux.com header.s=DFC430D2-D198-11EC-948E-34200CB392D2 header.b=xCGaBa6X; spf=pass (domain: savoirfairelinux.com, ip: 208.88.110.44, mailfrom: alassane.yattara@savoirfairelinux.com) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 224509C337F for ; Thu, 14 Dec 2023 17:11:44 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavis, port 10032) with ESMTP id DOmfJDi5TU_0; Thu, 14 Dec 2023 17:11:43 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 956A79C33C0; Thu, 14 Dec 2023 17:11:43 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.savoirfairelinux.com 956A79C33C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=savoirfairelinux.com; s=DFC430D2-D198-11EC-948E-34200CB392D2; t=1702591903; bh=Ps5VhZG3aXFU75HiR9QeQubHY2zhj56ZYcvs1jS/2zc=; h=From:To:Date:Message-Id:MIME-Version; b=xCGaBa6X6Fgpsv/sUWvSKw0B6lp+me7wEs6bU6tSwEuvJfAB3bM8SntNWpE1uNk64 BPjNYrqBgdfXd+xXeMpi0XnsqlMsuiEIaufkoKWNjeGJCb1ekNhVhlIhT+35Tvr8Zz lP2YWFC+xonwNuJpIBWHPpduTeRATow/7ED+EanQZsz+Iij3o0/dZ+igxHlDph5c37 kx0VNPtpl3hl5TYm2SRAglaefGymWBStDe1mrtwN1fU+KPiERBVyyBHVA/RLrZU5rh WylMUH/Sjynhh0roe4B+LGhS/dbWfKE4lSBy+he98WcqNyJ/HtQSOcKrEbXU11Raid E6FeLig9UHLcg== X-Virus-Scanned: amavis at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavis, port 10026) with ESMTP id VGJ2vqQCy3uY; Thu, 14 Dec 2023 17:11:43 -0500 (EST) Received: from jedi.. (unknown [196.127.183.75]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id DBCF29C284E; Thu, 14 Dec 2023 17:11:42 -0500 (EST) From: Alassane Yattara To: toaster@lists.yoctoproject.org Cc: Alassane Yattara Subject: [PATCH v2 1/6] toaster/test: bug-fix element click intercepted in browser/test_layerdetails_page.py Date: Thu, 14 Dec 2023 23:11:27 +0100 Message-Id: <20231214221132.603532-1-alassane.yattara@savoirfairelinux.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Thu, 14 Dec 2023 22:11:52 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/toaster/message/6102 selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Signed-off-by: Alassane Yattara --- .../tests/browser/selenium_helpers_base.py | 15 +++++++++++ .../tests/browser/test_layerdetails_page.py | 27 ++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/toaster/tests/browser/selenium_helpers_base.py b/lib/toaster/tests/browser/selenium_helpers_base.py index 46ced5a1..d6cae85d 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 @@ -211,6 +212,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 05ee88b0..9c8fcded 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,15 @@ 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") - self.driver.execute_script("arguments[0].click();", btn_save_chg_for_switch) + 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 +146,15 @@ 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