Commit ebc9fa9e by JonahStanley

Made a retry_on_exception world function that will retry the given function

parent 1ae86673
......@@ -144,17 +144,12 @@ def log_into_studio(
world.is_css_present(signin_css)
world.css_click(signin_css)
attempt = 0
while attempt < 5:
try:
login_form = world.browser.find_by_css('form#login_form')
login_form.find_by_name('email').fill(email)
login_form.find_by_name('password').fill(password)
login_form.find_by_name('submit').click()
break
except:
attempt += 1
def fill_login_form():
login_form = world.browser.find_by_css('form#login_form')
login_form.find_by_name('email').fill(email)
login_form.find_by_name('password').fill(password)
login_form.find_by_name('submit').click()
world.retry_on_exception(fill_login_form)
assert_true(world.is_css_present('.new-course-button'))
......
......@@ -7,18 +7,14 @@ from common import *
@step('I fill in the registration form$')
def i_fill_in_the_registration_form(step):
attempt = 0
while attempt < 5:
try:
register_form = world.css_find('form#register_form')
register_form.find_by_name('email').fill('robot+studio@edx.org')
register_form.find_by_name('password').fill('test')
register_form.find_by_name('username').fill('robot-studio')
register_form.find_by_name('name').fill('Robot Studio')
register_form.find_by_name('terms_of_service').check()
break
except:
attempt += 1
def fill_in_reg_form():
register_form = world.css_find('form#register_form')
register_form.find_by_name('email').fill('robot+studio@edx.org')
register_form.find_by_name('password').fill('test')
register_form.find_by_name('username').fill('robot-studio')
register_form.find_by_name('name').fill('Robot Studio')
register_form.find_by_name('terms_of_service').check()
world.retry_on_exception(fill_in_reg_form)
@step('I press the Create My Account button on the registration form$')
......
......@@ -249,7 +249,7 @@ def css_visible(css_selector, index=0, max_attempts=5):
attempt = 0
while attempt < max_attempts:
try:
return world.browser.find_by_css(css_selector)[index].visible
return
except:
attempt += 1
assert_true(attempt < max_attempts, 'Ran out of attempts to access {}'.format(css_selector))
......@@ -299,3 +299,14 @@ def click_tools():
@world.absorb
def is_mac():
return platform.mac_ver()[0] is not ''
@world.absorb
def retry_on_exception(func, max_attempts=5):
attempts = 0
while attempts < max_attempts:
try:
return func()
break
except:
attempts += 1
......@@ -20,15 +20,11 @@ def i_am_an_activated_user(step):
def i_submit_my_credentials_on_the_login_form(step):
fill_in_the_login_form('email', 'robot@edx.org')
fill_in_the_login_form('password', 'test')
attempt = 0
while attempt < 5:
try:
login_form = world.browser.find_by_css('form#login-form')
login_form.find_by_name('submit').click()
break
except:
attempt += 1
assert_true(attempt < 5, 'Login form could not be clicked')
def submit_login_form():
login_form = world.browser.find_by_css('form#login-form')
login_form.find_by_name('submit').click()
world.retry_on_excetion(submit_login_form)
@step(u'I should see the login error message "([^"]*)"$')
......@@ -57,13 +53,8 @@ def user_is_an_activated_user(uname):
def fill_in_the_login_form(field, value):
attempt = 0
while attempt < 5:
try:
login_form = world.browser.find_by_css('form#login-form')
form_field = login_form.find_by_name(field)
form_field.fill(value)
break
except:
attempt += 1
assert_true(attempt < 5, 'Login form could not be filled')
def fill_login_form():
login_form = world.browser.find_by_css('form#login-form')
form_field = login_form.find_by_name(field)
form_field.fill(value)
world.retry_on_excetion(fill_login_form)
......@@ -6,38 +6,26 @@ from lettuce import world, step
@step('I fill in "([^"]*)" on the registration form with "([^"]*)"$')
def when_i_fill_in_field_on_the_registration_form_with_value(step, field, value):
attempt = 0
while attempt < 5:
try:
register_form = world.browser.find_by_css('form#register-form')
form_field = register_form.find_by_name(field)
form_field.fill(value)
break
except:
attempt += 1
def fill_in_registration():
register_form = world.browser.find_by_css('form#register-form')
form_field = register_form.find_by_name(field)
form_field.fill(value)
world.retry_on_exception(fill_in_registration)
@step('I submit the registration form$')
def i_press_the_button_on_the_registration_form(step):
attempt = 0
while attempt < 5:
try:
register_form = world.browser.find_by_css('form#register-form')
register_form.find_by_name('submit').click()
break
except:
attempt += 1
def submit_registration():
register_form = world.browser.find_by_css('form#register-form')
register_form.find_by_name('submit').click()
world.retry_on_exception(submit_registration)
@step('I check the checkbox named "([^"]*)"$')
def i_check_checkbox(step, checkbox):
attempt = 0
while attempt < 5:
try:
world.browser.find_by_name(checkbox).check()
break
except:
attempt += 1
def check_box():
world.browser.find_by_name(checkbox).check()
world.retry_on_exception(check_box)
@step('I should see "([^"]*)" in the dashboard banner$')
......
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