ScriptEvents_HappyPath_SendReceiveAcrossMultiple.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. # fmt: off
  7. class Tests:
  8. enter_game_mode = ("Successfully entered game mode", "Failed to enter game mode")
  9. lines_found = ("Successfully found expected message", "Failed to find expected message")
  10. exit_game_mode = ("Successfully exited game mode", "Failed to exit game mode")
  11. # fmt: on
  12. def ScriptEvents_HappyPath_SendReceiveAcrossMultiple():
  13. """
  14. Summary:
  15. EntityA and EntityB will be created in a level. Attached to both will be a Script Canvas component.
  16. The Script Event created for the test will be sent from EntityA to EntityB.
  17. Expected Behavior:
  18. The output of the Script Event should be printed to the console
  19. Test Steps:
  20. 1) Create test level
  21. 2) Create EntityA/EntityB (add scriptcanvas files part of entity setup)
  22. 3) Enter Game Mode
  23. 4) Read for line
  24. 5) Exit Game Mode
  25. Note:
  26. - Any passed and failed tests are written to the Editor.log file.
  27. Parsing the file or running a log_monitor are required to observe the test results.
  28. :return: None
  29. """
  30. import os
  31. import azlmbr.math as math
  32. from editor_python_test_tools.editor_entity_utils import EditorEntity
  33. from editor_python_test_tools.editor_component.editor_script_canvas import ScriptCanvasComponent
  34. from editor_python_test_tools.utils import TestHelper as TestHelper
  35. from editor_python_test_tools.utils import Report, Tracer
  36. import azlmbr.legacy.general as general
  37. import azlmbr.paths as paths
  38. import scripting_utils.scripting_tools as scripting_tools
  39. from scripting_utils.scripting_constants import (WAIT_TIME_3)
  40. ASSET_PREFIX = "T92567321"
  41. asset_paths = {
  42. "event": os.path.join(paths.projectroot, "TestAssets", f"{ASSET_PREFIX}.scriptevents"),
  43. "assetA": os.path.join(paths.projectroot, "ScriptCanvas", f"{ASSET_PREFIX}A.scriptcanvas"),
  44. "assetB": os.path.join(paths.projectroot, "ScriptCanvas", f"{ASSET_PREFIX}B.scriptcanvas"),
  45. }
  46. ENTITY_NAME_FILEPATH_MAP = {"EntityA": asset_paths["assetA"], "EntityB": asset_paths["assetB"]}
  47. EXPECTED_LINES = ["Incoming Message Received"]
  48. position = math.Vector3(512.0, 512.0, 32.0)
  49. # Preconditions
  50. general.idle_enable(True)
  51. # 1) Create temp level
  52. TestHelper.open_level("", "Base")
  53. # 2) Create EntityA/EntityB
  54. for key_name in ENTITY_NAME_FILEPATH_MAP.keys():
  55. editor_entity = EditorEntity.create_editor_entity_at(position, key_name)
  56. scriptcanvas_component = ScriptCanvasComponent(editor_entity)
  57. scriptcanvas_component.set_component_graph_file_from_path(ENTITY_NAME_FILEPATH_MAP[key_name])
  58. TestHelper.wait_for_condition(lambda: editor_entity is not None, WAIT_TIME_3)
  59. with Tracer() as section_tracer:
  60. # 3) Enter Game Mode
  61. TestHelper.enter_game_mode(Tests.enter_game_mode)
  62. # 4) Read for line
  63. lines_located = TestHelper.wait_for_condition(
  64. lambda: scripting_tools.located_expected_tracer_lines(section_tracer, EXPECTED_LINES), WAIT_TIME_3)
  65. Report.result(Tests.lines_found, lines_located)
  66. # 5) Exit Game Mode
  67. TestHelper.exit_game_mode(Tests.exit_game_mode)
  68. if __name__ == "__main__":
  69. import ImportPathHelper as imports
  70. imports.init()
  71. from utils import Report
  72. Report.start_test(ScriptEvents_HappyPath_SendReceiveAcrossMultiple)