ScriptCanvas_TwoComponents_InteractSuccessfully.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. class Tests:
  7. entity_created = ("New entity created", "New entity not created")
  8. game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter")
  9. game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited")
  10. lines_found = ("Expected log lines were found", "Expected log lines were not found")
  11. def ScriptCanvas_TwoComponents_InteractSuccessfully():
  12. """
  13. Summary:
  14. A test entity contains two Script Canvas components with different unique script canvas files.
  15. Each of these files will have a print node set to activate on graph start.
  16. Expected Behavior:
  17. When game mode is entered, two unique strings should be printed out to the console
  18. Test Steps:
  19. 1) Create level
  20. 2) Create entity with SC components
  21. 3) Enter game mode
  22. 4) Wait for expected lines to be found
  23. 5) Report if expected lines were found
  24. 6) Exit game mode
  25. Note:
  26. - This test file must be called from the Open 3D Engine Editor command terminal
  27. - Any passed and failed tests are written to the Editor.log file.
  28. Parsing the file or running a log_monitor are required to observe the test results.
  29. :return: None
  30. """
  31. from editor_python_test_tools.utils import TestHelper
  32. from editor_python_test_tools.utils import Report, Tracer
  33. from editor_python_test_tools.editor_entity_utils import EditorEntity
  34. from editor_python_test_tools.editor_component.editor_script_canvas import ScriptCanvasComponent
  35. import scripting_utils.scripting_tools as scripting_tools
  36. import azlmbr.legacy.general as general
  37. import os
  38. import azlmbr.paths as paths
  39. import azlmbr.math as math
  40. from scripting_utils.scripting_constants import (WAIT_TIME_3)
  41. EXPECTED_LINES = ["Greetings from the first script", "Greetings from the second script"]
  42. SOURCE_FILE_0 = os.path.join(paths.projectroot, "ScriptCanvas", "ScriptCanvas_TwoComponents0.scriptcanvas")
  43. SOURCE_FILE_1 = os.path.join(paths.projectroot, "ScriptCanvas", "ScriptCanvas_TwoComponents1.scriptcanvas")
  44. TEST_ENTITY_NAME = "test_entity"
  45. # Preconditions
  46. general.idle_enable(True)
  47. # 1) Create level
  48. TestHelper.open_level("", "Base")
  49. # 2) Create entity with SC components
  50. position = math.Vector3(512.0, 512.0, 32.0)
  51. editor_entity = EditorEntity.create_editor_entity_at(position, TEST_ENTITY_NAME)
  52. scriptcanvas_component_1 = ScriptCanvasComponent(editor_entity)
  53. scriptcanvas_component_1.set_component_graph_file_from_path(SOURCE_FILE_0)
  54. scriptcanvas_component_2 = ScriptCanvasComponent(editor_entity)
  55. scriptcanvas_component_2.set_component_graph_file_from_path(SOURCE_FILE_1)
  56. with Tracer() as section_tracer:
  57. # 3) Enter game mode
  58. TestHelper.enter_game_mode(Tests.game_mode_entered)
  59. # 4) Wait for expected lines to be found
  60. lines_located = TestHelper.wait_for_condition(
  61. lambda: scripting_tools.located_expected_tracer_lines(section_tracer, EXPECTED_LINES),
  62. WAIT_TIME_3)
  63. Report.result(Tests.lines_found, lines_located)
  64. # 5) Exit game mode
  65. TestHelper.exit_game_mode(Tests.game_mode_exited)
  66. if __name__ == "__main__":
  67. import ImportPathHelper as imports
  68. imports.init()
  69. from utils import Report
  70. Report.start_test(ScriptCanvas_TwoComponents_InteractSuccessfully)