GraphClose_Default_SavePrompt.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import pyside_utils
  8. from editor_python_test_tools.utils import TestHelper as helper
  9. from editor_python_test_tools.utils import Report
  10. import azlmbr.legacy.general as general
  11. # fmt: off
  12. class Tests():
  13. new_graph = "New graph created"
  14. save_prompt = "Save prompt opened as expected"
  15. close_graph = "Close button worked as expected"
  16. # fmt: on
  17. GENERAL_WAIT = 0.5 # seconds
  18. class TestGraphClose_Default_SavePrompt:
  19. """
  20. Summary:
  21. The graph is closed when x button is clicked.
  22. Save Prompt is opened before closing.
  23. Expected Behavior:
  24. The Graph is closed.
  25. Upon closing the graph, User is prompted whether or not to save changes.
  26. Test Steps:
  27. 1) Open Script Canvas window (Tools > Script Canvas)
  28. 2) Get the SC window object
  29. 3) Trigger File->New action
  30. 4) Verify if New tab is opened
  31. 5) Close new tab using X on top of graph and check for save dialog
  32. 6) Check if tab is closed
  33. 7) Close Script Canvas window
  34. Note:
  35. - This test file must be called from the Open 3D Engine Editor command terminal
  36. - Any passed and failed tests are written to the Editor.log file.
  37. Parsing the file or running a log_monitor are required to observe the test results.
  38. :return: None
  39. """
  40. @pyside_utils.wrap_async
  41. async def run_test(self):
  42. # 1) Open Script Canvas window (Tools > Script Canvas)
  43. general.idle_enable(True)
  44. general.open_pane("Script Canvas")
  45. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  46. # 2) Get the SC window object
  47. editor_window = pyside_utils.get_editor_main_window()
  48. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  49. sc_main = sc.findChild(QtWidgets.QMainWindow)
  50. sc_tabs = sc_main.findChild(QtWidgets.QTabWidget, "ScriptCanvasTabs")
  51. tab_bar = sc_tabs.findChild(QtWidgets.QTabBar)
  52. # 3) Trigger File->New action
  53. initial_tabs_count = sc_tabs.count()
  54. action = pyside_utils.find_child_by_pattern(
  55. sc_main, {"objectName": "action_New_Script", "type": QtWidgets.QAction}
  56. )
  57. action.trigger()
  58. # 4) Verify if New tab is opened
  59. result = helper.wait_for_condition(lambda: sc_tabs.count() == initial_tabs_count + 1, GENERAL_WAIT)
  60. Report.info(f"{Tests.new_graph}: {result}")
  61. # 5) Close new tab using X on top of graph and check for save dialog
  62. close_button = tab_bar.findChildren(QtWidgets.QAbstractButton)[0]
  63. pyside_utils.click_button_async(close_button)
  64. popup = await pyside_utils.wait_for_modal_widget()
  65. if popup:
  66. Report.info(f"{Tests.save_prompt}: {popup.findChild(QtWidgets.QDialog, 'SaveChangesDialog') is not None}")
  67. dont_save = popup.findChild(QtWidgets.QPushButton, "m_continueButton")
  68. dont_save.click()
  69. # 6) Check if tab is closed
  70. await pyside_utils.wait_for_condition(lambda: sc_tabs.count() == initial_tabs_count, 5.0)
  71. Report.info(f"{Tests.close_graph}: {sc_tabs.count()==initial_tabs_count}")
  72. # 7) Close Script Canvas window
  73. general.close_pane("Script Canvas")
  74. test = TestGraphClose_Default_SavePrompt()
  75. test.run_test()