From 9ab35759bee82f4af0169c01a83030032e885489 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Fri, 1 Nov 2013 13:23:30 -0400 Subject: [PATCH] Added wait for problem to re-render when checking or resetting it Added wait for JS on upload page Fixed an issue where css_click wasn't waiting for JS to load --- common/djangoapps/terrain/ui_helpers.py | 24 +++++++++++++++---- .../courseware/features/problems.py | 7 +++++- .../instructor/features/bulk_email.py | 5 +--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/common/djangoapps/terrain/ui_helpers.py b/common/djangoapps/terrain/ui_helpers.py index b97af9c1e2..bde18fd3db 100644 --- a/common/djangoapps/terrain/ui_helpers.py +++ b/common/djangoapps/terrain/ui_helpers.py @@ -44,6 +44,12 @@ REQUIREJS_WAIT = { re.compile('^My Courses \|'): [ "js/sock", "gettext", "js/base", "jquery.ui", "coffee/src/main", "underscore"], + + # Upload + re.compile(r'^\s*Files & Uploads'): [ + 'js/base', 'jquery.ui', 'coffee/src/main', 'underscore', + 'js/views/assets', 'js/views/asset' + ] } @@ -389,12 +395,14 @@ def css_find(css, wait_time=30): @world.absorb -def css_click(css_selector, index=0, wait_time=30): +def css_click(css_selector, index=0, wait_time=30, dismiss_alert=False): """ Perform a click on a CSS selector, first waiting for the element to be present and clickable. This method will return True if the click worked. + + If `dismiss_alert` is true, dismiss any alerts that appear. """ wait_for_clickable(css_selector, timeout=wait_time) wait_for_visible(css_selector, index=index, timeout=wait_time) @@ -403,10 +411,16 @@ def css_click(css_selector, index=0, wait_time=30): msg="Element {}[{}] is present but not visible".format(css_selector, index) ) - result = retry_on_exception(lambda: css_find(css_selector)[index].click()) - if result: - wait_for_js_to_load() - return result + retry_on_exception(lambda: css_find(css_selector)[index].click()) + + # Dismiss any alerts that occur. + # We need to do this before calling `wait_for_js_to_load()` + # to avoid getting an unexpected alert exception + if dismiss_alert: + world.browser.get_alert().accept() + + wait_for_js_to_load() + return True @world.absorb diff --git a/lms/djangoapps/courseware/features/problems.py b/lms/djangoapps/courseware/features/problems.py index ecf1a33719..0be5b72284 100644 --- a/lms/djangoapps/courseware/features/problems.py +++ b/lms/djangoapps/courseware/features/problems.py @@ -107,6 +107,9 @@ def check_problem(step): world.browser.execute_script("window.scrollTo(0,1024)") world.css_click("input.check") + # Wait for the problem to finish re-rendering + world.wait_for_ajax_complete() + @step(u'The "([^"]*)" problem displays a "([^"]*)" answer') def assert_problem_has_answer(step, problem_type, answer_class): @@ -127,6 +130,9 @@ def assert_problem_has_answer(step, problem_type, answer_class): def reset_problem(_step): world.css_click('input.reset') + # Wait for the problem to finish re-rendering + world.wait_for_ajax_complete() + @step(u'I press the button with the label "([^"]*)"$') def press_the_button_with_label(_step, buttonname): @@ -172,7 +178,6 @@ def assert_answer_mark(_step, problem_type, isnt_marked, correctness): *problem_type* is a string identifying the type of problem (e.g. 'drop down') *correctness* is in ['correct', 'incorrect', 'unanswered'] """ - # Determine which selector(s) to look for based on correctness assert(correctness in ['correct', 'incorrect', 'unanswered']) assert(problem_type in PROBLEM_DICT) diff --git a/lms/djangoapps/instructor/features/bulk_email.py b/lms/djangoapps/instructor/features/bulk_email.py index d08b81c9c1..f2f541b9e6 100644 --- a/lms/djangoapps/instructor/features/bulk_email.py +++ b/lms/djangoapps/instructor/features/bulk_email.py @@ -115,10 +115,7 @@ def when_i_send_an_email(step, recipient): editor.fill('test message') # Click send - world.css_click('input[name="send"]') - - # Confirm the alert - world.browser.get_alert().accept() + world.css_click('input[name="send"]', dismiss_alert=True) # Expect to see a message that the email was sent expected_msg = "Your email was successfully queued for sending."