Node_HappyPath_DuplicateNode.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. from PySide2 import QtWidgets, QtTest
  7. from PySide2.QtCore import Qt
  8. from editor_python_test_tools.utils import Report
  9. from editor_python_test_tools.utils import TestHelper as helper
  10. import pyside_utils
  11. import azlmbr.legacy.general as general
  12. import scripting_utils.scripting_tools as scripting_tools
  13. from scripting_utils.scripting_constants import (SCRIPT_CANVAS_UI, NODE_INSPECTOR_QT, NODE_INSPECTOR_UI,
  14. WAIT_TIME_3, WAIT_FRAMES)
  15. COMMAND_LINE_ARGS = "add_node Print"
  16. EXPECTED_NODE_TITLE_STRING = "Print - Utilities/Debug (2 Selected)"
  17. # fmt: off
  18. class Tests:
  19. node_duplicated = ("Successfully duplicated node", "Failed to duplicate the node")
  20. # fmt: on
  21. class Node_HappyPath_DuplicateNode:
  22. """
  23. Summary:
  24. Duplicating node in graph
  25. Expected Behavior:
  26. Upon selecting a node and pressing Ctrl+D, the node will be duplicated
  27. Test Steps:
  28. 1) Open Script Canvas window (Tools > Script Canvas) and initialize Qt objects
  29. 2) Open a new graph
  30. 3) Add a node to the graph by emulating the Command Line tool's workflow
  31. 4) Duplicate nodes on graph w/ ctrl+a and ctrl+d keystroke
  32. 5) Verify the node was duplicated
  33. 6) Close Script Canvas window or else test hangs on save confirmation modal
  34. Note:
  35. - This test file must be called from the Open 3D Engine Editor command terminal
  36. - Any passed and failed tests are written to the Editor.log file.
  37. Parsing the file or running a log_monitor are required to observe the test results.
  38. :return: None
  39. """
  40. def __init__(self):
  41. self.editor_main_window = None
  42. self.sc_editor = None
  43. self.sc_editor_main_window = None
  44. self.sc_graph_view = None
  45. self.sc_graph = None
  46. def initialize_sc_graph_qt_objects(self):
  47. self.sc_graph_view = self.sc_editor.findChild(QtWidgets.QFrame, "graphicsViewFrame")
  48. self.sc_graph = self.sc_graph_view.findChild(QtWidgets.QWidget, "")
  49. # Function for entering and executing a string command in the Command Line Tool (SC > Tools > Command Line)
  50. def run_command_line_input(self, sc_editor, sc_editor_main_window, command_str):
  51. command_line_action = pyside_utils.find_child_by_pattern(
  52. sc_editor_main_window, {"objectName": "action_ViewCommandLine", "type": QtWidgets.QAction}
  53. )
  54. command_line_action.trigger()
  55. command_line_textbox = sc_editor.findChild(QtWidgets.QLineEdit, "commandText")
  56. QtTest.QTest.keyClicks(command_line_textbox, command_str)
  57. QtTest.QTest.keyClick(command_line_textbox, Qt.Key_Enter, Qt.NoModifier)
  58. @pyside_utils.wrap_async
  59. async def run_test(self):
  60. # Preconditions
  61. general.idle_enable(True)
  62. # 1) Open Script Canvas window (Tools > Script Canvas) and initialize Qt objects
  63. general.open_pane(SCRIPT_CANVAS_UI)
  64. helper.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_UI), WAIT_TIME_3)
  65. scripting_tools.initialize_editor_object(self)
  66. scripting_tools.initialize_sc_editor_objects(self)
  67. # 2) Open a new graph
  68. scripting_tools.create_new_sc_graph(self.sc_editor_main_window)
  69. # Toggle the node inspector if it's not already active
  70. sc_graph_node_inspector = scripting_tools.get_sc_editor_node_inspector(self.sc_editor)
  71. # 3) Add a node to the graph by emulating the Command Line tool's workflow
  72. self.run_command_line_input(self.sc_editor, self.sc_editor_main_window, COMMAND_LINE_ARGS)
  73. # 4) Duplicate nodes on graph w/ ctrl+a and ctrl+d keystroke
  74. self.initialize_sc_graph_qt_objects()
  75. self.sc_editor_main_window.activateWindow()
  76. QtTest.QTest.keyClick(self.sc_graph, "a", Qt.ControlModifier, WAIT_FRAMES)
  77. QtTest.QTest.keyClick(self.sc_graph, "d", Qt.ControlModifier, WAIT_FRAMES)
  78. # 5) Verify the node was duplicated
  79. # As direct interaction with node is not available the text on the label
  80. # inside the Node Inspector is validated showing two nodes exist
  81. node_titles = scripting_tools.get_node_inspector_node_titles(self, sc_graph_node_inspector, self.sc_graph)
  82. found_title = False
  83. for title in node_titles:
  84. if title == EXPECTED_NODE_TITLE_STRING:
  85. found_title = True
  86. break
  87. Report.result(Tests.node_duplicated, found_title)
  88. # 6) Close Script Canvas window or else test hangs on save confirmation modal
  89. general.close_pane(SCRIPT_CANVAS_UI)
  90. test = Node_HappyPath_DuplicateNode()
  91. test.run_test()