2
0

NodePalette_HappyPath_CanSelectNode.py 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. category_selected = ("Category can be selected", "Category cannot be selected")
  8. node_selected = ("Node can be selected", "Node cannot be selected")
  9. def TestNodePaletteHappyPathCanSelectNode():
  10. """
  11. Summary:
  12. Categories and Nodes can be selected
  13. Expected Behavior:
  14. A category can be selected inside the Node Palette
  15. A Node can be selected inside the Node Palette
  16. Test Steps:
  17. 1) Open Script Canvas window (Tools > Script Canvas)
  18. 2) Get the SC window object and get a handle on the Node Palette
  19. 3) Get a handle on the node palette's tree of nodes then expand the QTView tree object
  20. 4) Scroll down to the category we are looking for and verify we can click on it
  21. 5) Scroll down to the node within the category and verify we can click on it
  22. 6) Close Script Canvas window
  23. Note:
  24. - This test file must be called from the Open 3D Engine Editor command terminal
  25. - Any passed and failed tests are written to the Editor.log file.
  26. Parsing the file or running a log_monitor are required to observe the test results.
  27. :return: None
  28. """
  29. # Pre conditions
  30. from PySide2 import QtWidgets as qtwidgets
  31. from editor_python_test_tools.utils import Report
  32. import azlmbr.legacy.general as general
  33. import pyside_utils
  34. from scripting_utils.scripting_constants import (SCRIPT_CANVAS_UI, NODE_PALETTE_UI, WAIT_TIME_3, TREE_VIEW_QT,
  35. NODE_PALETTE_QT, NODE_CATEGORY_MATH, NODE_STRING_TO_NUMBER)
  36. general.idle_enable(True)
  37. # 1) Open Script Canvas window (Tools > Script Canvas)
  38. general.open_pane(SCRIPT_CANVAS_UI)
  39. pyside_utils.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_UI), WAIT_TIME_3)
  40. # 2) Get the SC window object and get a handle on the Node Palette
  41. editor_window = pyside_utils.get_editor_main_window()
  42. sc = editor_window.findChild(qtwidgets.QDockWidget, SCRIPT_CANVAS_UI)
  43. if sc.findChild(qtwidgets.QDockWidget, NODE_PALETTE_QT) is None:
  44. action = pyside_utils.find_child_by_pattern(sc, {"text": NODE_PALETTE_UI,
  45. "type": qtwidgets.QAction})
  46. action.trigger()
  47. node_palette = sc.findChild(qtwidgets.QDockWidget, NODE_PALETTE_QT)
  48. # 3) Get a handle on the node palette's tree of nodes then expand the QTView tree object
  49. node_palette_tree_view = node_palette.findChild(qtwidgets.QTreeView, TREE_VIEW_QT)
  50. node_palette_tree_view.expandAll()
  51. # 4) Scroll down to the category we are looking for and verify we can click on it
  52. category_index = pyside_utils.find_child_by_hierarchy(node_palette_tree_view, NODE_CATEGORY_MATH)
  53. node_palette_tree_view.scrollTo(category_index)
  54. pyside_utils.item_view_index_mouse_click(node_palette_tree_view, category_index)
  55. pyside_utils.wait_for_condition(lambda: node_palette_tree_view.selectedIndexes() and
  56. (node_palette_tree_view.selectedIndexes()[0] == category_index),
  57. WAIT_TIME_3)
  58. Report.result(Tests.category_selected, node_palette_tree_view.selectedIndexes()[0] == category_index)
  59. # 5) Scroll down to the node within the category and verify we can click on it
  60. pyside_utils.find_child_by_pattern(node_palette_tree_view, NODE_STRING_TO_NUMBER)
  61. node_index = pyside_utils.find_child_by_pattern(node_palette_tree_view, NODE_STRING_TO_NUMBER)
  62. node_palette_tree_view.scrollTo(node_index)
  63. pyside_utils.item_view_index_mouse_click(node_palette_tree_view, node_index)
  64. pyside_utils.wait_for_condition(lambda: node_palette_tree_view.selectedIndexes() and
  65. (node_palette_tree_view.selectedIndexes()[0] == node_index),
  66. WAIT_TIME_3)
  67. Report.result(Tests.node_selected, node_palette_tree_view.selectedIndexes()[0] == node_index)
  68. # 6) Close Script Canvas window
  69. general.close_pane(SCRIPT_CANVAS_UI)
  70. if __name__ == "__main__":
  71. import ImportPathHelper as imports
  72. imports.init()
  73. from utils import Report
  74. Report.start_test(TestNodePaletteHappyPathCanSelectNode)