WebUI tests: Fix 'Button is not displayed' exception

Add a small timeout (up to 5 seconds) which allows to prevent exceptions when
WebDriver attempts to click a button before it is rendered.

Ticket: https://pagure.io/freeipa/issue/8169

Signed-off-by: Serhii Tsymbaliuk <stsymbal@redhat.com>
Reviewed-By: Sergey Orlov <sorlov@redhat.com>
This commit is contained in:
Serhii Tsymbaliuk 2020-02-02 20:17:44 +01:00
parent d7830d900d
commit 9418042ee7
No known key found for this signature in database
GPG Key ID: 632C7F5C1BC85519

View File

@ -731,9 +731,16 @@ class UI_driver:
def _button_click(self, selector, parent, name=''):
btn = self.find(selector, By.CSS_SELECTOR, parent, strict=True)
# The small timeout (up to 5 seconds) allows to prevent exceptions when
# driver attempts to click a button before it is rendered.
WebDriverWait(self.driver, 5, 0.2).until(
lambda d: btn.is_displayed(),
'Button is not displayed: %s' % (name or selector)
)
self.move_to_element_in_page(btn)
disabled = btn.get_attribute("disabled")
assert btn.is_displayed(), 'Button is not displayed: %s' % name
assert not disabled, 'Invalid button state: disabled. Button: %s' % name
btn.click()
self.wait_for_request()