diff options
Diffstat (limited to 'bitbake/lib/toaster/tests/browser/selenium_helpers_base.py')
-rw-r--r-- | bitbake/lib/toaster/tests/browser/selenium_helpers_base.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py index 393be75496..6953541ab5 100644 --- a/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py +++ b/bitbake/lib/toaster/tests/browser/selenium_helpers_base.py | |||
@@ -27,7 +27,7 @@ from selenium.webdriver.common.by import By | |||
27 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | 27 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities |
28 | from selenium.common.exceptions import NoSuchElementException, \ | 28 | from selenium.common.exceptions import NoSuchElementException, \ |
29 | StaleElementReferenceException, TimeoutException, \ | 29 | StaleElementReferenceException, TimeoutException, \ |
30 | SessionNotCreatedException | 30 | SessionNotCreatedException, WebDriverException |
31 | 31 | ||
32 | def create_selenium_driver(cls,browser='chrome'): | 32 | def create_selenium_driver(cls,browser='chrome'): |
33 | # set default browser string based on env (if available) | 33 | # set default browser string based on env (if available) |
@@ -90,7 +90,7 @@ class Wait(WebDriverWait): | |||
90 | Subclass of WebDriverWait with predetermined timeout and poll | 90 | Subclass of WebDriverWait with predetermined timeout and poll |
91 | frequency. Also deals with a wider variety of exceptions. | 91 | frequency. Also deals with a wider variety of exceptions. |
92 | """ | 92 | """ |
93 | _TIMEOUT = 10 | 93 | _TIMEOUT = 20 |
94 | _POLL_FREQUENCY = 0.5 | 94 | _POLL_FREQUENCY = 0.5 |
95 | 95 | ||
96 | def __init__(self, driver, timeout=_TIMEOUT, poll=_POLL_FREQUENCY): | 96 | def __init__(self, driver, timeout=_TIMEOUT, poll=_POLL_FREQUENCY): |
@@ -114,6 +114,9 @@ class Wait(WebDriverWait): | |||
114 | pass | 114 | pass |
115 | except StaleElementReferenceException: | 115 | except StaleElementReferenceException: |
116 | pass | 116 | pass |
117 | except WebDriverException: | ||
118 | # selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Node with given id does not belong to the document"} | ||
119 | pass | ||
117 | 120 | ||
118 | time.sleep(self._poll) | 121 | time.sleep(self._poll) |
119 | if time.time() > end_time: | 122 | if time.time() > end_time: |
@@ -183,7 +186,7 @@ class SeleniumTestCaseBase(unittest.TestCase): | |||
183 | self.driver.get(abs_url) | 186 | self.driver.get(abs_url) |
184 | 187 | ||
185 | try: # Ensure page is loaded before proceeding | 188 | try: # Ensure page is loaded before proceeding |
186 | self.wait_until_visible("#global-nav", poll=3) | 189 | self.wait_until_visible("#global-nav") |
187 | except NoSuchElementException: | 190 | except NoSuchElementException: |
188 | self.driver.implicitly_wait(3) | 191 | self.driver.implicitly_wait(3) |
189 | except TimeoutException: | 192 | except TimeoutException: |
@@ -208,36 +211,43 @@ class SeleniumTestCaseBase(unittest.TestCase): | |||
208 | """ Return the element which currently has focus on the page """ | 211 | """ Return the element which currently has focus on the page """ |
209 | return self.driver.switch_to.active_element | 212 | return self.driver.switch_to.active_element |
210 | 213 | ||
211 | def wait_until_present(self, selector, poll=0.5): | 214 | def wait_until_present(self, selector, timeout=Wait._TIMEOUT): |
212 | """ Wait until element matching CSS selector is on the page """ | 215 | """ Wait until element matching CSS selector is on the page """ |
213 | is_present = lambda driver: self.find(selector) | 216 | is_present = lambda driver: self.find(selector) |
214 | msg = 'An element matching "%s" should be on the page' % selector | 217 | msg = 'An element matching "%s" should be on the page' % selector |
215 | element = Wait(self.driver, poll=poll).until(is_present, msg) | 218 | element = Wait(self.driver, timeout=timeout).until(is_present, msg) |
216 | if poll > 2: | ||
217 | time.sleep(poll) # element need more delay to be present | ||
218 | return element | 219 | return element |
219 | 220 | ||
220 | def wait_until_visible(self, selector, poll=1): | 221 | def wait_until_visible(self, selector, timeout=Wait._TIMEOUT): |
221 | """ Wait until element matching CSS selector is visible on the page """ | 222 | """ Wait until element matching CSS selector is visible on the page """ |
222 | is_visible = lambda driver: self.find(selector).is_displayed() | 223 | is_visible = lambda driver: self.find(selector).is_displayed() |
223 | msg = 'An element matching "%s" should be visible' % selector | 224 | msg = 'An element matching "%s" should be visible' % selector |
224 | Wait(self.driver, poll=poll).until(is_visible, msg) | 225 | Wait(self.driver, timeout=timeout).until(is_visible, msg) |
225 | time.sleep(poll) # wait for visibility to settle | 226 | return self.find(selector) |
227 | |||
228 | def wait_until_not_visible(self, selector, timeout=Wait._TIMEOUT): | ||
229 | """ Wait until element matching CSS selector is not visible on the page """ | ||
230 | is_visible = lambda driver: self.find(selector).is_displayed() | ||
231 | msg = 'An element matching "%s" should be visible' % selector | ||
232 | Wait(self.driver, timeout=timeout).until_not(is_visible, msg) | ||
226 | return self.find(selector) | 233 | return self.find(selector) |
227 | 234 | ||
228 | def wait_until_clickable(self, selector, poll=1): | 235 | def wait_until_clickable(self, selector, timeout=Wait._TIMEOUT): |
229 | """ Wait until element matching CSS selector is visible on the page """ | 236 | """ Wait until element matching CSS selector is visible on the page """ |
230 | WebDriverWait( | 237 | WebDriverWait(self.driver, timeout=timeout).until(lambda driver: self.driver.execute_script("return jQuery.active == 0")) |
231 | self.driver, | 238 | is_clickable = lambda driver: (self.find(selector).is_displayed() and self.find(selector).is_enabled()) |
232 | Wait._TIMEOUT, | 239 | msg = 'An element matching "%s" should be clickable' % selector |
233 | poll_frequency=poll | 240 | Wait(self.driver, timeout=timeout).until(is_clickable, msg) |
234 | ).until( | ||
235 | EC.element_to_be_clickable((By.ID, selector.removeprefix('#') | ||
236 | ) | ||
237 | ) | ||
238 | ) | ||
239 | return self.find(selector) | 241 | return self.find(selector) |
240 | 242 | ||
243 | def wait_until_element_clickable(self, finder, timeout=Wait._TIMEOUT): | ||
244 | """ Wait until element is clickable """ | ||
245 | WebDriverWait(self.driver, timeout=timeout).until(lambda driver: self.driver.execute_script("return jQuery.active == 0")) | ||
246 | is_clickable = lambda driver: (finder(driver).is_displayed() and finder(driver).is_enabled()) | ||
247 | msg = 'A matching element never became be clickable' | ||
248 | Wait(self.driver, timeout=timeout).until(is_clickable, msg) | ||
249 | return finder(self.driver) | ||
250 | |||
241 | def wait_until_focused(self, selector): | 251 | def wait_until_focused(self, selector): |
242 | """ Wait until element matching CSS selector has focus """ | 252 | """ Wait until element matching CSS selector has focus """ |
243 | is_focused = \ | 253 | is_focused = \ |