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

Xisco Fauli (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 13 08:37:00 UTC 2021


 sd/qa/uitest/findReplace/findReplace.py |  149 ++++++++++++++------------------
 uitest/uitest/test.py                   |    9 +
 2 files changed, 73 insertions(+), 85 deletions(-)

New commits:
commit a917d4abd8577cf7d6655f0484ff55dd86a0a8a1
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Fri Sep 10 17:09:40 2021 +0200
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Mon Sep 13 10:36:27 2021 +0200

    uitest: guard execute_modeless_dialog_through_command in sd
    
    Change-Id: I4d67318af30b00182253de5f6ccf9cafd7664ee1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121911
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sd/qa/uitest/findReplace/findReplace.py b/sd/qa/uitest/findReplace/findReplace.py
index 9a4cb34874e6..906f53bba363 100644
--- a/sd/qa/uitest/findReplace/findReplace.py
+++ b/sd/qa/uitest/findReplace/findReplace.py
@@ -22,101 +22,84 @@ class findReplace(UITestCase):
             self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 1)
 
             # search for string "second"
-            self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"}))  #2nd slide
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())
-
-            # verify we moved to slide 2
-            self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 2)
+            with self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog", close_button="close") as xDialog:
+                searchterm = xDialog.getChild("searchterm")
+                searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"}))  #2nd slide
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
 
-            # search for string "third"
-            searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"third"}))
-            xsearch.executeAction("CLICK", tuple())
+                # verify we moved to slide 2
+                self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 2)
 
-            #verify we moved to slide 3
-            self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 3)  #3rd slide
+                # search for string "third"
+                searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"third"}))
+                xsearch.executeAction("CLICK", tuple())
 
-            # close the dialog
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+                #verify we moved to slide 3
+                self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 3)  #3rd slide
 
             # now open dialog and verify find="third" (remember last value);
             # replace value with "First" (click match case) with word "Replace"
             # click twice the Replace button, check "Replace first first"
 
             # open the dialog again
-            self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            # verify search string is still "third" from previous search
-            searchterm = xDialog.getChild("searchterm")
-            self.assertEqual(get_state_as_dict(searchterm)["Text"], "third")
-
-            # replace it with "First"
-            searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"First"}))
-
-            # click "match case"
-            matchcase = xDialog.getChild("matchcase")
-            matchcase.executeAction("CLICK", tuple())  #click match case
-
-            # set the replace string to "Replace"
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace"})) #replace textbox
-
-            # hit replace button 2 times
-            replace = xDialog.getChild("replace")
-            replace.executeAction("CLICK", tuple())
-            replace.executeAction("CLICK", tuple())   #click twice Replace button (one selects, second replaces)
-
-            # close and reopen the dialog, because of bug 122788
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
-            self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            # now replace first (uncheck match case) with word "aaa" - click once Replace All button, check "Replace aaa aaa"
-            matchcase = xDialog.getChild("matchcase")
-            matchcase.executeAction("CLICK", tuple())  # uncheck match case
-
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"aaa"}))
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.executeAction("CLICK", tuple()) # click on replace all button
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn) #close the dialog
+            with self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog", close_button="close") as xDialog:
+
+                # verify search string is still "third" from previous search
+                searchterm = xDialog.getChild("searchterm")
+                self.assertEqual(get_state_as_dict(searchterm)["Text"], "third")
+
+                # replace it with "First"
+                searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"First"}))
+
+                # click "match case"
+                matchcase = xDialog.getChild("matchcase")
+                matchcase.executeAction("CLICK", tuple())  #click match case
+
+                # set the replace string to "Replace"
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace"})) #replace textbox
+
+                # hit replace button 2 times
+                replace = xDialog.getChild("replace")
+                replace.executeAction("CLICK", tuple())
+                replace.executeAction("CLICK", tuple())   #click twice Replace button (one selects, second replaces)
+
+            # reopen the dialog, because of bug 122788
+            with self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog", close_button="close") as xDialog:
+
+                # now replace first (uncheck match case) with word "aaa" - click once Replace All button, check "Replace aaa aaa"
+                matchcase = xDialog.getChild("matchcase")
+                matchcase.executeAction("CLICK", tuple())  # uncheck match case
+
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                replaceterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"aaa"}))
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple()) # click on replace all button
 
             # go to second page
-            self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"}))  #2nd slide
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+            with self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog", close_button="close") as xDialog:
+                searchterm = xDialog.getChild("searchterm")
+                searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"second"}))  #2nd slide
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
             self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 2)
             #now check if text "Replace aaa aaa" is on first slide
-            self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            backsearch = xDialog.getChild("backsearch")
-            searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace aaa aaa"}))
-            backsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 1)  #1st slide
-
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+            with self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog", close_button="close") as xDialog:
+                searchterm = xDialog.getChild("searchterm")
+                backsearch = xDialog.getChild("backsearch")
+                searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"Replace aaa aaa"}))
+                backsearch.executeAction("CLICK", tuple())
+                #verify
+                self.assertEqual(impress_doc.CurrentController.getCurrentPage().Number, 1)  #1st slide
+
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index fe06c1e65817..48ddf2833035 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -110,8 +110,8 @@ class UITest(object):
 
     # Calls UITest.close_dialog_through_button at exit
     @contextmanager
-    def execute_dialog_through_command(self, command, printNames=False, close_button = "ok"):
-        with EventListener(self._xContext, "DialogExecute", printNames=printNames) as event:
+    def execute_dialog_through_command(self, command, printNames=False, close_button = "ok", eventName = "DialogExecute"):
+        with EventListener(self._xContext, eventName, printNames=printNames) as event:
             if not self._xUITest.executeDialog(command):
                 raise Exception("Dialog not executed for: " + command)
             while True:
@@ -125,6 +125,11 @@ class UITest(object):
                     return
                 time.sleep(DEFAULT_SLEEP)
 
+    @contextmanager
+    def execute_modeless_dialog_through_command_guarded(self, command, printNames=False, close_button = "ok"):
+        with self.execute_dialog_through_command(command, printNames, close_button, "ModelessDialogVisible") as xDialog:
+            yield xDialog
+
     def execute_modeless_dialog_through_command(self, command, printNames=False):
         with EventListener(self._xContext, "ModelessDialogVisible", printNames = printNames) as event:
             if not self._xUITest.executeCommand(command):


More information about the Libreoffice-commits mailing list