diff --git a/cms/djangoapps/contentstore/features/advanced-settings.py b/cms/djangoapps/contentstore/features/advanced-settings.py index 4995f3505d..3113603467 100644 --- a/cms/djangoapps/contentstore/features/advanced-settings.py +++ b/cms/djangoapps/contentstore/features/advanced-settings.py @@ -2,7 +2,7 @@ #pylint: disable=W0621 from lettuce import world, step -from nose.tools import assert_false, assert_equal, assert_regexp_matches +from nose.tools import assert_false, assert_equal, assert_regexp_matches, assert_true from common import type_in_codemirror KEY_CSS = '.key input.policy-key' @@ -28,7 +28,14 @@ def i_am_on_advanced_course_settings(step): @step(u'I press the "([^"]*)" notification button$') def press_the_notification_button(step, name): css = 'a.%s-button' % name.lower() - world.css_click(css) + + # Save was clicked if either the save notification bar is gone, or we have a error notification + # overlaying it (expected in the case of typing Object into display_name). + save_clicked = lambda : world.is_css_not_present('.is-shown.wrapper-notification-warning') or \ + world.is_css_present('.is-shown.wrapper-notification-error') + + assert_true(world.css_click(css, success_condition=save_clicked), + 'The save button was not clicked after 5 attempts.') @step(u'I edit the value of a policy key$') diff --git a/common/djangoapps/terrain/ui_helpers.py b/common/djangoapps/terrain/ui_helpers.py index b1c5f30467..8e4330d940 100644 --- a/common/djangoapps/terrain/ui_helpers.py +++ b/common/djangoapps/terrain/ui_helpers.py @@ -58,10 +58,16 @@ def css_find(css, wait_time=5): @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 - This function will return if the click worked (since it is try/excepting all errors) + Perform a click on a CSS selector, retrying if it initially fails. + + 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) attempt = 0 @@ -69,8 +75,9 @@ def css_click(css_selector, index=0, attempts=5): while attempt < attempts: try: world.css_find(css_selector)[index].click() - result = True - break + if success_condition(): + result = True + break except WebDriverException: # Occasionally, MathJax or other JavaScript can cover up # an element temporarily.