test_error_page_embed.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from urllib.parse import quote
  2. from uuid import uuid4
  3. from django.urls import reverse
  4. from sentry.testutils.cases import AcceptanceTestCase
  5. from sentry.testutils.silo import no_silo_test
  6. @no_silo_test
  7. class ErrorPageEmbedTest(AcceptanceTestCase):
  8. def setUp(self):
  9. super().setUp()
  10. self.project = self.create_project()
  11. self.key = self.create_project_key(project=self.project)
  12. self.event_id = uuid4().hex
  13. self.path = "{}?eventId={}&dsn={}".format(
  14. reverse("sentry-error-page-embed"),
  15. quote(self.event_id),
  16. quote(self.key.dsn_public),
  17. )
  18. def wait_for_error_page_embed(self):
  19. script = f"""
  20. const script = window.document.createElement('script');
  21. script.async = true;
  22. script.crossOrigin = 'anonymous';
  23. script.src = '{self.path}';
  24. const injectionPoint = window.document.head || window.document.body;
  25. injectionPoint.appendChild(script);
  26. window.addEventListener('message', (event) => {{
  27. window.__error_page_embed_received_message__ = event.data;
  28. }});
  29. """
  30. self.browser.driver.execute_script(script)
  31. self.browser.wait_until(".sentry-error-embed")
  32. def wait_for_reportdialog_closed_message(self):
  33. self.browser.wait_until_script_execution(
  34. """return window.__error_page_embed_received_message__ === '__sentry_reportdialog_closed__'"""
  35. )
  36. def test_closed_message_received_on_close_button_click(self):
  37. self.wait_for_error_page_embed()
  38. self.browser.click(".sentry-error-embed button.close")
  39. self.wait_for_reportdialog_closed_message()
  40. def test_closed_message_received_on_outside_click(self):
  41. # in order to click outside we need to set a sufficiently large window size
  42. with self.browser.full_viewport(width=900, height=1330, fit_content=False):
  43. self.wait_for_error_page_embed()
  44. self.browser.click("body")
  45. self.wait_for_reportdialog_closed_message()