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