FileMenu_Default_NewAndOpen.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. from PySide2 import QtWidgets
  7. from editor_python_test_tools.utils import TestHelper as helper
  8. from editor_python_test_tools.utils import Report
  9. import azlmbr.legacy.general as general
  10. import pyside_utils
  11. class Tests():
  12. initialTabTestResults = "Verified no tabs open"
  13. newTabTestResults = "New tab opened successfully"
  14. fileMenuTestResults = "Open file window triggered successfully"
  15. TIME_TO_WAIT = 3
  16. SCRIPT_CANVAS_PANE = "Script Canvas"
  17. class TestFileMenuDefaultNewOpen:
  18. """
  19. Summary:
  20. When clicked on File->New, new script opens
  21. File->Open should open the FileBrowser
  22. Expected Behavior:
  23. New and Open actions should work as expected.
  24. Test Steps:
  25. 1) Open Script Canvas window and wait for it to render(Tools > Script Canvas)
  26. 2) Get the SC window object
  27. 3) Get the initial tab count and verify it's zero. Save the tab count for verification in step 5
  28. 4) Trigger open new graph file action
  29. 5) Check tab count again to verify a new tab has been opened
  30. 6) Trigger open file popup action then close the popup
  31. 7) Close Script Canvas window
  32. Note:
  33. - This test file must be called from the Open 3D Engine Editor command terminal
  34. - Any passed and failed tests are written to the Editor.log file.
  35. Parsing the file or running a log_monitor are required to observe the test results.
  36. :return: None
  37. """
  38. @pyside_utils.wrap_async
  39. async def run_test(self):
  40. # Preconditions
  41. general.idle_enable(True)
  42. # 1) Open Script Canvas window and wait for it to render(Tools > Script Canvas)
  43. general.open_pane(SCRIPT_CANVAS_PANE)
  44. helper.wait_for_condition(lambda: general.is_pane_visible(SCRIPT_CANVAS_PANE), TIME_TO_WAIT)
  45. # 2) Get the SC window object
  46. editor_window = pyside_utils.get_editor_main_window()
  47. sc = editor_window.findChild(QtWidgets.QDockWidget, SCRIPT_CANVAS_PANE)
  48. sc_main = sc.findChild(QtWidgets.QMainWindow)
  49. sc_tabs = sc_main.findChild(QtWidgets.QTabWidget, "ScriptCanvasTabs")
  50. # 3) Get the initial tab count and verify it's zero. Save the tab count for verification in step 5
  51. Report.info(f"{Tests.initialTabTestResults}: {sc_tabs.count() == 0}")
  52. initial_tabs_count = sc_tabs.count()
  53. # 4) Trigger open new graph file action
  54. action = pyside_utils.find_child_by_pattern(
  55. sc_main, {"objectName": "action_New_Script", "type": QtWidgets.QAction})
  56. action.trigger()
  57. # 5) Check tab count again to verify a new tab has been opened
  58. result = helper.wait_for_condition(lambda: sc_tabs.count() > initial_tabs_count, TIME_TO_WAIT)
  59. Report.info(f"{Tests.newTabTestResults}: {result}")
  60. # 6) Trigger open file popup action then close the popup.
  61. action = pyside_utils.find_child_by_pattern(sc_main, {"objectName": "action_Open", "type": QtWidgets.QAction})
  62. pyside_utils.trigger_action_async(action)
  63. popup = await pyside_utils.wait_for_modal_widget()
  64. result = popup and 'Open' in popup.windowTitle()
  65. Report.info(f"{Tests.fileMenuTestResults}: {result}")
  66. popup.close()
  67. # 7) Close Script Canvas window
  68. general.close_pane(SCRIPT_CANVAS_PANE)
  69. test = TestFileMenuDefaultNewOpen()
  70. test.run_test()