AssetBrowser_TreeNavigation.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. """
  10. """
  11. C13660195: Asset Browser - File Tree Navigation
  12. """
  13. import os
  14. import sys
  15. from PySide2 import QtWidgets, QtTest, QtCore
  16. import azlmbr.legacy.general as general
  17. import azlmbr.paths
  18. sys.path.append(os.path.join(azlmbr.paths.devroot, 'AutomatedTesting', 'Gem', 'PythonTests'))
  19. from automatedtesting_shared.editor_test_helper import EditorTestHelper
  20. import automatedtesting_shared.pyside_utils as pyside_utils
  21. class AssetBrowserTreeNavigationTest(EditorTestHelper):
  22. def __init__(self):
  23. EditorTestHelper.__init__(self, log_prefix="AssetBrowser_TreeNavigation", args=["level"])
  24. def run_test(self):
  25. """
  26. Summary:
  27. Verify if we are able to expand a file hierarchy in the Asset Browser and ScrollBar appears
  28. appropriately.
  29. Expected Behavior:
  30. The folder list is expanded to display the children of the selected folder.
  31. A scroll bar appears to allow scrolling up and down through the asset browser.
  32. Assets are present in the Asset Browser.
  33. Test Steps:
  34. 1) Open a new level
  35. 2) Open Asset Browser
  36. 3) Collapse all files initially
  37. 4) Get all Model Indexes
  38. 5) Expand each of the folder and verify if it is opened
  39. 6) Verify if the ScrollBar appears after expanding the tree
  40. Note:
  41. - This test file must be called from the Lumberyard Editor command terminal
  42. - Any passed and failed tests are written to the Editor.log file.
  43. Parsing the file or running a log_monitor are required to observe the test results.
  44. :return: None
  45. """
  46. def collapse_expand_and_verify(model_index, hierarchy_level):
  47. tree.collapse(model_index)
  48. collapse_success = not tree.isExpanded(model_index)
  49. self.log(f"Level {hierarchy_level} collapsed: {collapse_success}")
  50. tree.expand(model_index)
  51. expand_success = tree.isExpanded(model_index)
  52. self.log(f"Level {hierarchy_level} expanded: {expand_success}")
  53. return collapse_success and expand_success
  54. # This is the hierarchy we are expanding (4 steps inside)
  55. self.file_path = ("AutomatedTesting", "Assets", "ImageGradients", "lumberyard_gsi.png")
  56. # 1) Open a new level
  57. self.test_success = self.create_level(
  58. self.args["level"],
  59. heightmap_resolution=1024,
  60. heightmap_meters_per_pixel=1,
  61. terrain_texture_resolution=4096,
  62. use_terrain=False,
  63. )
  64. # 2) Open Asset Browser (if not opened already)
  65. editor_window = pyside_utils.get_editor_main_window()
  66. asset_browser_open = general.is_pane_visible("Asset Browser")
  67. if not asset_browser_open:
  68. self.log("Opening Asset Browser")
  69. action = pyside_utils.get_action_for_menu_path(editor_window, "Tools", "Asset Browser")
  70. action.trigger()
  71. else:
  72. self.log("Asset Browser is already open")
  73. # 3) Collapse all files initially
  74. main_window = editor_window.findChild(QtWidgets.QMainWindow)
  75. asset_browser = pyside_utils.find_child_by_hierarchy(main_window, ..., "Asset Browser")
  76. tree = pyside_utils.find_child_by_hierarchy(asset_browser, ..., "m_assetBrowserTreeViewWidget")
  77. scroll_area = tree.findChild(QtWidgets.QWidget, "qt_scrollarea_vcontainer")
  78. scroll_bar = scroll_area.findChild(QtWidgets.QScrollBar)
  79. tree.collapseAll()
  80. # 4) Get all Model Indexes
  81. model_index_1 = pyside_utils.find_child_by_hierarchy(tree, self.file_path[0])
  82. model_index_2 = pyside_utils.find_child_by_hierarchy(model_index_1, self.file_path[1])
  83. model_index_3 = pyside_utils.find_child_by_hierarchy(model_index_2, self.file_path[2])
  84. model_index_4 = pyside_utils.find_child_by_hierarchy(model_index_3, self.file_path[3])
  85. # 5) Verify each level of the hierarchy to the file can be collapsed/expanded
  86. self.test_success = collapse_expand_and_verify(model_index_1, 1) and self.test_success
  87. self.test_success = collapse_expand_and_verify(model_index_2, 2) and self.test_success
  88. self.test_success = collapse_expand_and_verify(model_index_3, 3) and self.test_success
  89. self.log(f"Collapse/Expand tests: {self.test_success}")
  90. # Select the asset
  91. tree.scrollTo(model_index_4)
  92. pyside_utils.item_view_index_mouse_click(tree, model_index_4)
  93. # Verify if the currently selected item model index is same as the Asset Model index
  94. # to prove that it is visible
  95. asset_visible = tree.currentIndex() == model_index_4
  96. self.test_success = asset_visible and self.test_success
  97. self.log(f"Asset visibility test: {asset_visible}")
  98. # 6) Verify if the ScrollBar appears after expanding the tree
  99. scrollbar_visible = scroll_bar.isVisible()
  100. self.test_success = scrollbar_visible and self.test_success
  101. self.log(f"Scrollbar visibility test: {scrollbar_visible}")
  102. # 7) Restore Asset Browser tool state
  103. if not asset_browser_open:
  104. self.log("Closing Asset Browser")
  105. general.close_pane("Asset Browser")
  106. test = AssetBrowserTreeNavigationTest()
  107. test.run()