VariableManager_Default_CreateDeleteVars.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, QtCore
  7. from editor_python_test_tools.utils import TestHelper as helper
  8. from editor_python_test_tools.utils import Report
  9. from scripting_utils.scripting_constants import (WAIT_TIME_3, SCRIPT_CANVAS_UI, VARIABLE_MANAGER_UI,
  10. VARIABLE_MANAGER_QT, VARIABLE_PALETTE_QT, GRAPH_VARIABLES_QT,
  11. ADD_BUTTON_QT, VARIABLE_TYPES)
  12. import azlmbr.legacy.general as general
  13. import pyside_utils
  14. class VariableManager_Default_CreateDeleteVars:
  15. """
  16. Summary:
  17. Creating and deleting each type of variable in the Variable Manager pane
  18. Expected Behavior:
  19. Each variable type can be created and deleted in variable manager.
  20. Test Steps:
  21. 1) Open Script Canvas window (Tools > Script Canvas)
  22. 2) Get the SC window object
  23. 3) Open Variable Manager if not opened already
  24. 4) Create Graph
  25. 5) Create variable of each type and verify if it is created
  26. 6) Delete each type of variable and verify if it is deleted
  27. 7) Close SC window
  28. Note:
  29. - This test file must be called from the Open 3D Engine Editor command terminal
  30. - Any passed and failed tests are written to the Editor.log file.
  31. Parsing the file or running a log_monitor are required to observe the test results.
  32. :return: None
  33. """
  34. @staticmethod
  35. def generate_variable_test_output(var_type, action):
  36. return f"{var_type} variable is {action}d"
  37. @pyside_utils.wrap_async
  38. async def run_test(self):
  39. # Preconditions
  40. general.idle_enable(True)
  41. # 1) Open Script Canvas window
  42. general.open_pane(SCRIPT_CANVAS_UI)
  43. helper.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_UI), WAIT_TIME_3)
  44. # 2) Get the SC window object
  45. editor_window = pyside_utils.get_editor_main_window()
  46. sc = editor_window.findChild(QtWidgets.QDockWidget, SCRIPT_CANVAS_UI)
  47. # 3) Open Variable Manager if not opened already
  48. if sc.findChild(QtWidgets.QDockWidget, VARIABLE_MANAGER_QT) is None:
  49. action = pyside_utils.find_child_by_pattern(sc, {"text": VARIABLE_MANAGER_UI, "type": QtWidgets.QAction})
  50. action.trigger()
  51. variable_manager = sc.findChild(QtWidgets.QDockWidget, VARIABLE_MANAGER_QT)
  52. # 4) Create Graph
  53. action = pyside_utils.find_child_by_pattern(sc, {"objectName": "action_New_Script", "type": QtWidgets.QAction})
  54. action.trigger()
  55. # Keep a handle of the created variables for verification
  56. graph_vars = variable_manager.findChild(QtWidgets.QTableView, GRAPH_VARIABLES_QT)
  57. # 5) Create variable_type of each type and verify if it is created
  58. for index, variable_type in enumerate(VARIABLE_TYPES):
  59. # Create new variable_type button
  60. add_button = variable_manager.findChild(QtWidgets.QPushButton, ADD_BUTTON_QT)
  61. # Click on Create Variable button and wait for it to render
  62. add_button.click()
  63. helper.wait_for_condition((
  64. lambda: variable_manager.findChild(QtWidgets.QTableView, VARIABLE_PALETTE_QT) is not None), WAIT_TIME_3)
  65. # Find the variable_type option in the rendered table and click on it
  66. table_view = variable_manager.findChild(QtWidgets.QTableView, VARIABLE_PALETTE_QT)
  67. model_index = pyside_utils.find_child_by_pattern(table_view, variable_type)
  68. pyside_utils.item_view_index_mouse_click(table_view, model_index)
  69. # Verify number of created variables in list and new variable's type
  70. row_count_increased = helper.wait_for_condition(lambda: graph_vars.model().rowCount(QtCore.QModelIndex()) == (
  71. index + 1), WAIT_TIME_3)
  72. new_var_entry = pyside_utils.find_child_by_pattern(graph_vars, f"Variable {index+1}")
  73. new_var_type = new_var_entry.siblingAtColumn(1).data(QtCore.Qt.DisplayRole)
  74. result = row_count_increased and (new_var_entry is not None) and (new_var_type == variable_type)
  75. test_output = self.generate_variable_test_output(variable_type, "create")
  76. Report.info(f"{test_output}: {result}")
  77. # 6) Delete each type of variable_type and verify if it is deleted
  78. for index, variable_type in enumerate(VARIABLE_TYPES):
  79. var_entry = pyside_utils.find_child_by_pattern(graph_vars, f"Variable {index+1}")
  80. pyside_utils.item_view_index_mouse_click(graph_vars, var_entry)
  81. QtTest.QTest.keyClick(graph_vars, QtCore.Qt.Key_Delete, QtCore.Qt.NoModifier)
  82. result = graph_vars.model().rowCount(QtCore.QModelIndex()) == (len(VARIABLE_TYPES) - (index + 1))
  83. test_output = self.generate_variable_test_output(variable_type, "delete")
  84. Report.info(f"{test_output}: {result}")
  85. # 7) Close SC window
  86. general.close_pane(SCRIPT_CANVAS_UI)
  87. test = VariableManager_Default_CreateDeleteVars()
  88. test.run_test()