Commit 66439943 by cahrens

Add an optional success lambda to css_click.

parent 9878c75b
...@@ -34,14 +34,8 @@ def press_the_notification_button(step, name): ...@@ -34,14 +34,8 @@ def press_the_notification_button(step, name):
save_clicked = lambda : world.is_css_not_present('.is-shown.wrapper-notification-warning') or \ save_clicked = lambda : world.is_css_not_present('.is-shown.wrapper-notification-warning') or \
world.is_css_present('.is-shown.wrapper-notification-error') world.is_css_present('.is-shown.wrapper-notification-error')
attempts = 0 assert_true(world.css_click(css, success_condition=save_clicked),
while attempts < 5: 'The save button was not clicked after 5 attempts.')
world.css_click(css)
if save_clicked():
break
attempts+=1
assert_true(save_clicked(), 'The save button was not clicked after 5 attempts.')
@step(u'I edit the value of a policy key$') @step(u'I edit the value of a policy key$')
......
...@@ -58,10 +58,16 @@ def css_find(css, wait_time=5): ...@@ -58,10 +58,16 @@ def css_find(css, wait_time=5):
@world.absorb @world.absorb
def css_click(css_selector, index=0, attempts=5): def css_click(css_selector, index=0, attempts=5, success_condition=lambda:True):
""" """
Perform a click on a CSS selector, retrying if it initially fails Perform a click on a CSS selector, retrying if it initially fails.
This function will return if the click worked (since it is try/excepting all errors)
This function handles errors that may be thrown if the component cannot be clicked on.
However, there are cases where an error may not be thrown, and yet the operation did not
actually succeed. For those cases, a success_condition lambda can be supplied to verify that the click worked.
This function will return True if the click worked (taking into account both errors and the optional
success_condition).
""" """
assert is_css_present(css_selector) assert is_css_present(css_selector)
attempt = 0 attempt = 0
...@@ -69,8 +75,9 @@ def css_click(css_selector, index=0, attempts=5): ...@@ -69,8 +75,9 @@ def css_click(css_selector, index=0, attempts=5):
while attempt < attempts: while attempt < attempts:
try: try:
world.css_find(css_selector)[index].click() world.css_find(css_selector)[index].click()
result = True if success_condition():
break result = True
break
except WebDriverException: except WebDriverException:
# Occasionally, MathJax or other JavaScript can cover up # Occasionally, MathJax or other JavaScript can cover up
# an element temporarily. # an element temporarily.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment