From a1bc5a1184c1a72466089ac11cdd1f75f074d01b Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Fri, 18 Oct 2013 11:50:44 -0400 Subject: [PATCH] Add synchronization logic to fill, check, and select --- common/djangoapps/terrain/ui_helpers.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/terrain/ui_helpers.py b/common/djangoapps/terrain/ui_helpers.py index ac8a3a2d1a..357607f11b 100644 --- a/common/djangoapps/terrain/ui_helpers.py +++ b/common/djangoapps/terrain/ui_helpers.py @@ -408,28 +408,34 @@ def css_click(css_selector, index=0, wait_time=30): @world.absorb -def css_check(css_selector, index=0, wait_time=30): +def css_check(css_selector, wait_time=30): """ Checks a check box based on a CSS selector, first waiting for the element to be present and clickable. This is just a wrapper for calling "click" because that's how selenium interacts with check boxes and radio buttons. + Then for synchronization purposes, wait for the element to be checked. This method will return True if the check worked. """ - return css_click(css_selector=css_selector, index=index, wait_time=wait_time) + css_click(css_selector=css_selector, wait_time=wait_time) + wait_for(lambda _: css_find(css_selector).selected) + return True @world.absorb -def select_option(name, value, index=0, wait_time=30): +def select_option(name, value, wait_time=30): ''' A method to select an option + Then for synchronization purposes, wait for the option to be selected. This method will return True if the selection worked. ''' select_css = "select[name='{}']".format(name) option_css = "option[value='{}']".format(value) css_selector = "{} {}".format(select_css, option_css) - return css_click(css_selector=css_selector, index=index, wait_time=wait_time) + css_click(css_selector=css_selector, wait_time=wait_time) + wait_for(lambda _: css_has_value(select_css, value)) + return True @world.absorb @@ -442,7 +448,14 @@ def id_click(elem_id): @world.absorb def css_fill(css_selector, text, index=0): + """ + Set the value of the element to the specified text. + Note that this will replace the current value completely. + Then for synchronization purposes, wait for the value on the page. + """ retry_on_exception(lambda: css_find(css_selector)[index].fill(text)) + wait_for(lambda _: css_has_value(css_selector, text, index=index)) + return True @world.absorb