[Libreoffice-commits] core.git: sw/qa uitest/uitest

Henry Castro (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 7 18:13:43 UTC 2021


 sw/qa/uitest/writer_tests2/fontworks.py |   36 ++++++++++++++------------------
 uitest/uitest/uihelper/guarded.py       |   10 ++++++++
 2 files changed, 26 insertions(+), 20 deletions(-)

New commits:
commit 7f49c4eea51c6c84ee7adacd5ba45e1e0fc4c1f7
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Fri Apr 9 17:32:56 2021 -0400
Commit:     Henry Castro <hcastro at collabora.com>
CommitDate: Mon Jun 7 20:13:04 2021 +0200

    sw/qa/uitest: close the dialog if thrown an exception
    
    if a unit test opens a dialog and exception
    is thrown if does not exist a control, the
    terminate() method fails, the unit test will
    wait indefinitely for the subprocess to terminate.
    
    Change-Id: I6dc77b2db8ce042ead78d13ce57e91892cd2db90
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113896
    Tested-by: Jenkins
    Reviewed-by: Henry Castro <hcastro at collabora.com>

diff --git a/sw/qa/uitest/writer_tests2/fontworks.py b/sw/qa/uitest/writer_tests2/fontworks.py
index 4d4044ab2bd0..d9ef76c10602 100644
--- a/sw/qa/uitest/writer_tests2/fontworks.py
+++ b/sw/qa/uitest/writer_tests2/fontworks.py
@@ -10,6 +10,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper import guarded
 #test FontWorks dialog
 class fontWorksDialog(UITestCase):
 
@@ -18,26 +19,21 @@ class fontWorksDialog(UITestCase):
         xWriterDoc = self.xUITest.getTopFocusWindow()
         xWriterEdit = xWriterDoc.getChild("writer_edit")
 
-        self.ui_test.execute_dialog_through_command(".uno:FontworkGalleryFloater")
-        xDialog = self.xUITest.getTopFocusWindow()
-
-        FontWorkSelector = xDialog.getChild("ctlFavoriteswin")
-        # Select element with id (3)
-        element3 = FontWorkSelector.getChild("2")
-        element3.executeAction("SELECT", mkPropertyValues({}))
-        print(get_state_as_dict(FontWorkSelector))
-        self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemPos"], "2")
-        self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemId"], "3")
-        self.assertEqual(get_state_as_dict(FontWorkSelector)["VisibleCount"], "36")
-
-        # Select element with id (7)
-        element7 = FontWorkSelector.getChild("6")
-        element7.executeAction("SELECT", mkPropertyValues({}))
-        self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemPos"], "6")
-        self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemId"], "7")
-
-        xCloseBtn = xDialog.getChild("cancel")
-        self.ui_test.close_dialog_through_button(xCloseBtn)
+        with guarded.execute_dialog_through_command(self, ".uno:FontworkGalleryFloater", close_button="cancel") as xDialog:
+            FontWorkSelector = xDialog.getChild("ctlFavoriteswin")
+            # Select element with id (3)
+            element3 = FontWorkSelector.getChild("2")
+            element3.executeAction("SELECT", mkPropertyValues({}))
+            print(get_state_as_dict(FontWorkSelector))
+            self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemPos"], "2")
+            self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemId"], "3")
+            self.assertEqual(get_state_as_dict(FontWorkSelector)["VisibleCount"], "36")
+
+            # Select element with id (7)
+            element7 = FontWorkSelector.getChild("6")
+            element7.executeAction("SELECT", mkPropertyValues({}))
+            self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemPos"], "6")
+            self.assertEqual(get_state_as_dict(FontWorkSelector)["SelectedItemId"], "7")
 
         self.ui_test.close_doc()
 
diff --git a/uitest/uitest/uihelper/guarded.py b/uitest/uitest/uihelper/guarded.py
index b7e5ce099d1e..871fa697d584 100644
--- a/uitest/uitest/uihelper/guarded.py
+++ b/uitest/uitest/uihelper/guarded.py
@@ -28,4 +28,14 @@ def execute_dialog_through_action(testCase, ui_object, action, parameters = None
     finally:
         testCase.ui_test.close_dialog_through_button(xDialog.getChild(close_button))
 
+# Calls UITest.close_dialog_through_button at exit
+ at contextmanager
+def execute_dialog_through_command(testCase, unoCommand, close_button = "ok"):
+    testCase.ui_test.execute_dialog_through_command(unoCommand)
+    xDialog = testCase.xUITest.getTopFocusWindow()
+    try:
+        yield xDialog
+    finally:
+        testCase.ui_test.close_dialog_through_button(xDialog.getChild(close_button))
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list