NewScriptEventButton_HappyPath_ContainsSCCategory.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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
  7. from editor_python_test_tools.utils import TestHelper as helper
  8. from editor_python_test_tools.utils import Report
  9. import azlmbr.legacy.general as general
  10. import pyside_utils
  11. from scripting_utils.scripting_constants import WAIT_TIME_3, SCRIPT_CANVAS_UI, ASSET_EDITOR_UI, NODE_PALETTE_QT
  12. class Tests:
  13. action_found = "New Script event action found"
  14. asset_editor_opened = "Asset Editor opened"
  15. new_asset = "Asset Editor created with new asset"
  16. script_event = "New Script event created in Asset Editor"
  17. class TestAssetEditor_NewScriptEvent:
  18. """
  19. Summary:
  20. Verifying logic flow of the "+" button on the Script Canvas pane's Node Palette is as expected
  21. Expected Behavior:
  22. Clicking the "+" button and selecting "New Script Event" opens the Asset Editor with a new Script Event asset
  23. Test Steps:
  24. 1) Open Script Canvas window (Tools > Script Canvas)
  25. 2) Close any existing AssetEditor window
  26. 3) Get the SC window object
  27. 4) Click on New Script Event on Node palette
  28. 5) Verify if Asset Editor opened
  29. 6) Verify if a new asset with Script Canvas category is opened
  30. 7) Close Script Canvas and Asset Editor
  31. Note:
  32. - This test file must be called from the Open 3D Engine Editor command terminal
  33. - Any passed and failed tests are written to the Editor.log file.
  34. Parsing the file or running a log_monitor are required to observe the test results.
  35. :return: None
  36. """
  37. @pyside_utils.wrap_async
  38. async def run_test(self):
  39. # 1) Open Script Canvas window (Tools > Script Canvas)
  40. general.idle_enable(True)
  41. general.open_pane(SCRIPT_CANVAS_UI)
  42. helper.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_UI), WAIT_TIME_3)
  43. # 2) Close any existing AssetEditor window
  44. general.close_pane(ASSET_EDITOR_UI)
  45. helper.wait_for_condition(lambda: not general.is_pane_visible(ASSET_EDITOR_UI), WAIT_TIME_3)
  46. # 3) Get the SC window object
  47. editor_window = pyside_utils.get_editor_main_window()
  48. sc = editor_window.findChild(QtWidgets.QDockWidget, SCRIPT_CANVAS_UI)
  49. node_palette = sc.findChild(QtWidgets.QDockWidget, NODE_PALETTE_QT)
  50. frame = node_palette.findChild(QtWidgets.QFrame, "searchCustomization")
  51. button = frame.findChild(QtWidgets.QToolButton)
  52. pyside_utils.click_button_async(button)
  53. # 4) Click on New Script Event on Node palette
  54. menu = None
  55. def menu_has_focus():
  56. nonlocal menu
  57. for focused_window in [
  58. QtWidgets.QApplication.activePopupWidget(),
  59. QtWidgets.QApplication.activeModalWidget(),
  60. QtWidgets.QApplication.focusWidget(),
  61. QtWidgets.QApplication.activeWindow(),
  62. ]:
  63. if focused_window and isinstance(focused_window, QtWidgets.QMenu) and focused_window.isVisible():
  64. menu = focused_window
  65. return True
  66. return False
  67. await pyside_utils.wait_for_condition(menu_has_focus, WAIT_TIME_3)
  68. action = await pyside_utils.wait_for_action_in_menu(menu, {"text": "New Script Event"})
  69. Report.info(f"{Tests.action_found}: {action is not None}")
  70. action.trigger()
  71. pyside_utils.queue_hide_event(menu)
  72. # 5) Verify if Asset Editor opened
  73. result = helper.wait_for_condition(lambda: general.is_pane_visible(ASSET_EDITOR_UI), WAIT_TIME_3)
  74. Report.info(f"{Tests.asset_editor_opened}: {result}")
  75. # 6) Verify if a new asset with Script Canvas category is opened
  76. asset_editor = editor_window.findChild(QtWidgets.QDockWidget, ASSET_EDITOR_UI)
  77. row_container = asset_editor.findChild(QtWidgets.QWidget, "ContainerForRows")
  78. # NOTE: QWidget ContainerForRows will have frames of Name, Category, ToolTip etc.
  79. # To validate if a new script event file is generated, we check for
  80. # QFrame Category and its value.
  81. # Order of objects in container not guaranteed!
  82. categories = row_container.findChildren(QtWidgets.QFrame, "Category")
  83. Report.info(f"{Tests.new_asset}: {len(categories)>0}")
  84. result = False
  85. for frame in categories:
  86. line_edit = frame.findChild(QtWidgets.QLineEdit)
  87. if line_edit and line_edit.text() == "Script Events":
  88. result = True
  89. break
  90. Report.info(f"{Tests.script_event}: {result}")
  91. # 7) Close Script Canvas and Asset Editor
  92. general.close_pane(SCRIPT_CANVAS_UI)
  93. general.close_pane(ASSET_EDITOR_UI)
  94. test = TestAssetEditor_NewScriptEvent()
  95. test.run_test()