Merge branch 'master' into jonahstanley/add-courseteam-tests

This commit is contained in:
JonahStanley
2013-06-20 16:55:37 -04:00
153 changed files with 1498 additions and 5058 deletions

View File

@@ -49,7 +49,7 @@ def css_has_text(css_selector, text):
@world.absorb
def css_find(css, wait_time=5):
def is_visible(driver):
def is_visible(_driver):
return EC.visibility_of_element_located((By.CSS_SELECTOR, css,))
world.browser.is_element_present_by_css(css, wait_time=wait_time)
@@ -58,19 +58,26 @@ 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, max_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
result = False
while attempt < attempts:
while attempt < max_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.
@@ -83,15 +90,47 @@ def css_click(css_selector, index=0, attempts=5):
@world.absorb
def css_click_at(css, x=10, y=10):
def css_check(css_selector, index=0, max_attempts=5, success_condition=lambda: True):
"""
Checks a check box based 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 check worked.
This function will return True if the check worked (taking into account both errors and the optional
success_condition).
"""
assert is_css_present(css_selector)
attempt = 0
result = False
while attempt < max_attempts:
try:
world.css_find(css_selector)[index].check()
if success_condition():
result = True
break
except WebDriverException:
# Occasionally, MathJax or other JavaScript can cover up
# an element temporarily.
# If this happens, wait a second, then try again
world.wait(1)
attempt += 1
except:
attempt += 1
return result
@world.absorb
def css_click_at(css, x_cord=10, y_cord=10):
'''
A method to click at x,y coordinates of the element
rather than in the center of the element
'''
e = css_find(css).first
e.action_chains.move_to_element_with_offset(e._element, x, y)
e.action_chains.click()
e.action_chains.perform()
element = css_find(css).first
element.action_chains.move_to_element_with_offset(element._element, x_cord, y_cord)
element.action_chains.click()
element.action_chains.perform()
@world.absorb
@@ -136,7 +175,7 @@ def css_visible(css_selector):
@world.absorb
def dialogs_closed():
def are_dialogs_closed(driver):
def are_dialogs_closed(_driver):
'''
Return True when no modal dialogs are visible
'''
@@ -147,12 +186,12 @@ def dialogs_closed():
@world.absorb
def save_the_html(path='/tmp'):
u = world.browser.url
url = world.browser.url
html = world.browser.html.encode('ascii', 'ignore')
filename = '%s.html' % quote_plus(u)
f = open('%s/%s' % (path, filename), 'w')
f.write(html)
f.close()
filename = '%s.html' % quote_plus(url)
file = open('%s/%s' % (path, filename), 'w')
file.write(html)
file.close()
@world.absorb