dashboard_detail.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from .base import BasePage
  2. EDIT_WIDGET_BUTTON = '[data-test-id="widget-edit"]'
  3. WIDGET_DRAG_HANDLE = ".widget-drag"
  4. WIDGET_RESIZE_HANDLE = ".widget-resize"
  5. WIDGET_EDITABLE_TEXT_LABEL = '[data-test-id="editable-text-label"]'
  6. WIDGET_TITLE_FIELD = 'input[aria-label="Widget title"]'
  7. class DashboardDetailPage(BasePage):
  8. def __init__(self, browser, client, **kwargs):
  9. super().__init__(browser)
  10. self.client = client
  11. self.organization = kwargs.get("organization", None)
  12. self.dashboard = kwargs.get("dashboard", None)
  13. def wait_until_loaded(self):
  14. self.browser.wait_until_not('[data-test-id="events-request-loading"]')
  15. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  16. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  17. self.browser.wait_until_not(".loading")
  18. def visit_default_overview(self):
  19. self.browser.get(f"/organizations/{self.organization.slug}/dashboard/default-overview/")
  20. self.wait_until_loaded()
  21. self.browser.driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
  22. self.wait_until_loaded()
  23. def visit_create_dashboard(self):
  24. self.browser.get(f"/organizations/{self.organization.slug}/dashboards/new/")
  25. self.wait_until_loaded()
  26. def visit_dashboard_detail(self):
  27. self.browser.get(f"/organizations/{self.organization.slug}/dashboard/{self.dashboard.id}/")
  28. self.wait_until_loaded()
  29. def enter_edit_state(self):
  30. button = self.browser.element('[data-test-id="dashboard-edit"]')
  31. self.browser.wait_until_clickable('[data-test-id="dashboard-edit"]')
  32. button.click()
  33. self.wait_until_loaded()
  34. def click_dashboard_add_widget_button(self):
  35. button = self.browser.element('[data-test-id="widget-add"]')
  36. # HACK: Use JavaScript to execute click to avoid click intercepted issues
  37. self.browser.driver.execute_script("arguments[0].click()", button)
  38. self.wait_until_loaded()
  39. def click_dashboard_header_add_widget_button(self):
  40. button = self.browser.element('[data-test-id="add-widget-library"]')
  41. self.browser.wait_until_clickable('[data-test-id="add-widget-library"]')
  42. button.click()
  43. self.wait_until_loaded()
  44. def click_cancel_button(self):
  45. button = self.browser.element('[data-test-id="dashboard-cancel"]')
  46. self.browser.wait_until_clickable('[data-test-id="dashboard-cancel"]')
  47. button.click()
  48. self.wait_until_loaded()
  49. def add_widget_through_dashboard(self, widget_title):
  50. self.click_dashboard_add_widget_button()
  51. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  52. title_input.clear()
  53. title_input.send_keys(widget_title)
  54. button = self.browser.element('[aria-label="Add Widget"]')
  55. button.click()
  56. self.wait_until_loaded()
  57. def save_dashboard(self):
  58. button = self.browser.element('[data-test-id="dashboard-commit"]')
  59. self.browser.wait_until_clickable('[data-test-id="dashboard-commit"]')
  60. button.click()
  61. # This is a kind of hack.
  62. # After we click the button, an API call is made and we want to wait
  63. # until the API call finishes. Since the loading indicator isn't used
  64. # we can't rely on self.wait_until_loaded(). The UI shows a
  65. # success toast, however if a previous step of a test shows a success
  66. # toast, a wait_until([data-test-id="toast-success"]) will return
  67. # immediately due to the previous toast still being in the DOM.
  68. # Since clicking the save dasboard button is removed once the API
  69. # call is complete, we can wait for that as a signal
  70. # that the API is complete.
  71. self.browser.wait_until_not('[data-test-id="dashboard-commit"]')
  72. self.wait_until_loaded()