From 86cfda32b323646a25a36f702f67b783232c9370 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Wed, 2 Apr 2014 13:52:10 -0400 Subject: [PATCH] Add synchronization for rendering to studio xblock tests --- .../test/acceptance/pages/studio/container.py | 15 +++++++++++---- common/test/acceptance/pages/studio/unit.py | 17 ++++++++++++----- common/test/acceptance/pages/xblock/acid.py | 12 ++++++++++-- common/test/acceptance/tests/test_studio.py | 5 +---- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/common/test/acceptance/pages/studio/container.py b/common/test/acceptance/pages/studio/container.py index 68580321e5..070f39a7ea 100644 --- a/common/test/acceptance/pages/studio/container.py +++ b/common/test/acceptance/pages/studio/container.py @@ -3,7 +3,7 @@ Container page in Studio """ from bok_choy.page_object import PageObject - +from bok_choy.promise import Promise from . import BASE_URL @@ -22,11 +22,18 @@ class ContainerPage(PageObject): return "{}/container/{}".format(BASE_URL, self.unit_locator) def is_browser_on_page(self): - # Wait until all components have been loaded + + def _is_finished_loading(): + # Wait until all components have been loaded + is_done = len(self.q(css=XBlockWrapper.BODY_SELECTOR).results) == len( + self.q(css='{} .xblock'.format(XBlockWrapper.BODY_SELECTOR)).results) + return (is_done, is_done) + + # First make sure that an element with the view-container class is present on the page, + # and then wait to make sure that the xblocks are all there. return ( self.q(css='body.view-container').present and - len(self.q(css=XBlockWrapper.BODY_SELECTOR).results) == len( - self.q(css='{} .xblock'.format(XBlockWrapper.BODY_SELECTOR)).results) + Promise(_is_finished_loading, 'Finished rendering the xblock wrappers.').fulfill() ) @property diff --git a/common/test/acceptance/pages/studio/unit.py b/common/test/acceptance/pages/studio/unit.py index f656e678fd..9712051b6b 100644 --- a/common/test/acceptance/pages/studio/unit.py +++ b/common/test/acceptance/pages/studio/unit.py @@ -3,7 +3,7 @@ Unit page in Studio """ from bok_choy.page_object import PageObject -from bok_choy.promise import EmptyPromise +from bok_choy.promise import EmptyPromise, Promise from . import BASE_URL from .container import ContainerPage @@ -24,12 +24,19 @@ class UnitPage(PageObject): return "{}/unit/{}".format(BASE_URL, self.unit_locator) def is_browser_on_page(self): - # Wait until all components have been loaded - number_of_leaf_xblocks = len(self.q(css='{} .xblock-student_view'.format(Component.BODY_SELECTOR)).results) - number_of_container_xblocks = len(self.q(css='{} .wrapper-xblock'.format(Component.BODY_SELECTOR)).results) + + def _is_finished_loading(): + # Wait until all components have been loaded + number_of_leaf_xblocks = len(self.q(css='{} .xblock-student_view'.format(Component.BODY_SELECTOR)).results) + number_of_container_xblocks = len(self.q(css='{} .wrapper-xblock'.format(Component.BODY_SELECTOR)).results) + is_done = len(self.q(css=Component.BODY_SELECTOR).results) == number_of_leaf_xblocks + number_of_container_xblocks + return (is_done, is_done) + + # First make sure that an element with the view-unit class is present on the page, + # and then wait to make sure that the xblocks are all there return ( self.q(css='body.view-unit').present and - len(self.q(css=Component.BODY_SELECTOR).results) == number_of_leaf_xblocks + number_of_container_xblocks + Promise(_is_finished_loading, 'Finished rendering the xblocks in the unit.').fulfill() ) @property diff --git a/common/test/acceptance/pages/xblock/acid.py b/common/test/acceptance/pages/xblock/acid.py index f9c1c1610b..9b9218ebe7 100644 --- a/common/test/acceptance/pages/xblock/acid.py +++ b/common/test/acceptance/pages/xblock/acid.py @@ -3,7 +3,7 @@ PageObjects related to the AcidBlock """ from bok_choy.page_object import PageObject -from bok_choy.promise import EmptyPromise, BrokenPromise +from bok_choy.promise import EmptyPromise, BrokenPromise, Promise class AcidView(PageObject): """ @@ -24,9 +24,17 @@ class AcidView(PageObject): self.context_selector = context_selector def is_browser_on_page(self): + + def _is_finished_loading(): + # Wait for the xblock javascript to finish initializing + is_done = self.browser.execute_script("return $({!r}).data('initialized')".format(self.context_selector)) + return (is_done, is_done) + + # First make sure that an element with the view-container class is present on the page, + # and then wait to make sure that the xblock has finished initializing. return ( self.q(css='{} .acid-block'.format(self.context_selector)).present and - self.browser.execute_script("return $({!r}).data('initialized')".format(self.context_selector)) + Promise(_is_finished_loading, 'Finished initializing the xblock.').fulfill() ) def test_passed(self, test_selector): diff --git a/common/test/acceptance/tests/test_studio.py b/common/test/acceptance/tests/test_studio.py index e5774d6e81..e5f876104f 100644 --- a/common/test/acceptance/tests/test_studio.py +++ b/common/test/acceptance/tests/test_studio.py @@ -25,7 +25,7 @@ from ..pages.studio.textbooks import TextbooksPage from ..pages.xblock.acid import AcidView from ..fixtures.course import CourseFixture, XBlockFixtureDesc -from .helpers import UniqueCourseTest, load_data_str +from .helpers import UniqueCourseTest class LoggedOutTest(WebAppTest): @@ -170,7 +170,6 @@ class XBlockAcidBase(WebAppTest): acid_block = AcidView(self.browser, unit.components[0].preview_selector) self.validate_acid_block_preview(acid_block) - @skip('Temporarily diabling because it is failing in Jenkins. TE-369') def test_acid_block_editor(self): """ Verify that all expected acid block tests pass in studio editor @@ -189,7 +188,6 @@ class XBlockAcidBase(WebAppTest): self.assertTrue(acid_block.scope_passed('settings')) -@skip('Temporarily diabling because it is failing in Jenkins. TE-369') class XBlockAcidNoChildTest(XBlockAcidBase): """ Tests of an AcidBlock with no children @@ -226,7 +224,6 @@ class XBlockAcidParentBase(XBlockAcidBase): super(XBlockAcidParentBase, self).validate_acid_block_preview(acid_block) self.assertTrue(acid_block.child_tests_passed) - @skip('Intermittently failing, needs a better page definition that waits until the unit is fully rendered') def test_acid_block_preview(self): """ Verify that all expected acid block tests pass in studio preview