ScriptCanvas_TwoComponents_InteractSuccessfully.py 3.5 KB

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