Commit 9ab35759 by Will Daly

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
parent 9f104eb6
...@@ -44,6 +44,12 @@ REQUIREJS_WAIT = { ...@@ -44,6 +44,12 @@ REQUIREJS_WAIT = {
re.compile('^My Courses \|'): [ re.compile('^My Courses \|'): [
"js/sock", "gettext", "js/base", "js/sock", "gettext", "js/base",
"jquery.ui", "coffee/src/main", "underscore"], "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): ...@@ -389,12 +395,14 @@ def css_find(css, wait_time=30):
@world.absorb @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 Perform a click on a CSS selector, first waiting for the element
to be present and clickable. to be present and clickable.
This method will return True if the click worked. 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_clickable(css_selector, timeout=wait_time)
wait_for_visible(css_selector, index=index, 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): ...@@ -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) msg="Element {}[{}] is present but not visible".format(css_selector, index)
) )
result = retry_on_exception(lambda: css_find(css_selector)[index].click()) retry_on_exception(lambda: css_find(css_selector)[index].click())
if result:
# 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() wait_for_js_to_load()
return result return True
@world.absorb @world.absorb
......
...@@ -107,6 +107,9 @@ def check_problem(step): ...@@ -107,6 +107,9 @@ def check_problem(step):
world.browser.execute_script("window.scrollTo(0,1024)") world.browser.execute_script("window.scrollTo(0,1024)")
world.css_click("input.check") 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') @step(u'The "([^"]*)" problem displays a "([^"]*)" answer')
def assert_problem_has_answer(step, problem_type, answer_class): def assert_problem_has_answer(step, problem_type, answer_class):
...@@ -127,6 +130,9 @@ 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): def reset_problem(_step):
world.css_click('input.reset') 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 "([^"]*)"$') @step(u'I press the button with the label "([^"]*)"$')
def press_the_button_with_label(_step, buttonname): def press_the_button_with_label(_step, buttonname):
...@@ -172,7 +178,6 @@ def assert_answer_mark(_step, problem_type, isnt_marked, correctness): ...@@ -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') *problem_type* is a string identifying the type of problem (e.g. 'drop down')
*correctness* is in ['correct', 'incorrect', 'unanswered'] *correctness* is in ['correct', 'incorrect', 'unanswered']
""" """
# Determine which selector(s) to look for based on correctness # Determine which selector(s) to look for based on correctness
assert(correctness in ['correct', 'incorrect', 'unanswered']) assert(correctness in ['correct', 'incorrect', 'unanswered'])
assert(problem_type in PROBLEM_DICT) assert(problem_type in PROBLEM_DICT)
......
...@@ -115,10 +115,7 @@ def when_i_send_an_email(step, recipient): ...@@ -115,10 +115,7 @@ def when_i_send_an_email(step, recipient):
editor.fill('test message') editor.fill('test message')
# Click send # Click send
world.css_click('input[name="send"]') world.css_click('input[name="send"]', dismiss_alert=True)
# Confirm the alert
world.browser.get_alert().accept()
# Expect to see a message that the email was sent # Expect to see a message that the email was sent
expected_msg = "Your email was successfully queued for sending." expected_msg = "Your email was successfully queued for sending."
......
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