dashboard_detail.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. self.wait_until_loaded()