sw/qa/uitest/findReplace/findReplace.py          |  256 ++++++--------
 sw/qa/uitest/findReplace/findSimilarity.py       |   29 -
 sw/qa/uitest/findReplace/tdf106099.py            |   35 -
 sw/qa/uitest/findReplace/tdf118208.py            |   15 
 sw/qa/uitest/findReplace/tdf119462.py            |   33 -
 sw/qa/uitest/findReplace/tdf126627.py            |   22 -
 sw/qa/uitest/findReplace/tdf144089.py            |   37 --
 sw/qa/uitest/findReplace/tdf44837.py             |   27 -
 sw/qa/uitest/macro_tests/tdf64690.py             |   41 +-
 sw/qa/uitest/ui/index/index.py                   |   35 -
 sw/qa/uitest/writer_tests/compareDocuments.py    |   34 -
 sw/qa/uitest/writer_tests/trackedChanges.py      |  169 ++++-----
 sw/qa/uitest/writer_tests/wordCount.py           |  416 ++++++++++-------------
 sw/qa/uitest/writer_tests2/asianPhoneticGuide.py |   36 -
 sw/qa/uitest/writer_tests4/spellDialog.py        |   74 +---
 sw/qa/uitest/writer_tests4/tdf122449.py          |   17 
 sw/qa/uitest/writer_tests6/tdf126017.py          |   13 
 sw/qa/uitest/writer_tests7/forms.py              |  189 +++++-----
 sw/qa/uitest/writer_tests7/tdf140731.py          |    9 
 sw/qa/uitest/writer_tests7/tdf90401.py           |   26 -
 20 files changed, 688 insertions(+), 825 deletions(-)

New commits:
commit 1301d8461ec5112ad8bc672dd1ac141238a29cef
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Sep 10 18:18:45 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Sep 13 10:37:29 2021 +0200

    uitest: guard execute_modeless_dialog_through_command in sw
    
    Change-Id: Ie3acd6eb716d6d3532bb50b5b9002f80044a2bc5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121913
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/uitest/findReplace/findReplace.py 
b/sw/qa/uitest/findReplace/findReplace.py
index 7ad35e4c1851..bde76fec35cd 100644
--- a/sw/qa/uitest/findReplace/findReplace.py
+++ b/sw/qa/uitest/findReplace/findReplace.py
@@ -14,83 +14,77 @@ class findReplace(UITestCase):
         with self.ui_test.load_file(get_url_for_data_file("findReplace.odt")) 
as writer_doc:
             xWriterDoc = self.xUITest.getTopFocusWindow()
             xWriterEdit = xWriterDoc.getChild("writer_edit")
-            
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 page
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"2")
-
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"third"}))
-            xsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"3")  #3rd page
-
-            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 page
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
+                #verify
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "2")
+
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"third"}))
+                xsearch.executeAction("CLICK", tuple())
+                #verify
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3")  #3rd page
+
 
             #now open dialog and verify find="third" (remember last value); 
replace value with "First" ( click match case) with word "Replace" - click 
twice Replace button, check "Replace first first"
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            self.assertEqual(get_state_as_dict(searchterm)["Text"], "third")
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"First"}))
-            matchcase = xDialog.getChild("matchcase")
-            matchcase.executeAction("CLICK", tuple())  #click match case
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"Replace"})) #replace textbox
-            replace = xDialog.getChild("replace")
-            replace.executeAction("CLICK", tuple())
-            replace.executeAction("CLICK", tuple())   #click twice Replace 
button
-            #verify
-            self.assertEqual(writer_doc.Text.String[0:19], "Replace first 
first")
-
-            #now replace first (uncheck match case) with word "aaa" - click 
once Replace All button, check "Replace aaa aaa"
-            replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"aaa"}))
-            matchcase.executeAction("CLICK", tuple())  #uncheck match case
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(writer_doc.Text.String[0:15], "Replace aaa aaa")
-
-            #now delete strings in textbox Find and textbox Replace, click 
button Format, select  Size=16 pt, Close OK, Find Next; verify Page=2;
-            #click No format button; close dialog
-            replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-
-            format = xDialog.getChild("format")
-            with self.ui_test.execute_blocking_action(format.executeAction, 
args=('CLICK', ())) as dialog:
-                xTabs = dialog.getChild("tabcontrol")
-                select_pos(xTabs, "0")
-                xSizeFont = dialog.getChild("westsizelb-cjk")
-                xSizeFont.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-                xSizeFont.executeAction("TYPE", 
mkPropertyValues({"TEXT":"16"}))    #set font size 16
-
-            # Verify these didn't get set again through 
SvxSearchController::StateChanged, timer-
-            # triggered from SfxBindings::NextJob while executing the Format 
dialog above:
-            self.assertEqual(get_state_as_dict(searchterm)["Text"], "")
-            self.assertEqual(get_state_as_dict(replaceterm)["Text"], "")
-
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"2")
-            noformat = xDialog.getChild("noformat")
-            noformat.executeAction("CLICK", tuple())   #click No format button
-
-            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")
+                self.assertEqual(get_state_as_dict(searchterm)["Text"], 
"third")
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"First"}))
+                matchcase = xDialog.getChild("matchcase")
+                matchcase.executeAction("CLICK", tuple())  #click match case
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"Replace"})) #replace textbox
+                replace = xDialog.getChild("replace")
+                replace.executeAction("CLICK", tuple())
+                replace.executeAction("CLICK", tuple())   #click twice Replace 
button
+                #verify
+                self.assertEqual(writer_doc.Text.String[0:19], "Replace first 
first")
+
+                #now replace first (uncheck match case) with word "aaa" - 
click once Replace All button, check "Replace aaa aaa"
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"aaa"}))
+                matchcase.executeAction("CLICK", tuple())  #uncheck match case
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple())
+                #verify
+                self.assertEqual(writer_doc.Text.String[0:15], "Replace aaa 
aaa")
+
+                #now delete strings in textbox Find and textbox Replace, click 
button Format, select  Size=16 pt, Close OK, Find Next; verify Page=2;
+                #click No format button; close dialog
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+
+                format = xDialog.getChild("format")
+                with 
self.ui_test.execute_blocking_action(format.executeAction, args=('CLICK', ())) 
as dialog:
+                    xTabs = dialog.getChild("tabcontrol")
+                    select_pos(xTabs, "0")
+                    xSizeFont = dialog.getChild("westsizelb-cjk")
+                    xSizeFont.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                    xSizeFont.executeAction("TYPE", 
mkPropertyValues({"TEXT":"16"}))    #set font size 16
+
+                # Verify these didn't get set again through 
SvxSearchController::StateChanged, timer-
+                # triggered from SfxBindings::NextJob while executing the 
Format dialog above:
+                self.assertEqual(get_state_as_dict(searchterm)["Text"], "")
+                self.assertEqual(get_state_as_dict(replaceterm)["Text"], "")
+
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
+                #verify
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "2")
+                noformat = xDialog.getChild("noformat")
+                noformat.executeAction("CLICK", tuple())   #click No format 
button
+
 
         #Bug 39022 - find-replace->$1, not pattern
     def test_tdf39022_replace_regexp(self):
@@ -99,22 +93,19 @@ class findReplace(UITestCase):
             xWriterEdit = xWriterDoc.getChild("writer_edit")
             type_text(xWriterEdit, "test number1 testnot")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"T(est|other)\\>"}))   #find
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"replaced$1"})) #replace
-            regexp = xDialog.getChild("regexp")
-            regexp.executeAction("CLICK", tuple())   #regular expressions
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(document.Text.String[0:27], "replacedest number1 
testnot")
-            regexp.executeAction("CLICK", tuple())
+            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":"T(est|other)\\>"}))   #find
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"replaced$1"})) #replace
+                regexp = xDialog.getChild("regexp")
+                regexp.executeAction("CLICK", tuple())   #regular expressions
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple())
+                #verify
+                self.assertEqual(document.Text.String[0:27], "replacedest 
number1 testnot")
+                regexp.executeAction("CLICK", tuple())
 
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
 
 
         #tdf116242  ţ ț
@@ -122,47 +113,40 @@ class findReplace(UITestCase):
         with self.ui_test.load_file(get_url_for_data_file("tdf116242.odt")) as 
writer_doc:
             xWriterDoc = self.xUITest.getTopFocusWindow()
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"ţ"}))   
#find
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"ț"})) 
#replace
-            includediacritics = xDialog.getChild("includediacritics")
-            if (get_state_as_dict(includediacritics)["Selected"]) == "false":
-                includediacritics.executeAction("CLICK", tuple())
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(writer_doc.Text.String[0:13], "țoootdf116242")
-
-            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":"ţ"}))   #find
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"ț"})) #replace
+                includediacritics = xDialog.getChild("includediacritics")
+                if (get_state_as_dict(includediacritics)["Selected"]) == 
"false":
+                    includediacritics.executeAction("CLICK", tuple())
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple())
+                #verify
+                self.assertEqual(writer_doc.Text.String[0:13], "țoootdf116242")
+
 
         #Bug 98417 - FIND & REPLACE: Add 'Find Previous' button
     def test_tdf98417_find_previous_writer(self):
         with self.ui_test.load_file(get_url_for_data_file("findReplace.odt")) 
as writer_doc:
             xWriterDoc = self.xUITest.getTopFocusWindow()
             xWriterEdit = xWriterDoc.getChild("writer_edit")
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"third"}))
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"3")
-            xsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"4")   #page 4
-            backsearch = xDialog.getChild("backsearch")
-            backsearch.executeAction("CLICK", tuple())
-            #verify
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"3")
-
-            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":"third"}))
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
+                #verify
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3")
+                xsearch.executeAction("CLICK", tuple())
+                #verify
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "4")   #page 4
+                backsearch = xDialog.getChild("backsearch")
+                backsearch.executeAction("CLICK", tuple())
+                #verify
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3")
 
     def test_tdf136577(self):
         with self.ui_test.create_doc_in_start_center("writer") as document:
@@ -170,27 +154,23 @@ class findReplace(UITestCase):
             xWriterDoc = self.xUITest.getTopFocusWindow()
             xWriterEdit = xWriterDoc.getChild("writer_edit")
 
-
             type_text(xWriterEdit, "x")
 
             self.assertEqual(document.Text.String, "x")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"x"}))
+            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":"x"}))
 
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.executeAction("CLICK", tuple())
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple())
 
-            self.assertEqual(document.Text.String, "")
+                self.assertEqual(document.Text.String, "")
 
-            self.xUITest.executeCommand(".uno:Undo")
-
-            # Without the fix in place, this test would have failed with 
AssertionError: '' != 'x'
-            self.assertEqual(document.Text.String, "x")
+                self.xUITest.executeCommand(".uno:Undo")
 
+                # Without the fix in place, this test would have failed with 
AssertionError: '' != 'x'
+                self.assertEqual(document.Text.String, "x")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/findReplace/findSimilarity.py 
b/sw/qa/uitest/findReplace/findSimilarity.py
index e637d60baffb..a24e9078d7e8 100644
--- a/sw/qa/uitest/findReplace/findSimilarity.py
+++ b/sw/qa/uitest/findReplace/findSimilarity.py
@@ -19,21 +19,20 @@ class findSimilarities(UITestCase):
             self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"1")
             # search and replace dialog
             #find = seco
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"seco"}))  #seco
-            # check similarities, button similarities, set values = 1; close 
dialog with OK
-            similarity = xDialog.getChild("similarity")
-            similaritybtn = xDialog.getChild("similaritybtn")
-            similarity.executeAction("CLICK", tuple())
-            with 
self.ui_test.execute_blocking_action(similaritybtn.executeAction, 
args=('CLICK', ())) as dialog:
-                otherfld = dialog.getChild("otherfld")
-                longerfld = dialog.getChild("longerfld")
-                shorterfld = dialog.getChild("shorterfld")
-                otherfld.executeAction("DOWN", tuple())
-                longerfld.executeAction("DOWN", tuple())
-                shorterfld.executeAction("DOWN", tuple())
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog",
 close_button="") as xDialog:
+                searchterm = xDialog.getChild("searchterm")
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"seco"}))  #seco
+                # check similarities, button similarities, set values = 1; 
close dialog with OK
+                similarity = xDialog.getChild("similarity")
+                similaritybtn = xDialog.getChild("similaritybtn")
+                similarity.executeAction("CLICK", tuple())
+                with 
self.ui_test.execute_blocking_action(similaritybtn.executeAction, 
args=('CLICK', ())) as dialog:
+                    otherfld = dialog.getChild("otherfld")
+                    longerfld = dialog.getChild("longerfld")
+                    shorterfld = dialog.getChild("shorterfld")
+                    otherfld.executeAction("DOWN", tuple())
+                    longerfld.executeAction("DOWN", tuple())
+                    shorterfld.executeAction("DOWN", tuple())
 
             #open dialog again, verify values = 1; close dialog with cancel
             with 
self.ui_test.execute_blocking_action(similaritybtn.executeAction, 
args=('CLICK', ()), close_button="cancel") as dialog:
diff --git a/sw/qa/uitest/findReplace/tdf106099.py 
b/sw/qa/uitest/findReplace/tdf106099.py
index c3eabef410df..843776fe4672 100644
--- a/sw/qa/uitest/findReplace/tdf106099.py
+++ b/sw/qa/uitest/findReplace/tdf106099.py
@@ -16,25 +16,22 @@ class tdf106099(UITestCase):
         with self.ui_test.create_doc_in_start_center("writer"):
             xWriterDoc = self.xUITest.getTopFocusWindow()
             #Find and replace
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            #2. Choose Format
-            format = xDialog.getChild("format")
-            with self.ui_test.execute_blocking_action(format.executeAction, 
args=('CLICK', ())) as dialog:
-                #Font effects - Underline Single. OK.
-                xTabs = dialog.getChild("tabcontrol")
-                select_pos(xTabs, "1")          #tab font effects
-                underlinelb = dialog.getChild("underlinelb")
-                select_by_text(underlinelb, "Single")
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog",
 close_button="close") as xDialog:
+                #2. Choose Format
+                format = xDialog.getChild("format")
+                with 
self.ui_test.execute_blocking_action(format.executeAction, args=('CLICK', ())) 
as dialog:
+                    #Font effects - Underline Single. OK.
+                    xTabs = dialog.getChild("tabcontrol")
+                    select_pos(xTabs, "1")          #tab font effects
+                    underlinelb = dialog.getChild("underlinelb")
+                    select_by_text(underlinelb, "Single")
 
-            #verify label searchdesc
-            searchdesc = xDialog.getChild("searchdesc")
-            print(get_state_as_dict(searchdesc))
-            self.assertEqual(get_state_as_dict(searchdesc)["Text"], "Single 
underline")
-            noformat = xDialog.getChild("noformat")
-            noformat.executeAction("CLICK", tuple())   #click No format button
-            self.assertEqual(get_state_as_dict(searchdesc)["Text"], "")
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+                #verify label searchdesc
+                searchdesc = xDialog.getChild("searchdesc")
+                print(get_state_as_dict(searchdesc))
+                self.assertEqual(get_state_as_dict(searchdesc)["Text"], 
"Single underline")
+                noformat = xDialog.getChild("noformat")
+                noformat.executeAction("CLICK", tuple())   #click No format 
button
+                self.assertEqual(get_state_as_dict(searchdesc)["Text"], "")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/findReplace/tdf118208.py 
b/sw/qa/uitest/findReplace/tdf118208.py
index b5abcfc83af0..57fcdea1f82d 100644
--- a/sw/qa/uitest/findReplace/tdf118208.py
+++ b/sw/qa/uitest/findReplace/tdf118208.py
@@ -36,18 +36,15 @@ class tdf118208(UITestCase):
                     complexlanguage.executeAction("CLICK", tuple())
 
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog",
 close_button="close") as xDialog:
 
-            format = xDialog.getChild("format")
+                format = xDialog.getChild("format")
 
-            with self.ui_test.execute_blocking_action(format.executeAction, 
args=('CLICK', ())):
-                pass
+                with 
self.ui_test.execute_blocking_action(format.executeAction, args=('CLICK', ())):
+                    pass
 
-            #verify
-            self.assertEqual(writer_doc.Text.String[0:14], "Aaaaaaaaaaaaaa")
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+                #verify
+                self.assertEqual(writer_doc.Text.String[0:14], 
"Aaaaaaaaaaaaaa")
 
             #enable lang support again
             with 
self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as 
xDialog:
diff --git a/sw/qa/uitest/findReplace/tdf119462.py 
b/sw/qa/uitest/findReplace/tdf119462.py
index c892584ed155..fa30ce500bfa 100644
--- a/sw/qa/uitest/findReplace/tdf119462.py
+++ b/sw/qa/uitest/findReplace/tdf119462.py
@@ -16,24 +16,21 @@ class tdf119462(UITestCase):
         with self.ui_test.create_doc_in_start_center("writer"):
             xWriterDoc = self.xUITest.getTopFocusWindow()
             #1. Choose Edit > Find and Replace
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            #2. Choose Format
-            format = xDialog.getChild("format")
-            with self.ui_test.execute_blocking_action(format.executeAction, 
args=('CLICK', ())) as dialog:
-                #3. Choose Bold
-                xTabs = dialog.getChild("tabcontrol")
-                select_pos(xTabs, "0")
-                xweststylelbcjk = dialog.getChild("weststylelb-cjk")
-                xweststylelbcjk.executeAction("TYPE", 
mkPropertyValues({"TEXT":"Bold"}))
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SearchDialog",
 close_button="close") as xDialog:
+                #2. Choose Format
+                format = xDialog.getChild("format")
+                with 
self.ui_test.execute_blocking_action(format.executeAction, args=('CLICK', ())) 
as dialog:
+                    #3. Choose Bold
+                    xTabs = dialog.getChild("tabcontrol")
+                    select_pos(xTabs, "0")
+                    xweststylelbcjk = dialog.getChild("weststylelb-cjk")
+                    xweststylelbcjk.executeAction("TYPE", 
mkPropertyValues({"TEXT":"Bold"}))
 
-            #verify label searchdesc
-            searchdesc = xDialog.getChild("searchdesc")
-            self.assertEqual(get_state_as_dict(searchdesc)["Text"], "bold")
-            noformat = xDialog.getChild("noformat")
-            noformat.executeAction("CLICK", tuple())   #click No format button
-            self.assertEqual(get_state_as_dict(searchdesc)["Text"], "")
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+                #verify label searchdesc
+                searchdesc = xDialog.getChild("searchdesc")
+                self.assertEqual(get_state_as_dict(searchdesc)["Text"], "bold")
+                noformat = xDialog.getChild("noformat")
+                noformat.executeAction("CLICK", tuple())   #click No format 
button
+                self.assertEqual(get_state_as_dict(searchdesc)["Text"], "")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/findReplace/tdf126627.py 
b/sw/qa/uitest/findReplace/tdf126627.py
index b5a6d61f9955..da7581796d16 100644
--- a/sw/qa/uitest/findReplace/tdf126627.py
+++ b/sw/qa/uitest/findReplace/tdf126627.py
@@ -15,16 +15,13 @@ class tdf126627(UITestCase):
         with self.ui_test.load_file(get_url_for_data_file("tdf126627.odt")) as 
writer_doc:
             xWriterDoc = self.xUITest.getTopFocusWindow()
             xWriterEdit = xWriterDoc.getChild("writer_edit")
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
+            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":"bar"}))
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())
+                searchterm = xDialog.getChild("searchterm")
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"bar"}))
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
 
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
             #2. Place the cursor before 'bar'
             xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"LEFT"}))
             xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"LEFT"}))
@@ -38,11 +35,8 @@ class tdf126627(UITestCase):
             #4. Undo once-> Crash
             self.xUITest.executeCommand(".uno:Undo")
             #verify that we have now two words
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            xselectwords = xDialog.getChild("selectwords")
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+                xselectwords = xDialog.getChild("selectwords")
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/findReplace/tdf144089.py 
b/sw/qa/uitest/findReplace/tdf144089.py
index 2957867aa338..5f71c6a01742 100644
--- a/sw/qa/uitest/findReplace/tdf144089.py
+++ b/sw/qa/uitest/findReplace/tdf144089.py
@@ -20,26 +20,23 @@ class tdf144089(UITestCase):
 
             self.assertEqual("test", document.CurrentSelection[0].String)
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            xSearchterm = xDialog.getChild("searchterm")
-            xSearchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            xSearchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            xSearchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"^."}))
-
-            xReplaceterm = xDialog.getChild("replaceterm")
-            xReplaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"A"}))
-
-            xSelectionOnly = xDialog.getChild("selection")
-            xSelectionOnly.executeAction("CLICK", tuple())
-
-            xRegexp = xDialog.getChild("regexp")
-            xRegexp.executeAction("CLICK", tuple())
-
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.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:
+                xSearchterm = xDialog.getChild("searchterm")
+                xSearchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                xSearchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                xSearchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"^."}))
+
+                xReplaceterm = xDialog.getChild("replaceterm")
+                xReplaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"A"}))
+
+                xSelectionOnly = xDialog.getChild("selection")
+                xSelectionOnly.executeAction("CLICK", tuple())
+
+                xRegexp = xDialog.getChild("regexp")
+                xRegexp.executeAction("CLICK", tuple())
+
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple())
 
             # Without the fix in place, this test would have failed with
             # AssertionError: 'This is a test' != 'This is a AAAA'
diff --git a/sw/qa/uitest/findReplace/tdf44837.py 
b/sw/qa/uitest/findReplace/tdf44837.py
index 66b3840fd9c9..ace6a8afcbd7 100644
--- a/sw/qa/uitest/findReplace/tdf44837.py
+++ b/sw/qa/uitest/findReplace/tdf44837.py
@@ -19,21 +19,18 @@ class tdf44837(UITestCase):
             type_text(xWriterEdit, "asd asd")
             self.xUITest.executeCommand(".uno:SelectAll")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"a"}))
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"b"})) 
#replace textbox
-
-            selectionOnly = xDialog.getChild("selection")
-            selectionOnly.executeAction("CLICK", tuple())
-            replaceall = xDialog.getChild("replaceall")
-            replaceall.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({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"a"}))
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"b"})) #replace textbox
+
+                selectionOnly = xDialog.getChild("selection")
+                selectionOnly.executeAction("CLICK", tuple())
+                replaceall = xDialog.getChild("replaceall")
+                replaceall.executeAction("CLICK", tuple())
 
             self.assertEqual(document.Text.String[0:8], "bsd bsd")
             self.assertEqual(len(document.CurrentSelection[0].String) > 1, 
True)
diff --git a/sw/qa/uitest/macro_tests/tdf64690.py 
b/sw/qa/uitest/macro_tests/tdf64690.py
index cd953d8ca2c0..00fe6f7aa802 100644
--- a/sw/qa/uitest/macro_tests/tdf64690.py
+++ b/sw/qa/uitest/macro_tests/tdf64690.py
@@ -34,35 +34,32 @@ class tdf64690(UITestCase):
 
             self.xUITest.executeCommand(".uno:SelectAll")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
+            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({"KEYCODE":"CTRL+A"}))
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
-            searchterm.executeAction("TYPE", mkPropertyValues({"TEXT":"."}))
+                searchterm = xDialog.getChild("searchterm")
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"BACKSPACE"}))
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"."}))
 
-            replaceterm = xDialog.getChild("replaceterm")
-            replaceterm.executeAction("TYPE", mkPropertyValues({"TEXT":"ABC"}))
+                replaceterm = xDialog.getChild("replaceterm")
+                replaceterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"ABC"}))
 
-            regexp = xDialog.getChild("regexp")
-            if get_state_as_dict(regexp)['Selected'] == 'false':
-                regexp.executeAction("CLICK", tuple())
-            self.assertEqual("true", get_state_as_dict(regexp)['Selected'])
+                regexp = xDialog.getChild("regexp")
+                if get_state_as_dict(regexp)['Selected'] == 'false':
+                    regexp.executeAction("CLICK", tuple())
+                self.assertEqual("true", get_state_as_dict(regexp)['Selected'])
 
-            selection = xDialog.getChild("selection")
-            if get_state_as_dict(selection)['Selected'] == 'false':
-                selection.executeAction("CLICK", tuple())
-            self.assertEqual("true", get_state_as_dict(selection)['Selected'])
+                selection = xDialog.getChild("selection")
+                if get_state_as_dict(selection)['Selected'] == 'false':
+                    selection.executeAction("CLICK", tuple())
+                self.assertEqual("true", 
get_state_as_dict(selection)['Selected'])
 
-            replaceall = xDialog.getChild("replaceall")
+                replaceall = xDialog.getChild("replaceall")
 
-            # Without the fix in place, this test would have hung here
-            with 
self.ui_test.execute_blocking_action(replaceall.executeAction, args=('CLICK', 
())):
-                pass
+                # Without the fix in place, this test would have hung here
+                with 
self.ui_test.execute_blocking_action(replaceall.executeAction, args=('CLICK', 
())):
+                    pass
 
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
 
             self.assertEqual("ABCABCABCABC\nABCABCABCABC\n", 
get_state_as_dict(xEditWin)['Text'])
 
diff --git a/sw/qa/uitest/ui/index/index.py b/sw/qa/uitest/ui/index/index.py
index abfe9e27cd2d..b203c9de9e62 100644
--- a/sw/qa/uitest/ui/index/index.py
+++ b/sw/qa/uitest/ui/index/index.py
@@ -19,25 +19,22 @@ class TestSwuiidxmrk(UITestCase):
         # Given an empty Writer document:
         with self.ui_test.create_doc_in_start_center("writer") as component:
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:InsertAuthoritiesEntry")
-            insert_entry = self.xUITest.getTopFocusWindow()
-            from_document = insert_entry.getChild("fromdocument")
-            from_document.executeAction("CLICK", tuple())
-            new = insert_entry.getChild("new")
-
-            # When inserting a biblio entry field with a page number:
-            with self.ui_test.execute_blocking_action(new.executeAction, 
args=('CLICK', ())) as define_entry:
-                entry = define_entry.getChild("entry")
-                type_text(entry, "aaa")
-                listbox = define_entry.getChild("listbox")
-                select_pos(listbox, "16")  # WWW document, just select a valid 
position
-                pagecb = define_entry.getChild("pagecb-local-visible")
-                pagecb.executeAction("CLICK", tuple())
-
-            insert = insert_entry.getChild("insert")
-            insert.executeAction("CLICK", tuple())
-            close = insert_entry.getChild("close")
-            self.ui_test.close_dialog_through_button(close)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:InsertAuthoritiesEntry",
 close_button="close") as insert_entry:
+                from_document = insert_entry.getChild("fromdocument")
+                from_document.executeAction("CLICK", tuple())
+                new = insert_entry.getChild("new")
+
+                # When inserting a biblio entry field with a page number:
+                with self.ui_test.execute_blocking_action(new.executeAction, 
args=('CLICK', ())) as define_entry:
+                    entry = define_entry.getChild("entry")
+                    type_text(entry, "aaa")
+                    listbox = define_entry.getChild("listbox")
+                    select_pos(listbox, "16")  # WWW document, just select a 
valid position
+                    pagecb = define_entry.getChild("pagecb-local-visible")
+                    pagecb.executeAction("CLICK", tuple())
+
+                insert = insert_entry.getChild("insert")
+                insert.executeAction("CLICK", tuple())
 
             # Then make sure the local URL contains that page number:
             paragraphs = component.Text.createEnumeration()
diff --git a/sw/qa/uitest/writer_tests/compareDocuments.py 
b/sw/qa/uitest/writer_tests/compareDocuments.py
index a8e0f21d87f9..bc21b53aedba 100644
--- a/sw/qa/uitest/writer_tests/compareDocuments.py
+++ b/sw/qa/uitest/writer_tests/compareDocuments.py
@@ -29,17 +29,14 @@ class compareDocuments(UITestCase):
                 with self.ui_test.execute_dialog_through_action(xOpenBtn, 
'CLICK', close_button="close"):
                     pass
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
-            changesList = xTrackDlg.getChild("writerchanges")
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
+                changesList = xTrackDlg.getChild("writerchanges")
 
-            text = "Unknown Author\t" + 
datetime.datetime.now().strftime("%m/%d/%Y")
-            self.assertEqual(2, len(changesList.getChildren()))
-            
self.assertTrue(get_state_as_dict(changesList.getChild('0'))["Text"].startswith(text))
-            
self.assertTrue(get_state_as_dict(changesList.getChild('1'))["Text"].startswith(text))
+                text = "Unknown Author\t" + 
datetime.datetime.now().strftime("%m/%d/%Y")
+                self.assertEqual(2, len(changesList.getChildren()))
+                
self.assertTrue(get_state_as_dict(changesList.getChild('0'))["Text"].startswith(text))
+                
self.assertTrue(get_state_as_dict(changesList.getChild('1'))["Text"].startswith(text))
 
-            xcloseBtn = xTrackDlg.getChild("close")
-            xcloseBtn.executeAction("CLICK", tuple())
 
     def test_tdf137855(self):
 
@@ -57,20 +54,17 @@ class compareDocuments(UITestCase):
                 with self.ui_test.execute_dialog_through_action(xOpenBtn, 
'CLICK', close_button="close"):
                     pass
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
-            changesList = xTrackDlg.getChild("writerchanges")
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
+                changesList = xTrackDlg.getChild("writerchanges")
 
-            # Check the number of changes
-            self.assertEqual(263, len(changesList.getChildren()))
+                # Check the number of changes
+                self.assertEqual(263, len(changesList.getChildren()))
 
-            # Without the fix in place, this test would have crashed here
-            xAccBtn = xTrackDlg.getChild("acceptall")
-            xAccBtn.executeAction("CLICK", tuple())
+                # Without the fix in place, this test would have crashed here
+                xAccBtn = xTrackDlg.getChild("acceptall")
+                xAccBtn.executeAction("CLICK", tuple())
 
-            self.assertEqual(0, len(changesList.getChildren()))
+                self.assertEqual(0, len(changesList.getChildren()))
 
-            xcloseBtn = xTrackDlg.getChild("close")
-            xcloseBtn.executeAction("CLICK", tuple())
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/writer_tests/trackedChanges.py 
b/sw/qa/uitest/writer_tests/trackedChanges.py
index f1eb2fb23f4a..fafa93714cca 100644
--- a/sw/qa/uitest/writer_tests/trackedChanges.py
+++ b/sw/qa/uitest/writer_tests/trackedChanges.py
@@ -23,11 +23,8 @@ class trackedchanges(UITestCase):
             selection = self.xUITest.executeCommand(".uno:SelectAll")  #select 
whole text
             self.xUITest.executeCommand(".uno:Cut")   #cut  text
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
-            xCancBtn = xTrackDlg.getChild("close")
-            xCancBtn.executeAction("CLICK", tuple())
-
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close"):
+                pass
 
     def test_tracked_changes_accept(self):
 
@@ -39,12 +36,9 @@ class trackedchanges(UITestCase):
             type_text(xWriterEdit, "Test LibreOffice")
             self.xUITest.executeCommand(".uno:ShowTrackedChanges")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
-            xAccBtn = xTrackDlg.getChild("accept")
-            xAccBtn.executeAction("CLICK", tuple())
-            xCancBtn = xTrackDlg.getChild("close")
-            xCancBtn.executeAction("CLICK", tuple())
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
+                xAccBtn = xTrackDlg.getChild("accept")
+                xAccBtn.executeAction("CLICK", tuple())
 
             self.assertEqual(document.Text.String[0:16], "Test LibreOffice")
 
@@ -58,13 +52,10 @@ class trackedchanges(UITestCase):
             type_text(xWriterEdit, "Test LibreOffice")
             self.xUITest.executeCommand(".uno:ShowTrackedChanges")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
 
-            xAccBtn = xTrackDlg.getChild("acceptall")
-            xAccBtn.executeAction("CLICK", tuple())
-            xCancBtn = xTrackDlg.getChild("close")
-            xCancBtn.executeAction("CLICK", tuple())
+                xAccBtn = xTrackDlg.getChild("acceptall")
+                xAccBtn.executeAction("CLICK", tuple())
 
 
             self.assertEqual(document.Text.String[0:16], "Test LibreOffice")
@@ -79,13 +70,10 @@ class trackedchanges(UITestCase):
             type_text(xWriterEdit, "Test LibreOffice")
             self.xUITest.executeCommand(".uno:ShowTrackedChanges")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
 
-            xRejBtn = xTrackDlg.getChild("reject")
-            xRejBtn.executeAction("CLICK", tuple())
-            xCancBtn = xTrackDlg.getChild("close")
-            xCancBtn.executeAction("CLICK", tuple())
+                xRejBtn = xTrackDlg.getChild("reject")
+                xRejBtn.executeAction("CLICK", tuple())
 
             self.assertEqual(document.Text.String[0:1], "")
 
@@ -99,13 +87,10 @@ class trackedchanges(UITestCase):
             type_text(xWriterEdit, "Test LibreOffice")
             self.xUITest.executeCommand(".uno:ShowTrackedChanges")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
 
-            xAccBtn = xTrackDlg.getChild("rejectall")
-            xAccBtn.executeAction("CLICK", tuple())
-            xCancBtn = xTrackDlg.getChild("close")
-            xCancBtn.executeAction("CLICK", tuple())
+                xAccBtn = xTrackDlg.getChild("rejectall")
+                xAccBtn.executeAction("CLICK", tuple())
 
             self.assertEqual(document.Text.String[0:1], "")
 
@@ -151,60 +136,57 @@ class trackedchanges(UITestCase):
                     "Unknown Author\t01/24/2020 16:19:39\t",
                     "Xisco Fauli\t01/27/2020 17:42:55\t"]
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
-            changesList = xTrackDlg.getChild("writerchanges")
-
-            resultsAccept = [
-                "The tennis ball is a small ball. The baskedtball is much 
bigger.",
-                "The tennis ball is a small ball. The baskedtball is much 
bigger.",
-                "The tennis ball is a small ball. The baskedtball is much 
bigger.",
-                "The tennis ball is a small ball. The basketball is much 
bigger.",
-                "The tennis ball is a small ball. The basketball is much 
bigger.",
-                "The tennis ball is a small ball. The basketball is much 
bigger."]
-
-            for i in range(len(listText)):
-                self.assertEqual(document.Text.String.strip(), 
resultsAccept[i])
-                
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
-                xAccBtn = xTrackDlg.getChild("accept")
-                xAccBtn.executeAction("CLICK", tuple())
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
+                changesList = xTrackDlg.getChild("writerchanges")
+
+                resultsAccept = [
+                    "The tennis ball is a small ball. The baskedtball is much 
bigger.",
+                    "The tennis ball is a small ball. The baskedtball is much 
bigger.",
+                    "The tennis ball is a small ball. The baskedtball is much 
bigger.",
+                    "The tennis ball is a small ball. The basketball is much 
bigger.",
+                    "The tennis ball is a small ball. The basketball is much 
bigger.",
+                    "The tennis ball is a small ball. The basketball is much 
bigger."]
+
+                for i in range(len(listText)):
+                    self.assertEqual(document.Text.String.strip(), 
resultsAccept[i])
+                    
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
+                    xAccBtn = xTrackDlg.getChild("accept")
+                    xAccBtn.executeAction("CLICK", tuple())
+
+                self.assertEqual(document.Text.String.strip(), 
resultsAccept[5])
+                #List is empty
+                self.assertFalse('0' in changesList.getChildren())
+
+                for i in reversed(range(len(listText))):
+                    xUndoBtn = xTrackDlg.getChild("undo")
+                    xUndoBtn.executeAction("CLICK", tuple())
+                    self.assertEqual(document.Text.String.strip(), 
resultsAccept[i])
+                    
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
+
+                resultsReject = [
+                    "The tennis ball is a small ball. The baskedtball is much 
bigger.",
+                    "The tenis ball is a small ball. The baskedtball is much 
bigger.",
+                    "The tenis ball is a small bal. The baskedtball is much 
bigger.",
+                    "The tenis ball is a small bal. The baskedtball is much 
bigger.",
+                    "The tenis ball is a small bal. The baskedball is much 
bigger.",
+                    "The tenis ball is a small bal. The baskedball is much 
biger."]
+
+                for i in range(len(listText)):
+                    self.assertEqual(document.Text.String.strip(), 
resultsReject[i])
+                    
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
+                    xAccBtn = xTrackDlg.getChild("reject")
+                    xAccBtn.executeAction("CLICK", tuple())
+
+                self.assertEqual(document.Text.String.strip(), 
resultsReject[5])
+                #List is empty
+                self.assertFalse('0' in changesList.getChildren())
+
+                for i in reversed(range(len(listText))):
+                    xUndoBtn = xTrackDlg.getChild("undo")
+                    xUndoBtn.executeAction("CLICK", tuple())
+                    self.assertEqual(document.Text.String.strip(), 
resultsReject[i])
+                    
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
 
-            self.assertEqual(document.Text.String.strip(), resultsAccept[5])
-            #List is empty
-            self.assertFalse('0' in changesList.getChildren())
-
-            for i in reversed(range(len(listText))):
-                xUndoBtn = xTrackDlg.getChild("undo")
-                xUndoBtn.executeAction("CLICK", tuple())
-                self.assertEqual(document.Text.String.strip(), 
resultsAccept[i])
-                
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
-
-            resultsReject = [
-                "The tennis ball is a small ball. The baskedtball is much 
bigger.",
-                "The tenis ball is a small ball. The baskedtball is much 
bigger.",
-                "The tenis ball is a small bal. The baskedtball is much 
bigger.",
-                "The tenis ball is a small bal. The baskedtball is much 
bigger.",
-                "The tenis ball is a small bal. The baskedball is much 
bigger.",
-                "The tenis ball is a small bal. The baskedball is much biger."]
-
-            for i in range(len(listText)):
-                self.assertEqual(document.Text.String.strip(), 
resultsReject[i])
-                
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
-                xAccBtn = xTrackDlg.getChild("reject")
-                xAccBtn.executeAction("CLICK", tuple())
-
-            self.assertEqual(document.Text.String.strip(), resultsReject[5])
-            #List is empty
-            self.assertFalse('0' in changesList.getChildren())
-
-            for i in reversed(range(len(listText))):
-                xUndoBtn = xTrackDlg.getChild("undo")
-                xUndoBtn.executeAction("CLICK", tuple())
-                self.assertEqual(document.Text.String.strip(), 
resultsReject[i])
-                
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], 
listText[i] )
-
-            xcloseBtn = xTrackDlg.getChild("close")
-            xcloseBtn.executeAction("CLICK", tuple())
 
     def test_tdf135018(self):
         with self.ui_test.load_file(get_url_for_data_file("tdf135018.odt")) as 
document:
@@ -213,24 +195,21 @@ class trackedchanges(UITestCase):
 
             self.assertEqual(5, document.CurrentController.PageCount)
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges")
-            xTrackDlg = self.xUITest.getTopFocusWindow()
-            changesList = xTrackDlg.getChild("writerchanges")
-            self.assertEqual(147, len(changesList.getChildren()))
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:AcceptTrackedChanges",
 close_button="close") as xTrackDlg:
+                changesList = xTrackDlg.getChild("writerchanges")
+                self.assertEqual(147, len(changesList.getChildren()))
 
-            # Without the fix in place, it would have crashed here
-            xAccBtn = xTrackDlg.getChild("acceptall")
-            xAccBtn.executeAction("CLICK", tuple())
+                # Without the fix in place, it would have crashed here
+                xAccBtn = xTrackDlg.getChild("acceptall")
+                xAccBtn.executeAction("CLICK", tuple())
 
-            self.assertEqual(0, len(changesList.getChildren()))
+                self.assertEqual(0, len(changesList.getChildren()))
 
-            xUndoBtn = xTrackDlg.getChild("undo")
-            xUndoBtn.executeAction("CLICK", tuple())
+                xUndoBtn = xTrackDlg.getChild("undo")
+                xUndoBtn.executeAction("CLICK", tuple())
 
-            self.assertEqual(147, len(changesList.getChildren()))
+                self.assertEqual(147, len(changesList.getChildren()))
 
-            xcloseBtn = xTrackDlg.getChild("close")
-            xcloseBtn.executeAction("CLICK", tuple())
 
             # Check the changes are shown after opening the Manage Tracked 
Changes dialog
             self.assertGreater(document.CurrentController.PageCount, 5)
diff --git a/sw/qa/uitest/writer_tests/wordCount.py 
b/sw/qa/uitest/writer_tests/wordCount.py
index 00d2e5963f60..4e0fe9298dcd 100644
--- a/sw/qa/uitest/writer_tests/wordCount.py
+++ b/sw/qa/uitest/writer_tests/wordCount.py
@@ -20,28 +20,25 @@ class writerWordCount(UITestCase):
             type_text(xWriterEdit, "Test for word count dialog") #type text
             xWriterEdit.executeAction("SELECT", mkPropertyValues({"START_POS": 
"0", "END_POS": "8"})) #select two words
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "8")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "26")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"7")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"22")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "8")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "26")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "7")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"22")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
 
 
     def test_tdf68347(self):
@@ -52,64 +49,55 @@ class writerWordCount(UITestCase):
 
             xWriterEdit.executeAction("SELECT", mkPropertyValues({"START_POS": 
"24", "END_POS": "39"})) #select two words
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "4")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "12")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "15")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "54")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"12")
-            #Bug 117703 Word Count: Wrong result for "Characters excluding 
spaces"
-            #self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"44")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "4")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "12")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "15")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "54")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "12")
+                #Bug 117703 Word Count: Wrong result for "Characters excluding 
spaces"
+                
#self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], "44")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
 
     def test_tdf91100(self):
         with self.ui_test.create_doc_in_start_center("writer") as document:
             xWriterDoc = self.xUITest.getTopFocusWindow()
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
-
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close"):
+                pass
 
     def test_tdf58050(self):
         with self.ui_test.load_file(get_url_for_data_file("tdf58050.html")) as 
writer_doc:
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "3")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "14")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"0")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"12")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "3")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "14")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"12")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
 
     def test_word_count_interpunction_counted_tdf56975_a(self):
 
@@ -119,28 +107,25 @@ class writerWordCount(UITestCase):
             #Open writer, enter "Testing one two! Test?"
             type_text(xWriterEdit, "Testing one two! Test?")
             #-> LO says: 4 words. SUCCESS! :)
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "4")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "22")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"0")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"19")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "4")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "22")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"19")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
 
 
     def test_word_count_interpunction_counted_tdf56975_b(self):
@@ -154,80 +139,71 @@ class writerWordCount(UITestCase):
             type_text(xWriterEdit, "This is a test sentence.")
             #3. Open the word count dialogue.
             #   Word count in both, dialogue and status line, shows 5 words.
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "24")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"0")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"20")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "24")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"20")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
             #4. Select the space between 'a' and 'test'.
             xWriterEdit.executeAction("SELECT", mkPropertyValues({"START_POS": 
"9", "END_POS": "10"}))
             #5. Replace selection by a non-breaking space by pressing 
Shift+Ctrl+Space.  Don't move the cursor.
             self.xUITest.executeCommand(".uno:InsertNonBreakingSpace")
             #   Word count in dialogue shows 4 words, whereas in the status 
line it shows 5 words.
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "24")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"0")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"20")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "24")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"20")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
             #6. Move the cursor by pressing Left.
             self.xUITest.executeCommand(".uno:GoLeft")
             #   Word count in both, dialogue and status line, shows 5 words.
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "24")
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"0")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"20")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "5")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "24")
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "0")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"20")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
 
     def test_tdf51816(self):
         with self.ui_test.load_file(get_url_for_data_file("tdf51816.odt")) as 
writer_doc:
@@ -235,46 +211,43 @@ class writerWordCount(UITestCase):
             xWriterEdit = xWriterDoc.getChild("writer_edit")
             #1. Open attached document
             #2. Tools> Word count
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            #3. Click after "At nunc" then <Ctrl><Shift><Left>
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:GoRight")
-            self.xUITest.executeCommand(".uno:WordLeftSel")
-
-            #needs to wait, because Word count dialog is already open and it 
takes time to refresh the counter
-            #Expected result : Words 1 & Characters 4 #Actual result : Words 0 
& Characters 0
-            self.ui_test.wait_until_property_is_updated(xselectwords, "Text", 
"1")
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "1")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "4")
-
-            #4. Click after "At nunc" then <Shift><Home>
-            self.xUITest.executeCommand(".uno:StartOfParaSel")
-
-            #needs to wait, because Word count dialog is already open and it 
takes time to refresh the counter
-            #Expected result : Words 2 & Characters 7 & excluding space 6  
#Actual result : Words 0 & Characters 0
-            self.ui_test.wait_until_property_is_updated(xselectwords, "Text", 
"2")
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "7")
-
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"6")
-
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                #3. Click after "At nunc" then <Ctrl><Shift><Left>
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:GoRight")
+                self.xUITest.executeCommand(".uno:WordLeftSel")
+
+                #needs to wait, because Word count dialog is already open and 
it takes time to refresh the counter
+                #Expected result : Words 1 & Characters 4 #Actual result : 
Words 0 & Characters 0
+                self.ui_test.wait_until_property_is_updated(xselectwords, 
"Text", "1")
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "1")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "4")
+
+                #4. Click after "At nunc" then <Shift><Home>
+                self.xUITest.executeCommand(".uno:StartOfParaSel")
+
+                #needs to wait, because Word count dialog is already open and 
it takes time to refresh the counter
+                #Expected result : Words 2 & Characters 7 & excluding space 6  
#Actual result : Words 0 & Characters 0
+                self.ui_test.wait_until_property_is_updated(xselectwords, 
"Text", "2")
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "2")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "7")
+
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "6")
+
 
     def test_tdf117703(self):
         with self.ui_test.load_file(get_url_for_data_file("tdf117703.odt")):
@@ -282,29 +255,26 @@ class writerWordCount(UITestCase):
 
             self.xUITest.executeCommand(".uno:SelectAll")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:WordCountDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xselectwords = xDialog.getChild("selectwords")
-            xdocwords = xDialog.getChild("docwords")
-            xselectchars = xDialog.getChild("selectchars")
-            xdocchars = xDialog.getChild("docchars")
-            xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
-            xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
-            xselectcjkchars = xDialog.getChild("selectcjkchars")
-            xdoccjkchars = xDialog.getChild("doccjkchars")
-
-            self.assertEqual(get_state_as_dict(xselectwords)["Text"], "12")
-            self.assertEqual(get_state_as_dict(xdocwords)["Text"], "12")
-            self.assertEqual(get_state_as_dict(xselectchars)["Text"], "54")
-            self.assertEqual(get_state_as_dict(xdocchars)["Text"], "54")
-
-            # Without the fix in place it would have failed with: 
AssertionError: '0' != '44'
-            self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], 
"44")
-            self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"44")
-            self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], "0")
-            self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
-            xCloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xCloseBtn)
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:WordCountDialog",
 close_button="close") as xDialog:
+
+                xselectwords = xDialog.getChild("selectwords")
+                xdocwords = xDialog.getChild("docwords")
+                xselectchars = xDialog.getChild("selectchars")
+                xdocchars = xDialog.getChild("docchars")
+                xselectcharsnospaces = xDialog.getChild("selectcharsnospaces")
+                xdoccharsnospaces = xDialog.getChild("doccharsnospaces")
+                xselectcjkchars = xDialog.getChild("selectcjkchars")
+                xdoccjkchars = xDialog.getChild("doccjkchars")
+
+                self.assertEqual(get_state_as_dict(xselectwords)["Text"], "12")
+                self.assertEqual(get_state_as_dict(xdocwords)["Text"], "12")
+                self.assertEqual(get_state_as_dict(xselectchars)["Text"], "54")
+                self.assertEqual(get_state_as_dict(xdocchars)["Text"], "54")
+
+                # Without the fix in place it would have failed with: 
AssertionError: '0' != '44'
+                
self.assertEqual(get_state_as_dict(xselectcharsnospaces)["Text"], "44")
+                self.assertEqual(get_state_as_dict(xdoccharsnospaces)["Text"], 
"44")
+                self.assertEqual(get_state_as_dict(xselectcjkchars)["Text"], 
"0")
+                self.assertEqual(get_state_as_dict(xdoccjkchars)["Text"], "0")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/writer_tests2/asianPhoneticGuide.py 
b/sw/qa/uitest/writer_tests2/asianPhoneticGuide.py
index 5304a692d9f6..80b68f5ba687 100644
--- a/sw/qa/uitest/writer_tests2/asianPhoneticGuide.py
+++ b/sw/qa/uitest/writer_tests2/asianPhoneticGuide.py
@@ -14,26 +14,22 @@ class asianPhoneticGuide(UITestCase):
         with self.ui_test.create_doc_in_start_center("writer") as document:
             xWriterDoc = self.xUITest.getTopFocusWindow()
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:RubyDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-
-            xLeft1ED = xDialog.getChild("Left1ED")
-            xRight1ED = xDialog.getChild("Right1ED")
-            xadjustlb = xDialog.getChild("adjustlb")
-            xpositionlb = xDialog.getChild("positionlb")
-            xstylelb = xDialog.getChild("stylelb")
-
-            xLeft1ED.executeAction("TYPE", mkPropertyValues({"TEXT":"a"}))
-            xRight1ED.executeAction("TYPE", mkPropertyValues({"TEXT":"w"}))
-            select_by_text(xadjustlb, "Right")
-            select_by_text(xpositionlb, "Right")
-            select_by_text(xstylelb, "Quotation")
-
-            xApplyBtn = xDialog.getChild("ok")
-            xApplyBtn.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:RubyDialog", 
close_button="close") as xDialog:
+
+                xLeft1ED = xDialog.getChild("Left1ED")
+                xRight1ED = xDialog.getChild("Right1ED")
+                xadjustlb = xDialog.getChild("adjustlb")
+                xpositionlb = xDialog.getChild("positionlb")
+                xstylelb = xDialog.getChild("stylelb")
+
+                xLeft1ED.executeAction("TYPE", mkPropertyValues({"TEXT":"a"}))
+                xRight1ED.executeAction("TYPE", mkPropertyValues({"TEXT":"w"}))
+                select_by_text(xadjustlb, "Right")
+                select_by_text(xpositionlb, "Right")
+                select_by_text(xstylelb, "Quotation")
+
+                xApplyBtn = xDialog.getChild("ok")
+                xApplyBtn.executeAction("CLICK", tuple())
 
             self.assertEqual(document.Text.String[0:1], "a")
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/uitest/writer_tests4/spellDialog.py 
b/sw/qa/uitest/writer_tests4/spellDialog.py
index 1532fc025a1c..13cc43542fda 100644
--- a/sw/qa/uitest/writer_tests4/spellDialog.py
+++ b/sw/qa/uitest/writer_tests4/spellDialog.py
@@ -28,12 +28,6 @@ class SpellingAndGrammarDialog(UITestCase):
             # we found the correct combination
             return True
 
-    def launch_dialog(self):
-        self.ui_test.execute_modeless_dialog_through_command(
-            ".uno:SpellingAndGrammarDialog")
-
-        return self.xUITest.getTopFocusWindow()
-
     TDF46852_INPUT = """\
 dogg
 dogg
@@ -72,34 +66,33 @@ frog, dogg, catt"""
 
             # Step 3: Initiate spellchecking, and make sure "Check grammar" is
             # unchecked
-            spell_dialog = self.launch_dialog()
-            checkgrammar = spell_dialog.getChild('checkgrammar')
-            if get_state_as_dict(checkgrammar)['Selected'] == 'true':
-                checkgrammar.executeAction('CLICK', ())
-            self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 
'false')
-
-            # Step 4: Repetitively click on "Correct all" for each misspelling
-            #         prompt until end of document is reached.
-            changeall = spell_dialog.getChild('changeall')
-            changeall.executeAction("CLICK", ())
-            changeall.executeAction("CLICK", ())
-            # The third time we click on changeall, the click action is going 
to
-            # block while two message boxes are shown, so we need to do this 
third
-            # click specially
-            # Use empty close_button to open consecutive dialogs
-            with self.ui_test.execute_blocking_action(
-                    changeall.executeAction, args=('CLICK', ()), 
close_button="") as dialog:
-                # Step 5: Confirm to "Continue check at beginning of document"
-                xYesBtn = dialog.getChild("yes")
-
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SpellingAndGrammarDialog",
 close_button="") as xDialog:
+                checkgrammar = xDialog.getChild('checkgrammar')
+                if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+                    checkgrammar.executeAction('CLICK', ())
+                self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 
'false')
+
+                # Step 4: Repetitively click on "Correct all" for each 
misspelling
+                #         prompt until end of document is reached.
+                changeall = xDialog.getChild('changeall')
+                changeall.executeAction("CLICK", ())
+                changeall.executeAction("CLICK", ())
+                # The third time we click on changeall, the click action is 
going to
+                # block while two message boxes are shown, so we need to do 
this third
+                # click specially
+                # Use empty close_button to open consecutive dialogs
                 with self.ui_test.execute_blocking_action(
-                        xYesBtn.executeAction, args=('CLICK', ())):
-                    pass
+                        changeall.executeAction, args=('CLICK', ()), 
close_button="") as dialog:
+                    # Step 5: Confirm to "Continue check at beginning of 
document"
+                    xYesBtn = dialog.getChild("yes")
+
+                    with self.ui_test.execute_blocking_action(
+                            xYesBtn.executeAction, args=('CLICK', ())):
+                        pass
 
             output_text = document.Text.getString().replace('\r\n', '\n')
             self.assertTrue(re.match(self.TDF46852_REGEX, output_text))
 
-
     def test_tdf66043(self):
         supported_locale = self.is_supported_locale("en", "US")
         if not supported_locale:
@@ -107,19 +100,16 @@ frog, dogg, catt"""
         with self.ui_test.load_file(get_url_for_data_file("tdf66043.fodt")) as 
writer_doc:
             # Step 1: Initiate spellchecking, and make sure "Check grammar" is
             # unchecked
-            spell_dialog = self.launch_dialog()
-            checkgrammar = spell_dialog.getChild('checkgrammar')
-            if get_state_as_dict(checkgrammar)['Selected'] == 'true':
-                checkgrammar.executeAction('CLICK', ())
-            self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 
'false')
-
-            # Step 2: Click on "Correct all" for each misspelling
-            #         prompt until end of document is reached.
-            changeall = spell_dialog.getChild('changeall')
-            changeall.executeAction("CLICK", ())
-
-            xCloseBtn = spell_dialog.getChild("close")
-            xCloseBtn.executeAction("CLICK", tuple())
+            with 
self.ui_test.execute_modeless_dialog_through_command_guarded(".uno:SpellingAndGrammarDialog",
 close_button="close") as xDialog:
+                checkgrammar = xDialog.getChild('checkgrammar')
+                if get_state_as_dict(checkgrammar)['Selected'] == 'true':
+                    checkgrammar.executeAction('CLICK', ())
+                self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 
'false')
+
+                # Step 2: Click on "Correct all" for each misspelling
+                #         prompt until end of document is reached.
+                changeall = xDialog.getChild('changeall')
+                changeall.executeAction("CLICK", ())
 
             output_text = writer_doc.Text.getString().replace('\r\n', '\n')
             # This was "gooodgood baaad eeend" ("goood" is a deletion,
diff --git a/sw/qa/uitest/writer_tests4/tdf122449.py 
b/sw/qa/uitest/writer_tests4/tdf122449.py
index c071745d024c..eb1f34c4d248 100644
--- a/sw/qa/uitest/writer_tests4/tdf122449.py
+++ b/sw/qa/uitest/writer_tests4/tdf122449.py
@@ -18,17 +18,14 @@ class tdf122449(UITestCase):
             xWriterDoc = self.xUITest.getTopFocusWindow()
             xWriterEdit = xWriterDoc.getChild("writer_edit")
             #search word Autocorrect (second find)   .uno:SearchDialog
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
+            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":"Autocorrection"}))
-            xsearch = xDialog.getChild("search")
-            xsearch.executeAction("CLICK", tuple())  #first search
-            xsearch.executeAction("CLICK", tuple())  #2nd search
-            self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], 
"6")
-            xcloseBtn = xDialog.getChild("close")
-            self.ui_test.close_dialog_through_button(xcloseBtn)
+                searchterm = xDialog.getChild("searchterm")
+                searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"Autocorrection"}))
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())  #first search
+                xsearch.executeAction("CLICK", tuple())  #2nd search
+                
self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "6")
             xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"HOME"}))
             # invoke Index dialog Index entry   .uno:IndexEntryDialog
             with 
self.ui_test.execute_dialog_through_command(".uno:IndexEntryDialog", 
close_button="close"):
diff --git a/sw/qa/uitest/writer_tests6/tdf126017.py 
b/sw/qa/uitest/writer_tests6/tdf126017.py
index b2255c31cdeb..4adba3be3b0c 100644
--- a/sw/qa/uitest/writer_tests6/tdf126017.py
+++ b/sw/qa/uitest/writer_tests6/tdf126017.py
@@ -16,14 +16,11 @@ class tdf126017(UITestCase):
             xWriterDoc = self.xUITest.getTopFocusWindow()
 
             #go to TOC
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:SearchDialog")
-            xDialog = self.xUITest.getTopFocusWindow()
-            searchterm = xDialog.getChild("searchterm")
-            searchterm.executeAction("TYPE", 
mkPropertyValues({"TEXT":"aasasas"}))
-            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":"aasasas"}))
+                xsearch = xDialog.getChild("search")
+                xsearch.executeAction("CLICK", tuple())
             #edit index
             with 
self.ui_test.execute_dialog_through_command(".uno:EditCurIndex") as xDiagIndex:
                 title = xDiagIndex.getChild("title")
diff --git a/sw/qa/uitest/writer_tests7/forms.py 
b/sw/qa/uitest/writer_tests7/forms.py
index 8bf828f2e704..5efa7f380d20 100644
--- a/sw/qa/uitest/writer_tests7/forms.py
+++ b/sw/qa/uitest/writer_tests7/forms.py
@@ -18,12 +18,12 @@ class Forms(UITestCase):
 
             self.xUITest.executeCommand(".uno:JumpToNextFrame")
 
-            
self.ui_test.execute_modeless_dialog_through_command(".uno:ControlProperties")
-            xChild = self.ui_test.wait_until_child_is_available('listbox-Empty 
string is NULL')

... etc. - the rest is truncated

Reply via email to