Commit 9cfbbb23 by Christina Roberts

Merge pull request #10298 from edx/christina/tnl-2419

Use waits because MathJax rendering is asynchronous.
parents cb252c31 f7e2830a
...@@ -116,11 +116,19 @@ class DiscussionThreadPage(PageObject, DiscussionPageMixin): ...@@ -116,11 +116,19 @@ class DiscussionThreadPage(PageObject, DiscussionPageMixin):
def is_discussion_body_visible(self): def is_discussion_body_visible(self):
return self._is_element_visible(".post-body") return self._is_element_visible(".post-body")
def is_mathjax_preview_available(self): def verify_mathjax_preview_available(self):
return self.q(css=".MathJax_Preview").text[0] == "" """ Checks that MathJax Preview css class is present """
self.wait_for(
lambda: len(self.q(css=".MathJax_Preview").text) > 0 and self.q(css=".MathJax_Preview").text[0] == "",
description="MathJax Preview is rendered"
)
def is_mathjax_rendered(self): def verify_mathjax_rendered(self):
return self._is_element_visible(".MathJax") """ Checks that MathJax css class is present """
self.wait_for(
lambda: self._is_element_visible(".MathJax"),
description="MathJax Preview is rendered"
)
def is_response_visible(self, comment_id): def is_response_visible(self, comment_id):
"""Returns true if the response is viewable onscreen""" """Returns true if the response is viewable onscreen"""
......
...@@ -42,21 +42,33 @@ class ProblemPage(PageObject): ...@@ -42,21 +42,33 @@ class ProblemPage(PageObject):
""" """
return self.q(css="div.problem div.problem-hint").text[0] return self.q(css="div.problem div.problem-hint").text[0]
@property def verify_mathjax_rendered_in_problem(self):
def mathjax_rendered_in_problem(self):
""" """
Check that MathJax have been rendered in problem hint Check that MathJax have been rendered in problem hint
""" """
mathjax_container = self.q(css="div.problem p .MathJax .math") def mathjax_present():
return mathjax_container.visible and mathjax_container.present """ Returns True if MathJax css is present in the problem body """
mathjax_container = self.q(css="div.problem p .MathJax .math")
return mathjax_container.visible and mathjax_container.present
@property self.wait_for(
def mathjax_rendered_in_hint(self): mathjax_present,
description="MathJax rendered in problem body"
)
def verify_mathjax_rendered_in_hint(self):
""" """
Check that MathJax have been rendered in problem hint Check that MathJax have been rendered in problem hint
""" """
mathjax_container = self.q(css="div.problem div.problem-hint .MathJax .math") def mathjax_present():
return mathjax_container.visible and mathjax_container.present """ Returns True if MathJax css is present in the problem body """
mathjax_container = self.q(css="div.problem div.problem-hint .MathJax .math")
return mathjax_container.visible and mathjax_container.present
self.wait_for(
mathjax_present,
description="MathJax rendered in hint"
)
def fill_answer(self, text): def fill_answer(self, text):
""" """
......
...@@ -6,7 +6,6 @@ import datetime ...@@ -6,7 +6,6 @@ import datetime
from pytz import UTC from pytz import UTC
from uuid import uuid4 from uuid import uuid4
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from flaky import flaky
from .helpers import BaseDiscussionTestCase from .helpers import BaseDiscussionTestCase
from ..helpers import UniqueCourseTest from ..helpers import UniqueCourseTest
...@@ -218,7 +217,6 @@ class DiscussionTabSingleThreadTest(BaseDiscussionTestCase, DiscussionResponsePa ...@@ -218,7 +217,6 @@ class DiscussionTabSingleThreadTest(BaseDiscussionTestCase, DiscussionResponsePa
self.thread_page = self.create_single_thread_page(thread_id) # pylint: disable=attribute-defined-outside-init self.thread_page = self.create_single_thread_page(thread_id) # pylint: disable=attribute-defined-outside-init
self.thread_page.visit() self.thread_page.visit()
@flaky # TODO fix this, see TNL-2419
def test_mathjax_rendering(self): def test_mathjax_rendering(self):
thread_id = "test_thread_{}".format(uuid4().hex) thread_id = "test_thread_{}".format(uuid4().hex)
...@@ -233,8 +231,8 @@ class DiscussionTabSingleThreadTest(BaseDiscussionTestCase, DiscussionResponsePa ...@@ -233,8 +231,8 @@ class DiscussionTabSingleThreadTest(BaseDiscussionTestCase, DiscussionResponsePa
thread_fixture.push() thread_fixture.push()
self.setup_thread_page(thread_id) self.setup_thread_page(thread_id)
self.assertTrue(self.thread_page.is_discussion_body_visible()) self.assertTrue(self.thread_page.is_discussion_body_visible())
self.assertTrue(self.thread_page.is_mathjax_preview_available()) self.thread_page.verify_mathjax_preview_available()
self.assertTrue(self.thread_page.is_mathjax_rendered()) self.thread_page.verify_mathjax_rendered()
def test_markdown_reference_link(self): def test_markdown_reference_link(self):
""" """
......
...@@ -275,28 +275,18 @@ class ProblemWithMathjax(ProblemsTest): ...@@ -275,28 +275,18 @@ class ProblemWithMathjax(ProblemsTest):
problem_page = ProblemPage(self.browser) problem_page = ProblemPage(self.browser)
self.assertEqual(problem_page.problem_name, "MATHJAX TEST PROBLEM") self.assertEqual(problem_page.problem_name, "MATHJAX TEST PROBLEM")
# Verify MathJax has been rendered problem_page.verify_mathjax_rendered_in_problem()
problem_page.wait_for(
lambda: problem_page.mathjax_rendered_in_problem,
description="MathJax rendered in body"
)
# The hint button rotates through multiple hints # The hint button rotates through multiple hints
problem_page.click_hint() problem_page.click_hint()
self.assertIn("Hint (1 of 2): mathjax should work1", problem_page.hint_text) self.assertIn("Hint (1 of 2): mathjax should work1", problem_page.hint_text)
problem_page.wait_for( problem_page.verify_mathjax_rendered_in_hint()
lambda: problem_page.mathjax_rendered_in_hint,
description="MathJax rendered in hint"
)
# Rotate the hint and check the problem hint # Rotate the hint and check the problem hint
problem_page.click_hint() problem_page.click_hint()
self.assertIn("Hint (2 of 2): mathjax should work2", problem_page.hint_text) self.assertIn("Hint (2 of 2): mathjax should work2", problem_page.hint_text)
problem_page.wait_for( problem_page.verify_mathjax_rendered_in_hint()
lambda: problem_page.mathjax_rendered_in_hint,
description="MathJax rendered in hint"
)
class ProblemPartialCredit(ProblemsTest): class ProblemPartialCredit(ProblemsTest):
......
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