Pane_PropertiesChanged_RetainsOnRestart.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. test_panes_visible = "All the test panes are opened"
  8. close_pane_1 = "Test pane 1 is closed"
  9. resize_pane_3 = "Test pane 3 resized successfully"
  10. location_changed = "Location of test pane 2 changed successfully"
  11. visiblity_retained = "Test pane retained its visiblity on Editor restart"
  12. location_retained = "Test pane retained its location on Editor restart"
  13. size_retained = "Test pane retained its size on Editor restart"
  14. def Pane_PropertiesChanged_RetainsOnRestart():
  15. """
  16. Summary:
  17. The Script Canvas window is opened to verify if Script canvas panes can retain its visibility, size and location
  18. upon Editor restart.
  19. Expected Behavior:
  20. The ScriptCanvas pane retain it's visiblity, size and location upon Editor restart.
  21. Test Steps:
  22. 1) Open Script Canvas window (Tools > Script Canvas)
  23. 2) Make sure test panes are open and visible
  24. 3) Close test pane 1
  25. 4) Change dock location of test pane 2
  26. 5) Resize test pane 3
  27. 6) Restart Editor
  28. 7) Verify if test pane 1 retain its visiblity
  29. 8) Verify if location of test pane 2 is retained
  30. 9) Verify if size of test pane 3 is retained
  31. 10) Restore default layout and close SC 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. import sys
  39. # Helper imports
  40. from utils import Report
  41. from utils import TestHelper as helper
  42. import pyside_utils
  43. # O3DE Imports
  44. import azlmbr.legacy.general as general
  45. # Pyside imports
  46. from PySide2 import QtCore, QtWidgets
  47. from PySide2.QtCore import Qt
  48. # Constants
  49. TEST_CONDITION = sys.argv[1]
  50. TEST_PANE_1 = "NodePalette" # pane used to test visibility
  51. TEST_PANE_2 = "VariableManager" # pane used to test location
  52. TEST_PANE_3 = "NodeInspector" # pane used to test size
  53. SCALE_INT = 10 # Random resize scale integer
  54. DOCKAREA = Qt.TopDockWidgetArea # Preferred top area since no widget is docked on top
  55. def click_menu_option(window, option_text):
  56. action = pyside_utils.find_child_by_pattern(window, {"text": option_text, "type": QtWidgets.QAction})
  57. action.trigger()
  58. def find_pane(window, pane_name):
  59. return window.findChild(QtWidgets.QDockWidget, pane_name)
  60. # Test starts here
  61. general.idle_enable(True)
  62. # 1) Open Script Canvas window (Tools > Script Canvas)
  63. general.open_pane("Script Canvas")
  64. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  65. if TEST_CONDITION == "before_restart":
  66. # 2) Make sure test panes are open and visible
  67. editor_window = pyside_utils.get_editor_main_window()
  68. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  69. click_menu_option(sc, "Restore Default Layout")
  70. test_pane_1 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_1)
  71. test_pane_2 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_2)
  72. test_pane_3 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_3)
  73. result = test_pane_1.isVisible() and test_pane_2.isVisible() and test_pane_3.isVisible()
  74. Report.info(f"{Tests.test_panes_visible}: {result}")
  75. # 3) Close test pane
  76. test_pane_1.close()
  77. Report.info(f"{Tests.close_pane_1}: {not test_pane_1.isVisible()}")
  78. # 4) Change dock location of test pane 2
  79. sc_main = sc.findChild(QtWidgets.QMainWindow)
  80. sc_main.addDockWidget(DOCKAREA, find_pane(sc_main, TEST_PANE_2), QtCore.Qt.Vertical)
  81. Report.info(f"{Tests.location_changed}: {sc_main.dockWidgetArea(find_pane(sc_main, TEST_PANE_2)) == DOCKAREA}")
  82. # 5) Resize test pane 3
  83. initial_size = test_pane_3.frameSize()
  84. test_pane_3.resize(initial_size.width() + SCALE_INT, initial_size.height() + SCALE_INT)
  85. new_size = test_pane_3.frameSize()
  86. resize_success = (
  87. abs(initial_size.width() - new_size.width()) == abs(initial_size.height() - new_size.height()) == SCALE_INT
  88. )
  89. Report.info(f"{Tests.resize_pane_3}: {resize_success}")
  90. if TEST_CONDITION == "after_restart":
  91. try:
  92. # 6) Restart Editor
  93. # Restart is not possible through script and hence it is done by running the same file as 2 tests with a
  94. # condition as before_test and after_test
  95. # 7) Verify if test pane 1 retain its visiblity
  96. # This pane closed before restart and expected that pane should not be visible.
  97. editor_window = pyside_utils.get_editor_main_window()
  98. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  99. Report.info(f"{Tests.visiblity_retained}: {not find_pane(sc, TEST_PANE_1).isVisible()}")
  100. # 8) Verify if location of test pane 2 is retained
  101. # This pane was set at DOCKAREA lcoation before restart
  102. sc_main = sc.findChild(QtWidgets.QMainWindow)
  103. Report.info(
  104. f"{Tests.location_retained}: {sc_main.dockWidgetArea(find_pane(sc_main, TEST_PANE_2)) == DOCKAREA}"
  105. )
  106. # 9) Verify if size of test pane 3 is retained
  107. # Verifying if size retained by checking current size not matching with default size
  108. test_pane_3 = find_pane(sc, TEST_PANE_3)
  109. retained_size = test_pane_3.frameSize()
  110. click_menu_option(sc, "Restore Default Layout")
  111. actual_size = test_pane_3.frameSize()
  112. Report.info(f"{Tests.size_retained}: {retained_size != actual_size}")
  113. finally:
  114. # 10) Restore default layout and close SC window
  115. general.open_pane("Script Canvas")
  116. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  117. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  118. click_menu_option(sc, "Restore Default Layout")
  119. sc.close()
  120. if __name__ == "__main__":
  121. import ImportPathHelper as imports
  122. imports.init()
  123. from utils import Report
  124. Report.start_test(Pane_PropertiesChanged_RetainsOnRestart)