From 715898cb9a2688957120d0286dc136db1298f9de Mon Sep 17 00:00:00 2001 From: Alassane Yattara Date: Wed, 29 Nov 2023 23:54:08 +0100 Subject: bitbake: toaster/tests: Update methods wait_until_~ to skip using time.sleep Update Class Wait from selenium_helpers_base, to override wait_until_visible and wait_until_present with poll argument to better handle delay between driver actions (Bitbake rev: 486817ac6ad28580d81dcf6e3789678d9259bb54) Signed-off-by: Alassane Yattara Signed-off-by: Richard Purdie --- bitbake/lib/toaster/tests/browser/selenium_helpers_base.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'bitbake/lib/toaster') diff --git a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py index e0ac43768e..d9ea7fd108 100644 --- a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py +++ b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py @@ -71,7 +71,9 @@ class Wait(WebDriverWait): _TIMEOUT = 10 _POLL_FREQUENCY = 0.5 - def __init__(self, driver): + def __init__(self, driver, timeout=_TIMEOUT, poll=_POLL_FREQUENCY): + self._TIMEOUT = timeout + self._POLL_FREQUENCY = poll super(Wait, self).__init__(driver, self._TIMEOUT, self._POLL_FREQUENCY) def until(self, method, message=''): @@ -175,18 +177,19 @@ class SeleniumTestCaseBase(unittest.TestCase): """ Return the element which currently has focus on the page """ return self.driver.switch_to.active_element - def wait_until_present(self, selector): + def wait_until_present(self, selector, poll=0.5): """ Wait until element matching CSS selector is on the page """ is_present = lambda driver: self.find(selector) msg = 'An element matching "%s" should be on the page' % selector - element = Wait(self.driver).until(is_present, msg) + element = Wait(self.driver, poll=poll).until(is_present, msg) return element - def wait_until_visible(self, selector): + def wait_until_visible(self, selector, poll=1): """ Wait until element matching CSS selector is visible on the page """ is_visible = lambda driver: self.find(selector).is_displayed() msg = 'An element matching "%s" should be visible' % selector - Wait(self.driver).until(is_visible, msg) + Wait(self.driver, poll=poll).until(is_visible, msg) + time.sleep(poll) # wait for visibility to settle return self.find(selector) def wait_until_focused(self, selector): -- cgit v1.2.3-54-g00ecf