diff --git a/common/djangoapps/terrain/steps.py b/common/djangoapps/terrain/steps.py index 52eeb23c4a..371496f823 100644 --- a/common/djangoapps/terrain/steps.py +++ b/common/djangoapps/terrain/steps.py @@ -9,6 +9,7 @@ from bs4 import BeautifulSoup import time import re import os.path +from selenium.common.exceptions import WebDriverException from logging import getLogger logger = getLogger(__name__) @@ -214,3 +215,15 @@ def save_the_course_content(path='/tmp'): f = open('%s/%s' % (path, filename), 'w') f.write(output) f.close + +@world.absorb +def css_click(css_selector): + try: + world.browser.find_by_css(css_selector).click() + + except WebDriverException: + # Occassionally, MathJax or other JavaScript can cover up + # an element temporarily. + # If this happens, wait a second, then try again + time.sleep(1) + world.browser.find_by_css(css_selector).click() diff --git a/lms/djangoapps/courseware/features/problems.py b/lms/djangoapps/courseware/features/problems.py index 314ffa0dbe..715e2689fb 100644 --- a/lms/djangoapps/courseware/features/problems.py +++ b/lms/djangoapps/courseware/features/problems.py @@ -1,7 +1,5 @@ from lettuce import world, step from lettuce.django import django_url -from selenium.webdriver.support.ui import Select -from selenium.common.exceptions import WebDriverException import random import textwrap import time @@ -208,20 +206,12 @@ def answer_problem(step, problem_type, correctness): @step(u'I check a problem') def check_problem(step): - try: - world.browser.find_by_css("input.check").click() - - except WebDriverException: - # Occassionally, MathJax or other JavaScript can cover up - # the 'Check' input temporarily. - # If this happens, wait a second, then try again - time.sleep(1) - world.browser.find_by_css("input.check").click() + world.css_click("input.check") @step(u'I reset the problem') def reset_problem(step): - world.browser.find_by_css('input.reset').click() + world.css_click('input.reset') @step(u'My "([^"]*)" answer is marked "([^"]*)"')