ScriptEvents_HappyPath_SendReceiveAcrossMultiple.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. import os
  7. from editor_python_test_tools.utils import TestHelper as helper
  8. from editor_python_test_tools.utils import Report, Tracer
  9. import pyside_utils
  10. import azlmbr.legacy.general as general
  11. import editor_python_test_tools.hydra_editor_utils as hydra
  12. import azlmbr.paths as paths
  13. import scripting_utils.scripting_tools as scripting_tools
  14. from scripting_utils.scripting_constants import (WAIT_TIME_3, BASE_LEVEL_NAME)
  15. # fmt: off
  16. class Tests:
  17. entity_created = ("Successfully created Entity", "Failed to create Entity")
  18. enter_game_mode = ("Successfully entered game mode", "Failed to enter game mode")
  19. lines_found = ("Successfully found expected message", "Failed to find expected message")
  20. exit_game_mode = ("Successfully exited game mode", "Failed to exit game mode")
  21. # fmt: on
  22. ASSET_PREFIX = "T92567321"
  23. asset_paths = {
  24. "event": os.path.join(paths.projectroot, "TestAssets", f"{ASSET_PREFIX}.scriptevents"),
  25. "assetA": os.path.join(paths.projectroot, "ScriptCanvas", f"{ASSET_PREFIX}A.scriptcanvas"),
  26. "assetB": os.path.join(paths.projectroot, "ScriptCanvas", f"{ASSET_PREFIX}B.scriptcanvas"),
  27. }
  28. ENTITY_NAME_FILEPATH_MAP = {"EntityA": asset_paths["assetA"], "EntityB": asset_paths["assetB"]}
  29. EXPECTED_LINES = ["Incoming Message Received"]
  30. class ScriptEvents_HappyPath_SendReceiveAcrossMultiple:
  31. """
  32. Summary:
  33. EntityA and EntityB will be created in a level. Attached to both will be a Script Canvas component.
  34. The Script Event created for the test will be sent from EntityA to EntityB.
  35. Expected Behavior:
  36. The output of the Script Event should be printed to the console
  37. Test Steps:
  38. 1) Create test level
  39. 2) Create EntityA/EntityB (add scriptcanvas files part of entity setup)
  40. 3) Enter Game Mode
  41. 4) Read for line
  42. 5) Exit Game Mode
  43. Note:
  44. - This test file must be called from the Open 3D Engine Editor command terminal
  45. - Any passed and failed tests are written to the Editor.log file.
  46. Parsing the file or running a log_monitor are required to observe the test results.
  47. :return: None
  48. """
  49. def __init__(self):
  50. editor_window = None
  51. @pyside_utils.wrap_async
  52. async def run_test(self):
  53. # Preconditions
  54. general.idle_enable(True)
  55. # 1) Create temp level
  56. hydra.open_base_level()
  57. helper.wait_for_condition(lambda: general.get_current_level_name() == BASE_LEVEL_NAME, WAIT_TIME_3)
  58. general.close_pane("Error Report")
  59. # 2) Create EntityA/EntityB
  60. for key_name in ENTITY_NAME_FILEPATH_MAP.keys():
  61. entity = scripting_tools.create_entity_with_sc_component_asset(key_name, ENTITY_NAME_FILEPATH_MAP[key_name])
  62. helper.wait_for_condition(lambda: entity is not None, WAIT_TIME_3)
  63. Report.critical_result(Tests.entity_created, entity.id.isValid())
  64. with Tracer() as section_tracer:
  65. # 3) Enter Game Mode
  66. helper.enter_game_mode(Tests.enter_game_mode)
  67. # 4) Read for line
  68. lines_located = helper.wait_for_condition(
  69. lambda: scripting_tools.located_expected_tracer_lines(self, section_tracer, EXPECTED_LINES), WAIT_TIME_3)
  70. Report.result(Tests.lines_found, lines_located)
  71. # 5) Exit Game Mode
  72. helper.exit_game_mode(Tests.exit_game_mode)
  73. test = ScriptEvents_HappyPath_SendReceiveAcrossMultiple()
  74. test.run_test()