AssetBrowser_TreeNavigation.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. class Tests:
  7. collapse_expand = (
  8. "Asset Browser hierarchy successfully collapsed/expanded",
  9. "Failed to collapse/expand Asset Browser hierarchy"
  10. )
  11. asset_visible = (
  12. "Expected asset is visible in the Asset Browser hierarchy",
  13. "Failed to find expected asset in the Asset Browser hierarchy"
  14. )
  15. scrollbar_visible = (
  16. "Scrollbar is visible",
  17. "Scrollbar was not found"
  18. )
  19. def AssetBrowser_TreeNavigation():
  20. """
  21. Summary:
  22. Verify if we are able to expand a file hierarchy in the Asset Browser and ScrollBar appears
  23. appropriately.
  24. Expected Behavior:
  25. The folder list is expanded to display the children of the selected folder.
  26. A scroll bar appears to allow scrolling up and down through the asset browser.
  27. Assets are present in the Asset Browser.
  28. Test Steps:
  29. 1) Open a simple level
  30. 2) Open Asset Browser
  31. 3) Collapse all files initially
  32. 4) Get all Model Indexes
  33. 5) Expand each of the folder and verify if it is opened
  34. 6) Verify if the ScrollBar appears after expanding the tree
  35. Note:
  36. - This test file must be called from the Open 3D Engine Editor command terminal
  37. - Any passed and failed tests are written to the Editor.log file.
  38. Parsing the file or running a log_monitor are required to observe the test results.
  39. :return: None
  40. """
  41. from PySide2 import QtWidgets, QtTest, QtCore
  42. import azlmbr.legacy.general as general
  43. import pyside_utils
  44. import editor_python_test_tools.hydra_editor_utils as hydra
  45. from editor_python_test_tools.utils import Report
  46. from editor_python_test_tools.utils import TestHelper as helper
  47. def collapse_expand_and_verify(model_index, hierarchy_level):
  48. tree.collapse(model_index)
  49. collapse_success = not tree.isExpanded(model_index)
  50. Report.info(f"Level {hierarchy_level} collapsed: {collapse_success}")
  51. tree.expand(model_index)
  52. expand_success = tree.isExpanded(model_index)
  53. Report.info(f"Level {hierarchy_level} expanded: {expand_success}")
  54. return collapse_success and expand_success
  55. # This is the hierarchy we are expanding (4 steps inside)
  56. file_path = ("AutomatedTesting", "Assets", "ImageGradients", "image_grad_test_gsi.png")
  57. # 1) Open an existing simple level
  58. hydra.open_base_level()
  59. # 2) Open Asset Browser (if not opened already)
  60. editor_window = pyside_utils.get_editor_main_window()
  61. asset_browser_open = general.is_pane_visible("Asset Browser")
  62. if not asset_browser_open:
  63. Report.info("Opening Asset Browser")
  64. action = pyside_utils.get_action_for_menu_path(editor_window, "Tools", "Asset Browser")
  65. action.trigger()
  66. else:
  67. Report.info("Asset Browser is already open")
  68. # 3) Switch to List view and collapse all files initially
  69. main_window = editor_window.findChild(QtWidgets.QMainWindow)
  70. asset_browser = pyside_utils.find_child_by_pattern(main_window, text="Asset Browser", type=QtWidgets.QDockWidget)
  71. tree_view_button = asset_browser.findChild(QtWidgets.QToolButton, "m_treeViewButton")
  72. tree_view_button.click()
  73. general.idle_wait(1.0)
  74. tree = pyside_utils.find_child_by_pattern(asset_browser, "m_assetBrowserTreeViewWidget")
  75. scroll_area = tree.findChild(QtWidgets.QWidget, "qt_scrollarea_vcontainer")
  76. scroll_bar = scroll_area.findChild(QtWidgets.QScrollBar)
  77. tree.collapseAll()
  78. # 4) Get all Model Indexes
  79. model_index_1 = pyside_utils.find_child_by_hierarchy(tree, file_path[0])
  80. model_index_2 = pyside_utils.find_child_by_hierarchy(model_index_1, file_path[1])
  81. model_index_3 = pyside_utils.find_child_by_hierarchy(model_index_2, file_path[2])
  82. model_index_4 = pyside_utils.find_child_by_hierarchy(model_index_3, file_path[3])
  83. # 5) Verify each level of the hierarchy to the file can be collapsed/expanded
  84. Report.result(Tests.collapse_expand, collapse_expand_and_verify(model_index_1, 1) and
  85. collapse_expand_and_verify(model_index_2, 2) and collapse_expand_and_verify(model_index_3, 3))
  86. # Select the asset
  87. tree.scrollTo(model_index_4)
  88. pyside_utils.item_view_index_mouse_click(tree, model_index_4)
  89. # Verify if the currently selected item model index is same as the Asset Model index
  90. # to prove that it is visible
  91. Report.result(Tests.asset_visible, tree.currentIndex() == model_index_4)
  92. # 6) Verify if the ScrollBar appears after expanding the tree
  93. Report.result(Tests.scrollbar_visible, scroll_bar.isVisible())
  94. # 7) Restore Asset Browser tool state
  95. if not asset_browser_open:
  96. Report.info("Closing Asset Browser")
  97. general.close_pane("Asset Browser")
  98. if __name__ == "__main__":
  99. from editor_python_test_tools.utils import Report
  100. Report.start_test(AssetBrowser_TreeNavigation)