2
0

Pane_Default_RetainOnSCRestart.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # fmt: off
  7. class Tests():
  8. relaunch_sc = ("Script Canvas window is relaunched", "Failed to relaunch Script Canvas window")
  9. test_panes_visible = ("All the test panes are opened", "Failed to open one or more test panes")
  10. close_pane_1 = ("Test pane 1 is closed", "Failed to close test pane 1")
  11. visibility_retained = ("Test pane retained its visibility on SC restart", "Failed to retain visibility of test pane on SC restart")
  12. resize_pane_3 = ("Test pane 3 resized successfully", "Failed to resize Test pane 3")
  13. size_retained = ("Test pane retained its size on SC restart", "Failed to retain size of test pane on SC restart")
  14. location_changed = ("Location of test pane 2 changed successfully", "Failed to change location of test pane 2")
  15. location_retained = ("Test pane retained its location on SC restart", "Failed to retain location of test pane on SC restart")
  16. # fmt: on
  17. def Pane_Default_RetainOnSCRestart():
  18. """
  19. Summary:
  20. The Script Canvas window is opened to verify if Script canvas panes can retain its visibility, size and location
  21. upon ScriptCanvas restart.
  22. Expected Behavior:
  23. The ScriptCanvas pane retain it's visibility, size and location upon ScriptCanvas restart.
  24. Test Steps:
  25. 1) Open Script Canvas window (Tools > Script Canvas)
  26. 2) Make sure test panes are open and visible
  27. 3) Close test pane 1
  28. 4) Change dock location of test pane 2
  29. 5) Resize test pane 3
  30. 6) Relaunch Script Canvas
  31. 7) Verify if test pane 1 retain its visibility
  32. 8) Verify if location of test pane 2 is retained
  33. 9) Verify if size of test pane 3 is retained
  34. 10) Restore default layout and close SC window
  35. Note:
  36. - This test file must be called from the Open 3D Engine Editor command terminal
  37. - Any passed and failed tests are written to the Editor.log file.
  38. Parsing the file or running a log_monitor are required to observe the test results.
  39. :return: None
  40. """
  41. # Pyside imports
  42. from PySide2 import QtCore, QtWidgets
  43. from PySide2.QtCore import Qt
  44. # Helper imports
  45. from utils import Report
  46. from utils import TestHelper as helper
  47. import pyside_utils
  48. # Open 3D Engine Imports
  49. import azlmbr.legacy.general as general
  50. TEST_PANE_1 = "NodePalette" # test visibility
  51. TEST_PANE_2 = "VariableManager" # test location
  52. TEST_PANE_3 = "NodeInspector" # 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"), 3.0)
  65. # 2) Make sure test panes are open and visible
  66. editor_window = pyside_utils.get_editor_main_window()
  67. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  68. click_menu_option(sc, "Restore Default Layout")
  69. test_pane_1 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_1)
  70. test_pane_2 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_2)
  71. test_pane_3 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_3)
  72. Report.result(
  73. Tests.test_panes_visible, test_pane_1.isVisible() and test_pane_2.isVisible() and test_pane_3.isVisible()
  74. )
  75. # Initiate try block here to restore default in finally block
  76. try:
  77. # 3) Close test pane
  78. test_pane_1.close()
  79. Report.result(Tests.close_pane_1, not test_pane_1.isVisible())
  80. # 4) Change dock location of test pane 2
  81. sc_main = sc.findChild(QtWidgets.QMainWindow)
  82. sc_main.addDockWidget(DOCKAREA, find_pane(sc_main, TEST_PANE_2), QtCore.Qt.Vertical)
  83. Report.result(Tests.location_changed, sc_main.dockWidgetArea(find_pane(sc_main, TEST_PANE_2)) == DOCKAREA)
  84. # 5) Resize test pane 3
  85. initial_size = test_pane_3.frameSize()
  86. test_pane_3.resize(initial_size.width() + SCALE_INT, initial_size.height() + SCALE_INT)
  87. new_size = test_pane_3.frameSize()
  88. resize_success = (
  89. abs(initial_size.width() - new_size.width()) == abs(initial_size.height() - new_size.height()) == SCALE_INT
  90. )
  91. Report.result(Tests.resize_pane_3, resize_success)
  92. # 6) Relaunch Script Canvas
  93. general.close_pane("Script Canvas")
  94. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 2.0)
  95. general.open_pane("Script Canvas")
  96. sc_visible = helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  97. Report.result(Tests.relaunch_sc, sc_visible)
  98. # 7) Verify if test pane 1 retain its visibility
  99. editor_window = pyside_utils.get_editor_main_window()
  100. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  101. Report.result(Tests.visibility_retained, not find_pane(sc, TEST_PANE_1).isVisible())
  102. # 8) Verify if location of test pane 2 is retained
  103. sc_main = sc.findChild(QtWidgets.QMainWindow)
  104. Report.result(Tests.location_retained, sc_main.dockWidgetArea(find_pane(sc_main, TEST_PANE_2)) == DOCKAREA)
  105. # 9) Verify if size of test pane 3 is retained
  106. test_pane_3 = sc.findChild(QtWidgets.QDockWidget, TEST_PANE_3)
  107. retained_size = test_pane_3.frameSize()
  108. retain_success = retained_size != initial_size
  109. Report.result(Tests.size_retained, retain_success)
  110. finally:
  111. # 10) Restore default layout and close SC window
  112. general.open_pane("Script Canvas")
  113. helper.wait_for_condition(lambda: general.is_pane_visible("Script Canvas"), 5.0)
  114. sc = editor_window.findChild(QtWidgets.QDockWidget, "Script Canvas")
  115. click_menu_option(sc, "Restore Default Layout")
  116. sc.close()
  117. if __name__ == "__main__":
  118. import ImportPathHelper as imports
  119. imports.init()
  120. from utils import Report
  121. Report.start_test(Pane_Default_RetainOnSCRestart)