dashboard_detail.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. self.browser.element(WIDGET_EDITABLE_TEXT_LABEL).click()
  52. title_input = self.browser.element(WIDGET_TITLE_FIELD)
  53. title_input.clear()
  54. title_input.send_keys(widget_title)
  55. button = self.browser.element('[aria-label="Add Widget"]')
  56. button.click()
  57. self.wait_until_loaded()
  58. def save_dashboard(self):
  59. button = self.browser.element('[data-test-id="dashboard-commit"]')
  60. self.browser.wait_until_clickable('[data-test-id="dashboard-commit"]')
  61. button.click()
  62. # This is a kind of hack.
  63. # After we click the button, an API call is made and we want to wait
  64. # until the API call finishes. Since the loading indicator isn't used
  65. # we can't rely on self.wait_until_loaded(). The UI shows a
  66. # success toast, however if a previous step of a test shows a success
  67. # toast, a wait_until([data-test-id="toast-success"]) will return
  68. # immediately due to the previous toast still being in the DOM.
  69. # Since clicking the save dasboard button is removed once the API
  70. # call is complete, we can wait for that as a signal
  71. # that the API is complete.
  72. self.browser.wait_until_not('[data-test-id="dashboard-commit"]')
  73. self.wait_until_loaded()