From 779edb7fe5fd54ab67c1acb2439522a5c13eded4 Mon Sep 17 00:00:00 2001 From: kritin Date: Thu, 30 Sep 2021 16:43:15 -0700 Subject: [PATCH 1/4] Sample Editor test for QA Automation project Signed-off-by: kritin --- .../EditorScripts/Sample_Editor_Tests.py | 143 ++++++++++++++++++ .../editor/TestSuite_Main_Optimized.py | 3 + 2 files changed, 146 insertions(+) create mode 100644 AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py diff --git a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py new file mode 100644 index 0000000000..746c0a936d --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py @@ -0,0 +1,143 @@ +""" +Copyright (c) Contributors to the Open 3D Engine Project. +For complete copyright and license terms please see the LICENSE at the root of this distribution. + +SPDX-License-Identifier: Apache-2.0 OR MIT + +Test Case: Creating tests for basic editor feature like creating a level, adding new entities, modifying the entities etc. +""" + + +class Tests: + create_level = ("Level created and loaded successfully", "Failed to create the level") + open_level = ("Level loaded successfully", "Failed to load the level") + create_entity = ("Parent entity created successfully", "Failed to create a parent entity") + set_entity_name = ("Entity name set successfully", "Failed to set entity name") + delete_entity = ("Parent entity deleted successfully", "Failed to delete parent entity") + game_mode_enter = ("Game Mode entered successfully", "Failed to enter the game mode") + game_mode_exit = ("Game mode exited successfully", "Failed to exit game mode") + create_child_entity = ("Child entity created successfully", "Failed to create a child entity") + delete_child_entity = ("Child entity deleted successfully", "Failed to delete child entity") + add_mesh_component = ("Mesh component added successfully", "Failed to add mesh component") + found_component_typeId = ("Found component typeId", "Unable to find component TypeId") + remove_mesh_component = ("Mesh component removed successfully", "Failed to remove mesh component") + + +def sample_editor_tests(): + """ + Performing basic test in editor + 01. create_level if it does not exist else 02. open exiting level + + 03. create parent entity and set name + 04. create child entity + 05. delete child entity + 06. add mesh component + 07. remove mesh component + 08. enter game mode + 09. exit game_mode + 10. delete parent entity + 11. save level + + """ + import os + from editor_python_test_tools.utils import Report + from editor_python_test_tools.utils import TestHelper as helper + import editor_python_test_tools.hydra_editor_utils as hydra + + import azlmbr.math as math + import azlmbr.asset as asset + import azlmbr.bus as bus + import azlmbr.editor as editor + import azlmbr.entity as entity + import azlmbr.legacy.general as general + import azlmbr.object + + def search_entity(entity_to_search, entity_name): + """ + + :param entity_to_search: entity to be searched + :param entity_name: name of the entity used in the set command + :return: True if entity id exists in the entity_list + False if entity id does not exist in the entity_list + """ + entity_list = [] + entity_search_filter = entity.SearchFilter() + entity_search_filter.names = entity_name + entity_list = entity.SearchBus(bus.Broadcast, 'SearchEntities', entity_search_filter) + if entity_list: + if entity_to_search in entity_list: + return True + return False + return False + + # 01. create_level + + test_level = 'Simple' + general.open_level_no_prompt(test_level) + Report.result(Tests.create_level, general.get_current_level_name() == test_level) + + # 02. load existing level - skipping this since this could alter existing level that other test depends on + + # 03. create_entity and set name + # Delete any exiting entity and Create a new Entity at the root level + search_filter = azlmbr.entity.SearchFilter() + all_entities = entity.SearchBus(azlmbr.bus.Broadcast, "SearchEntities", search_filter) + editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntities", all_entities) + parent_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, "CreateNewEntity", entity.EntityId()) + Report.result(Tests.create_entity, parent_entity.IsValid()) + + # Setting a new name + parent_entity_name = "Parent_1" + editor.EditorEntityAPIBus(bus.Event, 'SetName', parent_entity, parent_entity_name) + Report.result(Tests.set_entity_name, + editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', parent_entity) == parent_entity_name) + + # 04. Creating child Entity and setting name to above created parent entity + child_1_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', parent_entity) + Report.result(Tests.create_child_entity, child_1_entity.IsValid()) + child_entity_name = "Child_1" + editor.EditorEntityAPIBus(bus.Event, 'SetName', child_1_entity, child_entity_name) + Report.result(Tests.set_entity_name, + editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', child_1_entity) == child_entity_name) + + # 05. delete_Child_entity + editor.ToolsApplicationRequestBus(bus.Broadcast, 'DeleteEntityById', child_1_entity) + Report.result(Tests.delete_entity, search_entity(child_1_entity, "Child_1") == False) + + # 06. add mesh component to parent entity + type_id_list = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Mesh"], + entity.EntityType().Game) + if type_id_list is not None: + component_outcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', parent_entity, + type_id_list) + Report.result(Tests.add_mesh_component, component_outcome.IsSuccess()) + else: + Report.result(Tests.found_component_typeId, type_id_list is not None) + + # 09. remove mesh component + outcome_get_component = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', parent_entity, + type_id_list[0]) + if outcome_get_component.IsSuccess(): + component_entity_pair = outcome_get_component.GetValue() + editor.EditorComponentAPIBus(bus.Broadcast, 'RemoveComponents', [component_entity_pair]) + component_exists = editor.EditorComponentAPIBus(bus.Broadcast, 'HasComponentOfType', parent_entity, + type_id_list[0]) + mesh_test = True + if component_exists: + mesh_test = False + Report.result(Tests.remove_mesh_component, mesh_test) + else: + Report.result(Tests.found_component_typeId, outcome_get_component.IsSuccess()) + + # 10. delete parent entity + editor.ToolsApplicationRequestBus(azlmbr.bus.Broadcast, 'DeleteEntityById', parent_entity) + Report.result(Tests.delete_entity, search_entity(parent_entity, "Parent_1") == False) + + # Close editor without saving + editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') + + +if __name__ == "__main__": + from editor_python_test_tools.utils import Report + + Report.start_test(sample_editor_tests) diff --git a/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py b/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py index 9c0b99daff..9aef8a8b2c 100644 --- a/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py +++ b/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py @@ -73,3 +73,6 @@ class TestAutomationAutoTestMode(EditorTestSuite): @pytest.mark.skip(reason="Times out due to dialogs failing to dismiss: LYN-4208") class test_Menus_FileMenuOptions_Work(EditorSharedTest): from .EditorScripts import Menus_FileMenuOptions as test_module + + class test_Sample_Editor_Tests(EditorSharedTest): + from .EditorScripts import Sample_Editor_Tests as test_module \ No newline at end of file From b7e3a63faea416a22ba8f3a7d13dc22728bfd64a Mon Sep 17 00:00:00 2001 From: kritin Date: Mon, 4 Oct 2021 23:18:31 -0700 Subject: [PATCH 2/4] responded to code reviews Signed-off-by: kritin --- ...flows_ExistingLevel_EntityComponentCRUD.py | 159 ++++++++++++++++++ .../editor/TestSuite_Main_Optimized.py | 3 +- 2 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py diff --git a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py new file mode 100644 index 0000000000..451b3a6714 --- /dev/null +++ b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py @@ -0,0 +1,159 @@ +""" +Copyright (c) Contributors to the Open 3D Engine Project. +For complete copyright and license terms please see the LICENSE at the root of this distribution. + +SPDX-License-Identifier: Apache-2.0 OR MIT +""" + + +class Tests: + load_level = ( + "Level loaded successfully", + "Failed to load the level" + ) + create_entity = ( + "Parent entity created successfully", + "Failed to create a parent entity" + ) + set_entity_name = ( + "Entity name set successfully", + "Failed to set entity name" + ) + delete_entity = ( + "Parent Entity deleted successfully", + "Failed to delete parent entity" + ) + create_child_entity = ( + "Child entity created successfully", + "Failed to create a child entity" + ) + delete_child_entity = ( + "Child entity deleted successfully", + "Failed to delete child entity" + ) + add_mesh_component = ( + "Mesh component added successfully", + "Failed to add mesh component" + ) + found_component_typeId = ( + "Found component typeId", + "Unable to find component TypeId" + ) + remove_mesh_component = ( + "Mesh component removed successfully", + "Failed to remove mesh component" + ) + + +def BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD(): + """ + Performing basic test in editor + 01. Load exiting level + 02. create parent entity and set name + 03. create child entity and set a name + 04. delete child entity + 05. add mesh component to parent entity + 06. remove mesh component + 07. delete parent entity + Close editor without saving + """ + import os + from editor_python_test_tools.utils import Report + from editor_python_test_tools.utils import TestHelper as helper + import editor_python_test_tools.hydra_editor_utils as hydra + + import azlmbr.math as math + import azlmbr.asset as asset + import azlmbr.bus as bus + import azlmbr.editor as editor + import azlmbr.entity as entity + import azlmbr.legacy.general as general + import azlmbr.object + + def search_entity(entity_to_search, entity_name): + """ + + :param entity_to_search: entity to be searched + :param entity_name: name of the entity used in the set command + :return: True if entity id exists in the entity_list + False if entity id does not exist in the entity_list + """ + entity_list = [] + entity_search_filter = entity.SearchFilter() + entity_search_filter.names = entity_name + entity_list = entity.SearchBus(bus.Broadcast, 'SearchEntities', entity_search_filter) + if entity_list: + if entity_to_search in entity_list: + return True + return False + return False + + # 01. load an existing level + + test_level = 'Simple' + general.open_level_no_prompt(test_level) + Report.result(Tests.load_level, general.get_current_level_name() == test_level) + + # 02. create parent entity and set name + # Delete any exiting entity and Create a new Entity at the root level + search_filter = azlmbr.entity.SearchFilter() + all_entities = entity.SearchBus(azlmbr.bus.Broadcast, "SearchEntities", search_filter) + editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntities", all_entities) + parent_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, "CreateNewEntity", entity.EntityId()) + Report.result(Tests.create_entity, parent_entity.IsValid()) + + # Setting a new name + parent_entity_name = "Parent_1" + editor.EditorEntityAPIBus(bus.Event, 'SetName', parent_entity, parent_entity_name) + Report.result(Tests.set_entity_name, + editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', parent_entity) == parent_entity_name) + + # 03. Create child Entity to above created parent entity and set a name + child_1_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', parent_entity) + Report.result(Tests.create_child_entity, child_1_entity.IsValid()) + child_entity_name = "Child_1" + editor.EditorEntityAPIBus(bus.Event, 'SetName', child_1_entity, child_entity_name) + Report.result(Tests.set_entity_name, + editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', child_1_entity) == child_entity_name) + + # 04. delete_Child_entity + editor.ToolsApplicationRequestBus(bus.Broadcast, 'DeleteEntityById', child_1_entity) + Report.result(Tests.delete_child_entity, search_entity(child_1_entity, "Child_1") == False) + + # 05. add mesh component to parent entity + type_id_list = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Mesh"], + entity.EntityType().Game) + if type_id_list is not None: + component_outcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', parent_entity, + type_id_list) + Report.result(Tests.add_mesh_component, component_outcome.IsSuccess()) + else: + Report.result(Tests.found_component_typeId, type_id_list is not None) + + # 06. remove mesh component + outcome_get_component = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', parent_entity, + type_id_list[0]) + if outcome_get_component.IsSuccess(): + component_entity_pair = outcome_get_component.GetValue() + editor.EditorComponentAPIBus(bus.Broadcast, 'RemoveComponents', [component_entity_pair]) + component_exists = editor.EditorComponentAPIBus(bus.Broadcast, 'HasComponentOfType', parent_entity, + type_id_list[0]) + mesh_test = True + if component_exists: + mesh_test = False + Report.result(Tests.remove_mesh_component, mesh_test) + else: + Report.result(Tests.found_component_typeId, outcome_get_component.IsSuccess()) + + # 7. delete parent entity + editor.ToolsApplicationRequestBus(azlmbr.bus.Broadcast, 'DeleteEntityById', parent_entity) + Report.result(Tests.delete_entity, search_entity(parent_entity, "Parent_1") == False) + + # Close editor without saving + editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') + + +if __name__ == "__main__": + from editor_python_test_tools.utils import Report + + Report.start_test(BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD) diff --git a/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py b/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py index 9aef8a8b2c..755f75216b 100644 --- a/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py +++ b/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py @@ -73,6 +73,7 @@ class TestAutomationAutoTestMode(EditorTestSuite): @pytest.mark.skip(reason="Times out due to dialogs failing to dismiss: LYN-4208") class test_Menus_FileMenuOptions_Work(EditorSharedTest): from .EditorScripts import Menus_FileMenuOptions as test_module + class test_Sample_Editor_Tests(EditorSharedTest): - from .EditorScripts import Sample_Editor_Tests as test_module \ No newline at end of file + from .EditorScripts import BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD as test_module From f1fe2912e45ba6e493ba0fee3e6edd4876ccfc20 Mon Sep 17 00:00:00 2001 From: kritin Date: Tue, 5 Oct 2021 14:54:07 -0700 Subject: [PATCH 3/4] responded to code reviews Signed-off-by: kritin --- ...flows_ExistingLevel_EntityComponentCRUD.py | 82 +++------- .../EditorScripts/Sample_Editor_Tests.py | 143 ------------------ .../editor/TestSuite_Main_Optimized.py | 2 +- 3 files changed, 21 insertions(+), 206 deletions(-) delete mode 100644 AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py diff --git a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py index 451b3a6714..803b9e9a11 100644 --- a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py +++ b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py @@ -53,40 +53,19 @@ def BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD(): 03. create child entity and set a name 04. delete child entity 05. add mesh component to parent entity - 06. remove mesh component 07. delete parent entity Close editor without saving """ import os from editor_python_test_tools.utils import Report - from editor_python_test_tools.utils import TestHelper as helper - import editor_python_test_tools.hydra_editor_utils as hydra + from editor_python_test_tools.editor_entity_utils import EditorEntity - import azlmbr.math as math - import azlmbr.asset as asset import azlmbr.bus as bus import azlmbr.editor as editor import azlmbr.entity as entity import azlmbr.legacy.general as general import azlmbr.object - def search_entity(entity_to_search, entity_name): - """ - - :param entity_to_search: entity to be searched - :param entity_name: name of the entity used in the set command - :return: True if entity id exists in the entity_list - False if entity id does not exist in the entity_list - """ - entity_list = [] - entity_search_filter = entity.SearchFilter() - entity_search_filter.names = entity_name - entity_list = entity.SearchBus(bus.Broadcast, 'SearchEntities', entity_search_filter) - if entity_list: - if entity_to_search in entity_list: - return True - return False - return False # 01. load an existing level @@ -94,60 +73,39 @@ def BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD(): general.open_level_no_prompt(test_level) Report.result(Tests.load_level, general.get_current_level_name() == test_level) + # 02. create parent entity and set name # Delete any exiting entity and Create a new Entity at the root level + search_filter = azlmbr.entity.SearchFilter() all_entities = entity.SearchBus(azlmbr.bus.Broadcast, "SearchEntities", search_filter) editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntities", all_entities) - parent_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, "CreateNewEntity", entity.EntityId()) - Report.result(Tests.create_entity, parent_entity.IsValid()) + parent_entity = EditorEntity.create_editor_entity("Parent_1") + Report.result(Tests.create_entity, parent_entity.exists()) - # Setting a new name - parent_entity_name = "Parent_1" - editor.EditorEntityAPIBus(bus.Event, 'SetName', parent_entity, parent_entity_name) - Report.result(Tests.set_entity_name, - editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', parent_entity) == parent_entity_name) # 03. Create child Entity to above created parent entity and set a name - child_1_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', parent_entity) - Report.result(Tests.create_child_entity, child_1_entity.IsValid()) - child_entity_name = "Child_1" - editor.EditorEntityAPIBus(bus.Event, 'SetName', child_1_entity, child_entity_name) - Report.result(Tests.set_entity_name, - editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', child_1_entity) == child_entity_name) + + child_1_entity = EditorEntity.create_editor_entity("Child_1", parent_entity.id ) + Report.result(Tests.create_child_entity, child_1_entity.exists()) + # 04. delete_Child_entity - editor.ToolsApplicationRequestBus(bus.Broadcast, 'DeleteEntityById', child_1_entity) - Report.result(Tests.delete_child_entity, search_entity(child_1_entity, "Child_1") == False) + + child_1_entity.delete() + Report.result(Tests.delete_child_entity, not child_1_entity.exists()) + # 05. add mesh component to parent entity - type_id_list = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Mesh"], - entity.EntityType().Game) - if type_id_list is not None: - component_outcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', parent_entity, - type_id_list) - Report.result(Tests.add_mesh_component, component_outcome.IsSuccess()) - else: - Report.result(Tests.found_component_typeId, type_id_list is not None) - - # 06. remove mesh component - outcome_get_component = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', parent_entity, - type_id_list[0]) - if outcome_get_component.IsSuccess(): - component_entity_pair = outcome_get_component.GetValue() - editor.EditorComponentAPIBus(bus.Broadcast, 'RemoveComponents', [component_entity_pair]) - component_exists = editor.EditorComponentAPIBus(bus.Broadcast, 'HasComponentOfType', parent_entity, - type_id_list[0]) - mesh_test = True - if component_exists: - mesh_test = False - Report.result(Tests.remove_mesh_component, mesh_test) - else: - Report.result(Tests.found_component_typeId, outcome_get_component.IsSuccess()) + + parent_entity.add_component("Mesh") + Report.result(Tests.add_mesh_component, parent_entity.has_component("Mesh")) + # 7. delete parent entity - editor.ToolsApplicationRequestBus(azlmbr.bus.Broadcast, 'DeleteEntityById', parent_entity) - Report.result(Tests.delete_entity, search_entity(parent_entity, "Parent_1") == False) + + parent_entity.delete() + Report.result(Tests.delete_entity, not parent_entity.exists()) # Close editor without saving editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') diff --git a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py deleted file mode 100644 index 746c0a936d..0000000000 --- a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Sample_Editor_Tests.py +++ /dev/null @@ -1,143 +0,0 @@ -""" -Copyright (c) Contributors to the Open 3D Engine Project. -For complete copyright and license terms please see the LICENSE at the root of this distribution. - -SPDX-License-Identifier: Apache-2.0 OR MIT - -Test Case: Creating tests for basic editor feature like creating a level, adding new entities, modifying the entities etc. -""" - - -class Tests: - create_level = ("Level created and loaded successfully", "Failed to create the level") - open_level = ("Level loaded successfully", "Failed to load the level") - create_entity = ("Parent entity created successfully", "Failed to create a parent entity") - set_entity_name = ("Entity name set successfully", "Failed to set entity name") - delete_entity = ("Parent entity deleted successfully", "Failed to delete parent entity") - game_mode_enter = ("Game Mode entered successfully", "Failed to enter the game mode") - game_mode_exit = ("Game mode exited successfully", "Failed to exit game mode") - create_child_entity = ("Child entity created successfully", "Failed to create a child entity") - delete_child_entity = ("Child entity deleted successfully", "Failed to delete child entity") - add_mesh_component = ("Mesh component added successfully", "Failed to add mesh component") - found_component_typeId = ("Found component typeId", "Unable to find component TypeId") - remove_mesh_component = ("Mesh component removed successfully", "Failed to remove mesh component") - - -def sample_editor_tests(): - """ - Performing basic test in editor - 01. create_level if it does not exist else 02. open exiting level - - 03. create parent entity and set name - 04. create child entity - 05. delete child entity - 06. add mesh component - 07. remove mesh component - 08. enter game mode - 09. exit game_mode - 10. delete parent entity - 11. save level - - """ - import os - from editor_python_test_tools.utils import Report - from editor_python_test_tools.utils import TestHelper as helper - import editor_python_test_tools.hydra_editor_utils as hydra - - import azlmbr.math as math - import azlmbr.asset as asset - import azlmbr.bus as bus - import azlmbr.editor as editor - import azlmbr.entity as entity - import azlmbr.legacy.general as general - import azlmbr.object - - def search_entity(entity_to_search, entity_name): - """ - - :param entity_to_search: entity to be searched - :param entity_name: name of the entity used in the set command - :return: True if entity id exists in the entity_list - False if entity id does not exist in the entity_list - """ - entity_list = [] - entity_search_filter = entity.SearchFilter() - entity_search_filter.names = entity_name - entity_list = entity.SearchBus(bus.Broadcast, 'SearchEntities', entity_search_filter) - if entity_list: - if entity_to_search in entity_list: - return True - return False - return False - - # 01. create_level - - test_level = 'Simple' - general.open_level_no_prompt(test_level) - Report.result(Tests.create_level, general.get_current_level_name() == test_level) - - # 02. load existing level - skipping this since this could alter existing level that other test depends on - - # 03. create_entity and set name - # Delete any exiting entity and Create a new Entity at the root level - search_filter = azlmbr.entity.SearchFilter() - all_entities = entity.SearchBus(azlmbr.bus.Broadcast, "SearchEntities", search_filter) - editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntities", all_entities) - parent_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, "CreateNewEntity", entity.EntityId()) - Report.result(Tests.create_entity, parent_entity.IsValid()) - - # Setting a new name - parent_entity_name = "Parent_1" - editor.EditorEntityAPIBus(bus.Event, 'SetName', parent_entity, parent_entity_name) - Report.result(Tests.set_entity_name, - editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', parent_entity) == parent_entity_name) - - # 04. Creating child Entity and setting name to above created parent entity - child_1_entity = editor.ToolsApplicationRequestBus(bus.Broadcast, 'CreateNewEntity', parent_entity) - Report.result(Tests.create_child_entity, child_1_entity.IsValid()) - child_entity_name = "Child_1" - editor.EditorEntityAPIBus(bus.Event, 'SetName', child_1_entity, child_entity_name) - Report.result(Tests.set_entity_name, - editor.EditorEntityInfoRequestBus(bus.Event, 'GetName', child_1_entity) == child_entity_name) - - # 05. delete_Child_entity - editor.ToolsApplicationRequestBus(bus.Broadcast, 'DeleteEntityById', child_1_entity) - Report.result(Tests.delete_entity, search_entity(child_1_entity, "Child_1") == False) - - # 06. add mesh component to parent entity - type_id_list = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', ["Mesh"], - entity.EntityType().Game) - if type_id_list is not None: - component_outcome = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', parent_entity, - type_id_list) - Report.result(Tests.add_mesh_component, component_outcome.IsSuccess()) - else: - Report.result(Tests.found_component_typeId, type_id_list is not None) - - # 09. remove mesh component - outcome_get_component = editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', parent_entity, - type_id_list[0]) - if outcome_get_component.IsSuccess(): - component_entity_pair = outcome_get_component.GetValue() - editor.EditorComponentAPIBus(bus.Broadcast, 'RemoveComponents', [component_entity_pair]) - component_exists = editor.EditorComponentAPIBus(bus.Broadcast, 'HasComponentOfType', parent_entity, - type_id_list[0]) - mesh_test = True - if component_exists: - mesh_test = False - Report.result(Tests.remove_mesh_component, mesh_test) - else: - Report.result(Tests.found_component_typeId, outcome_get_component.IsSuccess()) - - # 10. delete parent entity - editor.ToolsApplicationRequestBus(azlmbr.bus.Broadcast, 'DeleteEntityById', parent_entity) - Report.result(Tests.delete_entity, search_entity(parent_entity, "Parent_1") == False) - - # Close editor without saving - editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') - - -if __name__ == "__main__": - from editor_python_test_tools.utils import Report - - Report.start_test(sample_editor_tests) diff --git a/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py b/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py index 755f75216b..afc52f962d 100644 --- a/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py +++ b/AutomatedTesting/Gem/PythonTests/editor/TestSuite_Main_Optimized.py @@ -75,5 +75,5 @@ class TestAutomationAutoTestMode(EditorTestSuite): from .EditorScripts import Menus_FileMenuOptions as test_module - class test_Sample_Editor_Tests(EditorSharedTest): + class test_BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD(EditorSharedTest): from .EditorScripts import BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD as test_module From f009e06cab8f1af7e0c74a24421b97b38955e517 Mon Sep 17 00:00:00 2001 From: kritin Date: Wed, 6 Oct 2021 13:20:48 -0700 Subject: [PATCH 4/4] responding to code reviews Signed-off-by: kritin --- ...flows_ExistingLevel_EntityComponentCRUD.py | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py index 803b9e9a11..39cacf9af5 100644 --- a/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py +++ b/AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD.py @@ -53,10 +53,9 @@ def BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD(): 03. create child entity and set a name 04. delete child entity 05. add mesh component to parent entity - 07. delete parent entity - Close editor without saving + 06. delete parent entity """ - import os + from editor_python_test_tools.utils import Report from editor_python_test_tools.editor_entity_utils import EditorEntity @@ -66,50 +65,35 @@ def BasicEditorWorkflows_ExistingLevel_EntityComponentCRUD(): import azlmbr.legacy.general as general import azlmbr.object - # 01. load an existing level - test_level = 'Simple' general.open_level_no_prompt(test_level) Report.result(Tests.load_level, general.get_current_level_name() == test_level) - # 02. create parent entity and set name # Delete any exiting entity and Create a new Entity at the root level - search_filter = azlmbr.entity.SearchFilter() all_entities = entity.SearchBus(azlmbr.bus.Broadcast, "SearchEntities", search_filter) editor.ToolsApplicationRequestBus(bus.Broadcast, "DeleteEntities", all_entities) parent_entity = EditorEntity.create_editor_entity("Parent_1") Report.result(Tests.create_entity, parent_entity.exists()) - # 03. Create child Entity to above created parent entity and set a name - child_1_entity = EditorEntity.create_editor_entity("Child_1", parent_entity.id ) Report.result(Tests.create_child_entity, child_1_entity.exists()) - # 04. delete_Child_entity - child_1_entity.delete() Report.result(Tests.delete_child_entity, not child_1_entity.exists()) - # 05. add mesh component to parent entity - parent_entity.add_component("Mesh") Report.result(Tests.add_mesh_component, parent_entity.has_component("Mesh")) - - # 7. delete parent entity - + # 06. delete parent entity parent_entity.delete() Report.result(Tests.delete_entity, not parent_entity.exists()) - # Close editor without saving - editor.EditorToolsApplicationRequestBus(bus.Broadcast, 'ExitNoPrompt') - if __name__ == "__main__": from editor_python_test_tools.utils import Report