From defbd874683bcb804fec3073f05cb92e2106a55b Mon Sep 17 00:00:00 2001 From: Will Daly Date: Wed, 19 Feb 2014 10:35:59 -0500 Subject: [PATCH] Protect Acid XBlock test from stale element or zero-length locator list --- common/test/acceptance/pages/studio/unit.py | 17 +++++++++++------ common/test/acceptance/tests/test_lms.py | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/common/test/acceptance/pages/studio/unit.py b/common/test/acceptance/pages/studio/unit.py index 9b5934abba..e082d23d8d 100644 --- a/common/test/acceptance/pages/studio/unit.py +++ b/common/test/acceptance/pages/studio/unit.py @@ -4,7 +4,7 @@ Unit page in Studio from bok_choy.page_object import PageObject from bok_choy.query import SubQuery -from bok_choy.promise import EmptyPromise, fulfill +from bok_choy.promise import Promise, EmptyPromise, fulfill from . import BASE_URL @@ -27,12 +27,17 @@ class UnitPage(PageObject): return self.is_css_present('body.view-unit') def component(self, title): - return Component( - self.browser, - self.q(css=Component.BODY_SELECTOR).filter( + return Component(self.browser, self._locator(title)) + + def _locator(self, title): + def _check_func(): + locators = self.q(css=Component.BODY_SELECTOR).filter( SubQuery(css=Component.NAME_SELECTOR).filter(text=title) - )[0]['data-locator'] - ) + ).map(lambda el: el['data-locator']).results + + return (len(locators) > 0, locators[0]) + + return fulfill(Promise(_check_func, "Found data locator for component")) class Component(PageObject): diff --git a/common/test/acceptance/tests/test_lms.py b/common/test/acceptance/tests/test_lms.py index 5744167e31..bbad1ba4c9 100644 --- a/common/test/acceptance/tests/test_lms.py +++ b/common/test/acceptance/tests/test_lms.py @@ -69,6 +69,23 @@ class RegistrationTest(UniqueCourseTest): course_names = dashboard.available_courses self.assertIn(self.course_info['display_name'], course_names) + def assert_course_available(self, course_id): + # Occassionally this does not show up immediately, + # so we wait and try reloading the page + def _check_course_available(): + available = self.find_courses_page.course_id_list + if course_id in available: + return True + else: + self.find_courses_page.visit() + return False + + return fulfill(EmptyPromise( + _check_course_available, + "Found course {course_id} in the list of available courses".format(course_id=course_id), + try_limit=3, try_interval=2 + )) + class LanguageTest(UniqueCourseTest): """