[Libreoffice-commits] core.git: cui/qa svx/qa uitest/demo_ui uitest/impress_tests uitest/math_tests uitest/uitest

Xisco Fauli (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 30 11:19:14 UTC 2021


 cui/qa/uitest/dialogs/chardlg.py          |  125 ++++++++++-----------
 cui/qa/uitest/dialogs/pastedlg.py         |   51 ++++----
 cui/qa/uitest/dialogs/shortcuts.py        |   27 ++--
 svx/qa/uitest/table/tablecontroller.py    |  101 ++++++++---------
 uitest/demo_ui/char_dialog.py             |    9 -
 uitest/demo_ui/checkbox.py                |    9 -
 uitest/demo_ui/combobox.py                |   15 +-
 uitest/demo_ui/command_with_parameters.py |   11 -
 uitest/demo_ui/edit.py                    |   40 +++---
 uitest/demo_ui/gridwin.py                 |   37 ++----
 uitest/demo_ui/hierarchy.py               |   15 +-
 uitest/demo_ui/listbox.py                 |   14 +-
 uitest/demo_ui/radiobutton.py             |    9 -
 uitest/demo_ui/spinfield.py               |   47 +++-----
 uitest/demo_ui/tabcontrol.py              |   23 +--
 uitest/demo_ui/tabdialog.py               |   14 +-
 uitest/demo_ui/treelist.py                |   31 ++---
 uitest/impress_tests/backgrounds.py       |   41 +++----
 uitest/impress_tests/drawinglayer.py      |  174 ++++++++++++++----------------
 uitest/impress_tests/layouts.py           |   41 +++----
 uitest/impress_tests/start.py             |   40 +++---
 uitest/math_tests/start.py                |   73 +++++-------
 uitest/uitest/uihelper/testDialog.py      |   29 ++---
 23 files changed, 465 insertions(+), 511 deletions(-)

New commits:
commit 3874e092da4acbaa076d885444f26f014fd781b5
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Wed Jun 30 11:57:03 2021 +0200
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Wed Jun 30 13:18:38 2021 +0200

    uitest: guard the remaining create_doc_in_start_center
    
    Mostly done by a script
    for motivation, see 89aaa17a0a4413f07da2bc5084b0164f15dc01ac
    < UITest: introduce guarded context managers >
    
    Change-Id: I2a6149b318d1fdaa36efe5d65af4c238827eaaf5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118154
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/cui/qa/uitest/dialogs/chardlg.py b/cui/qa/uitest/dialogs/chardlg.py
index 878f9e2a8ae7..276f7c9a8c53 100644
--- a/cui/qa/uitest/dialogs/chardlg.py
+++ b/cui/qa/uitest/dialogs/chardlg.py
@@ -14,84 +14,79 @@ class Test(UITestCase):
 
     def testSvxCharEffectsPage(self):
         # Start Impress.
-        self.ui_test.create_doc_in_start_center("impress")
-        template = self.xUITest.getTopFocusWindow()
-        self.ui_test.close_dialog_through_button(template.getChild("close"))
-        doc = self.xUITest.getTopFocusWindow()
-        editWin = doc.getChild("impress_win")
-        # Select the title shape.
-        editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
-        editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"}))
-        self.xUITest.executeCommand(".uno:SelectAll")
+        with self.ui_test.create_doc_in_start_center_guarded("impress") as component:
+            template = self.xUITest.getTopFocusWindow()
+            self.ui_test.close_dialog_through_button(template.getChild("close"))
+            doc = self.xUITest.getTopFocusWindow()
+            editWin = doc.getChild("impress_win")
+            # Select the title shape.
+            editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
+            editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"}))
+            self.xUITest.executeCommand(".uno:SelectAll")
 
-        # Now use Format -> Character.
-        with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
-            xTabs = xDialog.getChild("tabcontrol")
-            # Select RID_SVXPAGE_CHAR_EFFECTS.
-            select_pos(xTabs, "1")
-            xFontTransparency = xDialog.getChild("fonttransparencymtr")
-            for _ in range(5):
-                xFontTransparency.executeAction("UP", tuple())
+            # Now use Format -> Character.
+            with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
+                xTabs = xDialog.getChild("tabcontrol")
+                # Select RID_SVXPAGE_CHAR_EFFECTS.
+                select_pos(xTabs, "1")
+                xFontTransparency = xDialog.getChild("fonttransparencymtr")
+                for _ in range(5):
+                    xFontTransparency.executeAction("UP", tuple())
 
-        # Verify the result.
-        component = self.ui_test.get_component()
-        drawPage = component.getDrawPages().getByIndex(0)
-        shape = drawPage.getByIndex(0)
+            # Verify the result.
+            drawPage = component.getDrawPages().getByIndex(0)
+            shape = drawPage.getByIndex(0)
 
-        # Without the accompanying fix in place, this test would have failed with:
-        # AssertionError: 100 != 5
-        # i.e. the dialog did not set transparency to 5%, instead it left the character color at
-        # COL_AUTO.
-        self.assertEqual(shape.CharTransparence, 5)
-        self.ui_test.close_doc()
+            # Without the accompanying fix in place, this test would have failed with:
+            # AssertionError: 100 != 5
+            # i.e. the dialog did not set transparency to 5%, instead it left the character color at
+            # COL_AUTO.
+            self.assertEqual(shape.CharTransparence, 5)
 
     def testSvxCharEffectsPageWriter(self):
         # Start Writer.
-        self.ui_test.create_doc_in_start_center("writer")
-        doc = self.xUITest.getTopFocusWindow()
-        editWin = doc.getChild("writer_edit")
-        # Type a character and select it.
-        editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
-        editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"}))
-        self.xUITest.executeCommand(".uno:SelectAll")
+        with self.ui_test.create_doc_in_start_center_guarded("writer") as component:
+            doc = self.xUITest.getTopFocusWindow()
+            editWin = doc.getChild("writer_edit")
+            # Type a character and select it.
+            editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
+            editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"}))
+            self.xUITest.executeCommand(".uno:SelectAll")
 
-        # Now use Format -> Character.
-        with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
-            xTabs = xDialog.getChild("tabcontrol")
-            # Select RID_SVXPAGE_CHAR_EFFECTS.
-            select_pos(xTabs, "1")
-            xFontTransparency = xDialog.getChild("fonttransparencymtr")
-            # Without the accompanying fix in place, this test would have failed with:
-            # AssertionError: 'false' != 'true'
-            # i.e. the transparency widget was hidden.
-            self.assertEqual(get_state_as_dict(xFontTransparency)["Visible"], "true")
-            for _ in range(5):
-                xFontTransparency.executeAction("UP", tuple())
+            # Now use Format -> Character.
+            with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
+                xTabs = xDialog.getChild("tabcontrol")
+                # Select RID_SVXPAGE_CHAR_EFFECTS.
+                select_pos(xTabs, "1")
+                xFontTransparency = xDialog.getChild("fonttransparencymtr")
+                # Without the accompanying fix in place, this test would have failed with:
+                # AssertionError: 'false' != 'true'
+                # i.e. the transparency widget was hidden.
+                self.assertEqual(get_state_as_dict(xFontTransparency)["Visible"], "true")
+                for _ in range(5):
+                    xFontTransparency.executeAction("UP", tuple())
 
-        # Verify the result.
-        component = self.ui_test.get_component()
-        paragraph = component.Text.createEnumeration().nextElement()
+            # Verify the result.
+            paragraph = component.Text.createEnumeration().nextElement()
 
-        self.assertEqual(paragraph.CharTransparence, 5)
-        self.ui_test.close_doc()
+            self.assertEqual(paragraph.CharTransparence, 5)
 
     def testSvxCharEffectsPageWriterAutomatic(self):
         # Start Writer.
-        self.ui_test.create_doc_in_start_center("writer")
-        doc = self.xUITest.getTopFocusWindow()
-        editWin = doc.getChild("writer_edit")
+        with self.ui_test.create_doc_in_start_center_guarded("writer"):
+            doc = self.xUITest.getTopFocusWindow()
+            editWin = doc.getChild("writer_edit")
 
-        # Use Format -> Character.
-        with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
-            xTabs = xDialog.getChild("tabcontrol")
-            # Select RID_SVXPAGE_CHAR_EFFECTS.
-            select_pos(xTabs, "1")
-            xFontColorLB = xDialog.getChild("fontcolorlb")
-            # Without the accompanying fix in place, this test would have failed with:
-            # AssertionError: 'White' != 'Automatic'
-            # i.e. the auto color lost its alpha component and appeared as white.
-            self.assertEqual(get_state_as_dict(xFontColorLB)["Text"], "Automatic")
+            # Use Format -> Character.
+            with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog:
+                xTabs = xDialog.getChild("tabcontrol")
+                # Select RID_SVXPAGE_CHAR_EFFECTS.
+                select_pos(xTabs, "1")
+                xFontColorLB = xDialog.getChild("fontcolorlb")
+                # Without the accompanying fix in place, this test would have failed with:
+                # AssertionError: 'White' != 'Automatic'
+                # i.e. the auto color lost its alpha component and appeared as white.
+                self.assertEqual(get_state_as_dict(xFontColorLB)["Text"], "Automatic")
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/cui/qa/uitest/dialogs/pastedlg.py b/cui/qa/uitest/dialogs/pastedlg.py
index 9248f923891d..cb37387ff081 100644
--- a/cui/qa/uitest/dialogs/pastedlg.py
+++ b/cui/qa/uitest/dialogs/pastedlg.py
@@ -14,31 +14,30 @@ class Test(UITestCase):
 
     def testGetFormat(self):
         # Copy a string in Impress.
-        self.ui_test.create_doc_in_start_center("impress")
-        template = self.xUITest.getTopFocusWindow()
-        self.ui_test.close_dialog_through_button(template.getChild("close"))
-        doc = self.xUITest.getTopFocusWindow()
-        editWin = doc.getChild("impress_win")
-        # Select the title shape.
-        editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
-        editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"}))
-        self.xUITest.executeCommand(".uno:SelectAll")
-        self.xUITest.executeCommand(".uno:Copy")
-
-        # Now use paste special to see what formats are offered.
-        with self.ui_test.execute_dialog_through_command(".uno:PasteSpecial", close_button="cancel") as pasteSpecial:
-            formats = pasteSpecial.getChild("list")
-            entryCount = int(get_state_as_dict(formats)["Children"])
-            items = []
-            for index in range(entryCount):
-                entry = formats.getChild(str(index))
-                entry.executeAction("SELECT", tuple())
-                items.append(get_state_as_dict(formats)["SelectEntryText"])
-
-            # Make sure there is no RTF vs Richtext duplication.
-            self.assertTrue("Rich text formatting (RTF)" in items)
-            self.assertFalse("Rich text formatting (Richtext)" in items)
-
-        self.ui_test.close_doc()
+        with self.ui_test.create_doc_in_start_center_guarded("impress"):
+            template = self.xUITest.getTopFocusWindow()
+            self.ui_test.close_dialog_through_button(template.getChild("close"))
+            doc = self.xUITest.getTopFocusWindow()
+            editWin = doc.getChild("impress_win")
+            # Select the title shape.
+            editWin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
+            editWin.executeAction("TYPE", mkPropertyValues({"TEXT": "t"}))
+            self.xUITest.executeCommand(".uno:SelectAll")
+            self.xUITest.executeCommand(".uno:Copy")
+
+            # Now use paste special to see what formats are offered.
+            with self.ui_test.execute_dialog_through_command(".uno:PasteSpecial", close_button="cancel") as pasteSpecial:
+                formats = pasteSpecial.getChild("list")
+                entryCount = int(get_state_as_dict(formats)["Children"])
+                items = []
+                for index in range(entryCount):
+                    entry = formats.getChild(str(index))
+                    entry.executeAction("SELECT", tuple())
+                    items.append(get_state_as_dict(formats)["SelectEntryText"])
+
+                # Make sure there is no RTF vs Richtext duplication.
+                self.assertTrue("Rich text formatting (RTF)" in items)
+                self.assertFalse("Rich text formatting (Richtext)" in items)
+
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/cui/qa/uitest/dialogs/shortcuts.py b/cui/qa/uitest/dialogs/shortcuts.py
index 261536d0694f..e1e318384a28 100644
--- a/cui/qa/uitest/dialogs/shortcuts.py
+++ b/cui/qa/uitest/dialogs/shortcuts.py
@@ -13,28 +13,27 @@ from uitest.uihelper.common import get_state_as_dict
 class Test(UITestCase):
 
     def test_tab_navigation(self):
-        self.ui_test.create_doc_in_start_center("writer")
-        xWriterDoc = self.xUITest.getTopFocusWindow()
-        xWriterEdit = xWriterDoc.getChild("writer_edit")
+        with self.ui_test.create_doc_in_start_center_guarded("writer"):
+            xWriterDoc = self.xUITest.getTopFocusWindow()
+            xWriterEdit = xWriterDoc.getChild("writer_edit")
 
-        with self.ui_test.execute_dialog_through_command(".uno:EditStyle") as xDialog:
+            with self.ui_test.execute_dialog_through_command(".uno:EditStyle") as xDialog:
 
-            xTabs = xDialog.getChild("tabcontrol")
-            select_pos(xTabs, "0")
+                xTabs = xDialog.getChild("tabcontrol")
+                select_pos(xTabs, "0")
 
-            for i in range(16):
-                self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
+                for i in range(16):
+                    self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
 
-                xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEDOWN"}))
+                    xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEDOWN"}))
 
-            self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], "0")
+                self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], "0")
 
-            for i in reversed(range(16)):
-                xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEUP"}))
+                for i in reversed(range(16)):
+                    xTabs.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+PAGEUP"}))
 
-                self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
+                    self.assertEqual(get_state_as_dict(xTabs)["CurrPagePos"], str(i))
 
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/svx/qa/uitest/table/tablecontroller.py b/svx/qa/uitest/table/tablecontroller.py
index 20a88ddf8268..c3e8691c40de 100644
--- a/svx/qa/uitest/table/tablecontroller.py
+++ b/svx/qa/uitest/table/tablecontroller.py
@@ -14,66 +14,63 @@ class SvxTableControllerTest(UITestCase):
 
     def testOnFormatTable(self):
         # Create an Impress document with a single table in it.
-        self.ui_test.create_doc_in_start_center("impress")
-        template = self.xUITest.getTopFocusWindow()
-        self.ui_test.close_dialog_through_button(template.getChild("close"))
-        self.xUITest.executeCommand(".uno:SelectAll")
-        self.xUITest.executeCommand(".uno:Delete")
-        self.xUITest.executeCommand(".uno:InsertTable?Columns:short=2&Rows:short=2")
+        with self.ui_test.create_doc_in_start_center_guarded("impress") as component:
+            template = self.xUITest.getTopFocusWindow()
+            self.ui_test.close_dialog_through_button(template.getChild("close"))
+            self.xUITest.executeCommand(".uno:SelectAll")
+            self.xUITest.executeCommand(".uno:Delete")
+            self.xUITest.executeCommand(".uno:InsertTable?Columns:short=2&Rows:short=2")
 
-        # Enable shadow.
-        with self.ui_test.execute_dialog_through_command(".uno:TableDialog") as tableDialog:
-            tabs = tableDialog.getChild("tabcontrol")
-            # Select "shadow".
-            select_pos(tabs, "4")
-            shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
-            shadowCheckbox.executeAction("CLICK", tuple())
+            # Enable shadow.
+            with self.ui_test.execute_dialog_through_command(".uno:TableDialog") as tableDialog:
+                tabs = tableDialog.getChild("tabcontrol")
+                # Select "shadow".
+                select_pos(tabs, "4")
+                shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
+                shadowCheckbox.executeAction("CLICK", tuple())
 
-        # Check if the shadow was enabled.
-        component = self.ui_test.get_component()
-        drawPage = component.getDrawPages().getByIndex(0)
-        shape = drawPage.getByIndex(0)
-        # Without the accompanying fix in place, this test would have failed with:
-        # AssertionError: False != True
-        # i.e. the table still had no shadow.
-        self.assertEqual(shape.Shadow, True)
+            # Check if the shadow was enabled.
+            drawPage = component.getDrawPages().getByIndex(0)
+            shape = drawPage.getByIndex(0)
+            # Without the accompanying fix in place, this test would have failed with:
+            # AssertionError: False != True
+            # i.e. the table still had no shadow.
+            self.assertEqual(shape.Shadow, True)
 
-        # Close the document.
-        self.ui_test.close_doc()
+            # Close the document.
 
     def testUndoCrash(self):
         # Given an Impress document with a single table in it:
-        self.ui_test.create_doc_in_start_center("impress")
-        template = self.xUITest.getTopFocusWindow()
-        self.ui_test.close_dialog_through_button(template.getChild("close"))
-        self.xUITest.executeCommand(".uno:SelectAll")
-        self.xUITest.executeCommand(".uno:Delete")
-        self.xUITest.executeCommand(".uno:InsertTable?Columns:short=3&Rows:short=3")
-        self.xUITest.executeCommand(".uno:SelectAll")
+        with self.ui_test.create_doc_in_start_center_guarded("impress"):
+            template = self.xUITest.getTopFocusWindow()
+            self.ui_test.close_dialog_through_button(template.getChild("close"))
+            self.xUITest.executeCommand(".uno:SelectAll")
+            self.xUITest.executeCommand(".uno:Delete")
+            self.xUITest.executeCommand(".uno:InsertTable?Columns:short=3&Rows:short=3")
+            self.xUITest.executeCommand(".uno:SelectAll")
 
-        # When enabling shadow on the shape while text edit is active:
-        doc = self.xUITest.getTopFocusWindow()
-        impress = doc.getChild("impress_win")
-        impress.executeAction("TYPE", mkPropertyValues({"TEXT": "A1"}))
-        for i in range(6):
-            impress.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+TAB"}))
-        impress.executeAction("TYPE", mkPropertyValues({"TEXT": "A3"}))
-        self.xUITest.executeCommand(".uno:SelectAll")
-        with self.ui_test.execute_dialog_through_command(".uno:TableDialog") as tableDialog:
-            tabs = tableDialog.getChild("tabcontrol")
-            # Select "shadow".
-            select_pos(tabs, "4")
-            shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
-            shadowCheckbox.executeAction("CLICK", tuple())
+            # When enabling shadow on the shape while text edit is active:
+            doc = self.xUITest.getTopFocusWindow()
+            impress = doc.getChild("impress_win")
+            impress.executeAction("TYPE", mkPropertyValues({"TEXT": "A1"}))
+            for i in range(6):
+                impress.executeAction("TYPE", mkPropertyValues({"KEYCODE": "CTRL+TAB"}))
+            impress.executeAction("TYPE", mkPropertyValues({"TEXT": "A3"}))
+            self.xUITest.executeCommand(".uno:SelectAll")
+            with self.ui_test.execute_dialog_through_command(".uno:TableDialog") as tableDialog:
+                tabs = tableDialog.getChild("tabcontrol")
+                # Select "shadow".
+                select_pos(tabs, "4")
+                shadowCheckbox = tableDialog.getChild("TSB_SHOW_SHADOW")
+                shadowCheckbox.executeAction("CLICK", tuple())
 
-        # Then make sure we don't crash:
-        # Without the accompanying fix in place, this test would have failed crashed due to a
-        # use-after-free: text edit ended but an undo action of the text edit remained on the undo
-        # stack.
-        for i in range(2):
-            self.xUITest.executeCommand(".uno:Undo")
+            # Then make sure we don't crash:
+            # Without the accompanying fix in place, this test would have failed crashed due to a
+            # use-after-free: text edit ended but an undo action of the text edit remained on the undo
+            # stack.
+            for i in range(2):
+                self.xUITest.executeCommand(".uno:Undo")
 
-        # Close the document.
-        self.ui_test.close_doc()
+            # Close the document.
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/char_dialog.py b/uitest/demo_ui/char_dialog.py
index 96028621a25a..1f231c3b39c3 100644
--- a/uitest/demo_ui/char_dialog.py
+++ b/uitest/demo_ui/char_dialog.py
@@ -11,15 +11,14 @@ from uitest.framework import UITestCase
 class CharDialogText(UITestCase):
 
     def test_select_char(self):
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:InsertSymbol", close_button="cancel") as xCharDialog:
+            with self.ui_test.execute_dialog_through_command(".uno:InsertSymbol", close_button="cancel") as xCharDialog:
 
-            xCharSet = xCharDialog.getChild("showcharset")
+                xCharSet = xCharDialog.getChild("showcharset")
 
-            xCharSet.executeAction("SELECT", mkPropertyValues({"COLUMN": "2", "ROW": "2"}))
+                xCharSet.executeAction("SELECT", mkPropertyValues({"COLUMN": "2", "ROW": "2"}))
 
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/checkbox.py b/uitest/demo_ui/checkbox.py
index 1d0c96902b44..d944b62d37d4 100644
--- a/uitest/demo_ui/checkbox.py
+++ b/uitest/demo_ui/checkbox.py
@@ -13,13 +13,12 @@ class CheckBoxTest(UITestCase):
 
     def test_toggle_checkbox(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
-            xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
-            xNegativeNumRedCB.executeAction("CLICK",tuple())
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
+                xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
+                xNegativeNumRedCB.executeAction("CLICK",tuple())
 
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/combobox.py b/uitest/demo_ui/combobox.py
index 8b47f8338fb9..924b5c3af035 100644
--- a/uitest/demo_ui/combobox.py
+++ b/uitest/demo_ui/combobox.py
@@ -14,17 +14,16 @@ class ComboBoxTest(UITestCase):
 
     def test_select_entry_pos(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        self.ui_test.execute_modeless_dialog_through_command(".uno:AddName")
-        xAddNameDlg = self.xUITest.getTopFocusWindow()
+            self.ui_test.execute_modeless_dialog_through_command(".uno:AddName")
+            xAddNameDlg = self.xUITest.getTopFocusWindow()
 
-        scopeCB = xAddNameDlg.getChild("scope")
-        select_pos(scopeCB, "1")
+            scopeCB = xAddNameDlg.getChild("scope")
+            select_pos(scopeCB, "1")
 
-        xCancelBtn = xAddNameDlg.getChild("cancel")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xCancelBtn = xAddNameDlg.getChild("cancel")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/command_with_parameters.py b/uitest/demo_ui/command_with_parameters.py
index c82d3359559a..3a140643b659 100644
--- a/uitest/demo_ui/command_with_parameters.py
+++ b/uitest/demo_ui/command_with_parameters.py
@@ -12,13 +12,12 @@ class CommandWithParametersTest(UITestCase):
 
     def test_text_color_change(self):
 
-        self.ui_test.create_doc_in_start_center("writer")
+        with self.ui_test.create_doc_in_start_center_guarded("writer"):
 
-        self.xUITest.executeCommandWithParameters(".uno:Color",
-            mkPropertyValues({"Color": 16776960}))
-        xWriterEdit = self.xUITest.getTopFocusWindow().getChild("writer_edit")
-        type_text(xWriterEdit, "LibreOffice")
+            self.xUITest.executeCommandWithParameters(".uno:Color",
+                mkPropertyValues({"Color": 16776960}))
+            xWriterEdit = self.xUITest.getTopFocusWindow().getChild("writer_edit")
+            type_text(xWriterEdit, "LibreOffice")
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/edit.py b/uitest/demo_ui/edit.py
index 48ada3b1d15e..7007c07b4a90 100644
--- a/uitest/demo_ui/edit.py
+++ b/uitest/demo_ui/edit.py
@@ -16,40 +16,38 @@ class EditTest(UITestCase):
 
     def test_type_text(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        self.ui_test.execute_modeless_dialog_through_command(".uno:AddName")
-        xAddNameDlg = self.xUITest.getTopFocusWindow()
+            self.ui_test.execute_modeless_dialog_through_command(".uno:AddName")
+            xAddNameDlg = self.xUITest.getTopFocusWindow()
 
-        xEdit = xAddNameDlg.getChild("edit")
+            xEdit = xAddNameDlg.getChild("edit")
 
-        type_text(xEdit, "simpleRangeName")
+            type_text(xEdit, "simpleRangeName")
 
-        xAddBtn = xAddNameDlg.getChild("cancel")
-        self.ui_test.close_dialog_through_button(xAddBtn)
+            xAddBtn = xAddNameDlg.getChild("cancel")
+            self.ui_test.close_dialog_through_button(xAddBtn)
 
-        self.ui_test.close_doc()
 
     def test_select_text(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        self.ui_test.execute_modeless_dialog_through_command(".uno:AddName")
-        xAddNameDlg = self.xUITest.getTopFocusWindow()
+            self.ui_test.execute_modeless_dialog_through_command(".uno:AddName")
+            xAddNameDlg = self.xUITest.getTopFocusWindow()
 
-        xEdit = xAddNameDlg.getChild("edit")
+            xEdit = xAddNameDlg.getChild("edit")
 
-        type_text(xEdit, "simpleRangeName")
-        xEdit.executeAction("SELECT", mkPropertyValues({"FROM": "2", "TO": "9"}))
-        type_text(xEdit, "otherChars")
-        self.assertEqual("siotherCharsgeName", get_state_as_dict(xEdit)["Text"])
+            type_text(xEdit, "simpleRangeName")
+            xEdit.executeAction("SELECT", mkPropertyValues({"FROM": "2", "TO": "9"}))
+            type_text(xEdit, "otherChars")
+            self.assertEqual("siotherCharsgeName", get_state_as_dict(xEdit)["Text"])
 
-        select_text(xEdit, from_pos="2", to="12")
-        self.assertEqual("otherChars", get_state_as_dict(xEdit)["SelectedText"])
+            select_text(xEdit, from_pos="2", to="12")
+            self.assertEqual("otherChars", get_state_as_dict(xEdit)["SelectedText"])
 
-        xAddBtn = xAddNameDlg.getChild("cancel")
-        self.ui_test.close_dialog_through_button(xAddBtn)
+            xAddBtn = xAddNameDlg.getChild("cancel")
+            self.ui_test.close_dialog_through_button(xAddBtn)
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/gridwin.py b/uitest/demo_ui/gridwin.py
index ddfb13273bb8..142c395f22c9 100644
--- a/uitest/demo_ui/gridwin.py
+++ b/uitest/demo_ui/gridwin.py
@@ -13,39 +13,36 @@ class GridWinTest(UITestCase):
 
     def test_select_cell(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
-        xCalcDoc = self.xUITest.getTopFocusWindow()
-        xGridWindow = xCalcDoc.getChild("grid_window")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            xGridWindow = xCalcDoc.getChild("grid_window")
 
-        selectProps = mkPropertyValues({"CELL": "B10"})
-        xGridWindow.executeAction("SELECT", selectProps)
+            selectProps = mkPropertyValues({"CELL": "B10"})
+            xGridWindow.executeAction("SELECT", selectProps)
 
-        self.ui_test.close_doc()
 
     def test_select_range(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
-        xCalcDoc = self.xUITest.getTopFocusWindow()
-        xGridWindow = xCalcDoc.getChild("grid_window")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            xGridWindow = xCalcDoc.getChild("grid_window")
 
-        selectProps = mkPropertyValues({"RANGE": "B10:C20"})
-        xGridWindow.executeAction("SELECT", selectProps)
+            selectProps = mkPropertyValues({"RANGE": "B10:C20"})
+            xGridWindow.executeAction("SELECT", selectProps)
 
-        self.ui_test.close_doc()
 
     def test_extend_range(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
-        xTopWindow = self.xUITest.getTopFocusWindow()
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
+            xTopWindow = self.xUITest.getTopFocusWindow()
 
-        xGridWindow = xTopWindow.getChild("grid_window")
+            xGridWindow = xTopWindow.getChild("grid_window")
 
-        selectProps = mkPropertyValues({"RANGE": "B10:C20"})
-        xGridWindow.executeAction("SELECT", selectProps)
+            selectProps = mkPropertyValues({"RANGE": "B10:C20"})
+            xGridWindow.executeAction("SELECT", selectProps)
 
-        select2Props = mkPropertyValues({"RANGE": "D3:F5", "EXTEND": "true"})
-        xGridWindow.executeAction("SELECT", select2Props)
+            select2Props = mkPropertyValues({"RANGE": "D3:F5", "EXTEND": "true"})
+            xGridWindow.executeAction("SELECT", select2Props)
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/hierarchy.py b/uitest/demo_ui/hierarchy.py
index 1bfc85d7d99f..b17626a108ca 100644
--- a/uitest/demo_ui/hierarchy.py
+++ b/uitest/demo_ui/hierarchy.py
@@ -15,18 +15,17 @@ class CheckBoxTest(UITestCase):
 
     def test_get_json(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:About", close_button="btnClose") as xAboutDlg:
+            with self.ui_test.execute_dialog_through_command(".uno:About", close_button="btnClose") as xAboutDlg:
 
 
-            json_string = xAboutDlg.getHierarchy()
-            print(json_string)
-            json_content = json.loads(json_string)
-            print(json_content)
-            print(json.dumps(json_content, indent=4))
+                json_string = xAboutDlg.getHierarchy()
+                print(json_string)
+                json_content = json.loads(json_string)
+                print(json_content)
+                print(json.dumps(json_content, indent=4))
 
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/listbox.py b/uitest/demo_ui/listbox.py
index 3a61d5f9717e..6a1a075d35f4 100644
--- a/uitest/demo_ui/listbox.py
+++ b/uitest/demo_ui/listbox.py
@@ -14,20 +14,18 @@ class ListBoxTest(UITestCase):
 
     def test_select_entry_pos(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
-            pass
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
+                pass
 
-        self.ui_test.close_doc()
 
     def test_select_entry_text(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
-            pass
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
+                pass
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/radiobutton.py b/uitest/demo_ui/radiobutton.py
index f76192b4ffb0..628cf2a38834 100644
--- a/uitest/demo_ui/radiobutton.py
+++ b/uitest/demo_ui/radiobutton.py
@@ -25,13 +25,12 @@ class RadioButtonTest(UITestCase):
 
     def test_toggle_radiobutton(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
-            xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
-            xNegativeNumRedCB.executeAction("CLICK",tuple())
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
+                xNegativeNumRedCB = xCellsDlg.getChild("negnumred")
+                xNegativeNumRedCB.executeAction("CLICK",tuple())
 
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/spinfield.py b/uitest/demo_ui/spinfield.py
index d29ce33141ab..bed26702122b 100644
--- a/uitest/demo_ui/spinfield.py
+++ b/uitest/demo_ui/spinfield.py
@@ -14,53 +14,50 @@ class SpinFieldTest(UITestCase):
 
     def test_up(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
 
-            xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
-            xDecimalPlaces.executeAction("UP", tuple())
+                xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
+                xDecimalPlaces.executeAction("UP", tuple())
 
-            decimal_places_state = get_state_as_dict(xDecimalPlaces)
-            assert(decimal_places_state["Text"] == "2")
+                decimal_places_state = get_state_as_dict(xDecimalPlaces)
+                assert(decimal_places_state["Text"] == "2")
 
 
-        self.ui_test.close_doc()
 
     def test_down(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
 
-            xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
-            xDecimalPlaces.executeAction("UP", tuple())
-            xDecimalPlaces.executeAction("UP", tuple())
+                xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
+                xDecimalPlaces.executeAction("UP", tuple())
+                xDecimalPlaces.executeAction("UP", tuple())
 
-            decimal_places_state = get_state_as_dict(xDecimalPlaces)
-            assert(decimal_places_state["Text"] == "3")
+                decimal_places_state = get_state_as_dict(xDecimalPlaces)
+                assert(decimal_places_state["Text"] == "3")
         
-            xDecimalPlaces.executeAction("DOWN", tuple())
+                xDecimalPlaces.executeAction("DOWN", tuple())
 
-            decimal_places_state = get_state_as_dict(xDecimalPlaces)
-            assert(decimal_places_state["Text"] == "2")
+                decimal_places_state = get_state_as_dict(xDecimalPlaces)
+                assert(decimal_places_state["Text"] == "2")
 
 
-        self.ui_test.close_doc()
 
     def test_text(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog") as xCellsDlg:
         
-            xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
-            type_text(xDecimalPlaces, "4")
+                xDecimalPlaces = xCellsDlg.getChild("leadzerosed")
+                type_text(xDecimalPlaces, "4")
 
-            decimal_places_state = get_state_as_dict(xDecimalPlaces)
-            assert(decimal_places_state["Text"] == "41")
+                decimal_places_state = get_state_as_dict(xDecimalPlaces)
+                assert(decimal_places_state["Text"] == "41")
 
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/tabcontrol.py b/uitest/demo_ui/tabcontrol.py
index 47b3f33a3cf4..f47c51f8303c 100644
--- a/uitest/demo_ui/tabcontrol.py
+++ b/uitest/demo_ui/tabcontrol.py
@@ -16,23 +16,22 @@ class TabControlTest(UITestCase):
 
     def test_select_pos(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        xCalcDoc = self.xUITest.getTopFocusWindow()
-        xGridWindow = xCalcDoc.getChild("grid_window")
-        enter_text_to_cell(xGridWindow, "B2", "=2+3+4")
-        xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "B2"}))
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            xGridWindow = xCalcDoc.getChild("grid_window")
+            enter_text_to_cell(xGridWindow, "B2", "=2+3+4")
+            xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "B2"}))
 
-        self.ui_test.execute_modeless_dialog_through_command(".uno:FunctionDialog")
+            self.ui_test.execute_modeless_dialog_through_command(".uno:FunctionDialog")
 
-        xFunctionDlg = self.xUITest.getTopFocusWindow()
+            xFunctionDlg = self.xUITest.getTopFocusWindow()
 
-        xTabs = xFunctionDlg.getChild("tabcontrol")
-        select_pos(xTabs, "1")
+            xTabs = xFunctionDlg.getChild("tabcontrol")
+            select_pos(xTabs, "1")
 
-        xCancelBtn = xFunctionDlg.getChild("cancel")
-        xCancelBtn.executeAction("CLICK", tuple())
+            xCancelBtn = xFunctionDlg.getChild("cancel")
+            xCancelBtn.executeAction("CLICK", tuple())
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/tabdialog.py b/uitest/demo_ui/tabdialog.py
index 95eb3b1e81be..e3fde961f014 100644
--- a/uitest/demo_ui/tabdialog.py
+++ b/uitest/demo_ui/tabdialog.py
@@ -14,20 +14,18 @@ class TabDialogTest(UITestCase):
 
     def test_select_tab_page_pos(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
-            pass
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
+                pass
 
-        self.ui_test.close_doc()
 
     def test_select_tab_page_name(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
-            pass
+            with self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog"):
+                pass
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/demo_ui/treelist.py b/uitest/demo_ui/treelist.py
index 265fa8b975b3..20331230df08 100644
--- a/uitest/demo_ui/treelist.py
+++ b/uitest/demo_ui/treelist.py
@@ -16,31 +16,30 @@ class TreeListTest(UITestCase):
 
     def test_expand(self):
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.create_doc_in_start_center_guarded("calc"):
 
-        xCalcDoc = self.xUITest.getTopFocusWindow()
-        xGridWindow = xCalcDoc.getChild("grid_window")
-        enter_text_to_cell(xGridWindow, "B2", "=2+3+4")
-        xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "B2"}))
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            xGridWindow = xCalcDoc.getChild("grid_window")
+            enter_text_to_cell(xGridWindow, "B2", "=2+3+4")
+            xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "B2"}))
 
-        self.ui_test.execute_modeless_dialog_through_command(".uno:FunctionDialog")
+            self.ui_test.execute_modeless_dialog_through_command(".uno:FunctionDialog")
 
-        xFunctionDlg = self.xUITest.getTopFocusWindow()
+            xFunctionDlg = self.xUITest.getTopFocusWindow()
 
-        xTabs = xFunctionDlg.getChild("tabcontrol")
-        select_pos(xTabs, "1")
+            xTabs = xFunctionDlg.getChild("tabcontrol")
+            select_pos(xTabs, "1")
 
-        xTreelist = xTabs.getChild("struct")
+            xTreelist = xTabs.getChild("struct")
 
-        xTreeEntry = xTreelist.getChild('0')
+            xTreeEntry = xTreelist.getChild('0')
 
-        xTreeEntry.executeAction("COLLAPSE", tuple())
+            xTreeEntry.executeAction("COLLAPSE", tuple())
 
-        xTreeEntry.executeAction("EXPAND", tuple())
+            xTreeEntry.executeAction("EXPAND", tuple())
 
-        xCancelBtn = xFunctionDlg.getChild("cancel")
-        xCancelBtn.executeAction("CLICK", tuple())
+            xCancelBtn = xFunctionDlg.getChild("cancel")
+            xCancelBtn.executeAction("CLICK", tuple())
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/impress_tests/backgrounds.py b/uitest/impress_tests/backgrounds.py
index f37ef2a22a44..256878926967 100644
--- a/uitest/impress_tests/backgrounds.py
+++ b/uitest/impress_tests/backgrounds.py
@@ -105,38 +105,37 @@ class ImpressBackgrounds(UITestCase):
 
     def test_background_dialog(self):
 
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress"):
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        buttons = ['btnbitmap', 'btncolor', 'btngradient', 'btnhatch', 'btnpattern']
-        for index, button in enumerate(buttons):
-            with self.ui_test.execute_dialog_through_command(".uno:PageSetup") as xPageSetupDlg:
+            buttons = ['btnbitmap', 'btncolor', 'btngradient', 'btnhatch', 'btnpattern']
+            for index, button in enumerate(buttons):
+                with self.ui_test.execute_dialog_through_command(".uno:PageSetup") as xPageSetupDlg:
 
-                tabcontrol = xPageSetupDlg.getChild("tabcontrol")
-                select_pos(tabcontrol, "1")
+                    tabcontrol = xPageSetupDlg.getChild("tabcontrol")
+                    select_pos(tabcontrol, "1")
 
-                xBtn = xPageSetupDlg.getChild(button)
-                xBtn.executeAction("CLICK", tuple())
+                    xBtn = xPageSetupDlg.getChild(button)
+                    xBtn.executeAction("CLICK", tuple())
 
-                # tdf#100024: Without the fix in place, this test would have crashed here
-                # changing the background to bitmap
+                    # tdf#100024: Without the fix in place, this test would have crashed here
+                    # changing the background to bitmap
 
-            self.checkDefaultBackground(button)
+                self.checkDefaultBackground(button)
 
-            with self.ui_test.execute_dialog_through_command(".uno:PageSetup") as xPageSetupDlg:
+                with self.ui_test.execute_dialog_through_command(".uno:PageSetup") as xPageSetupDlg:
 
-                tabcontrol = xPageSetupDlg.getChild("tabcontrol")
-                select_pos(tabcontrol, "1")
+                    tabcontrol = xPageSetupDlg.getChild("tabcontrol")
+                    select_pos(tabcontrol, "1")
 
-                xBtn = xPageSetupDlg.getChild('btnnone')
-                xBtn.executeAction("CLICK", tuple())
+                    xBtn = xPageSetupDlg.getChild('btnnone')
+                    xBtn.executeAction("CLICK", tuple())
 
 
-            self.checkDefaultBackground('btnnone')
+                self.checkDefaultBackground('btnnone')
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/impress_tests/drawinglayer.py b/uitest/impress_tests/drawinglayer.py
index bc1e785f65e3..93edd5503df7 100644
--- a/uitest/impress_tests/drawinglayer.py
+++ b/uitest/impress_tests/drawinglayer.py
@@ -13,134 +13,128 @@ from uitest.framework import UITestCase
 class ImpressDrawinglayerTest(UITestCase):
 
     def test_move_object(self):
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress") as document:
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        change_measurement_unit(self, 'Centimeter')
+            change_measurement_unit(self, 'Centimeter')
 
-        xImpressDoc = self.xUITest.getTopFocusWindow()
+            xImpressDoc = self.xUITest.getTopFocusWindow()
 
-        document = self.ui_test.get_component()
-        self.assertEqual(1400, document.DrawPages[0].getByIndex(0).Position.X)
-        self.assertEqual(628, document.DrawPages[0].getByIndex(0).Position.Y)
-        self.assertEqual(1400, document.DrawPages[0].getByIndex(1).Position.X)
-        self.assertEqual(3685, document.DrawPages[0].getByIndex(1).Position.Y)
+            self.assertEqual(1400, document.DrawPages[0].getByIndex(0).Position.X)
+            self.assertEqual(628, document.DrawPages[0].getByIndex(0).Position.Y)
+            self.assertEqual(1400, document.DrawPages[0].getByIndex(1).Position.X)
+            self.assertEqual(3685, document.DrawPages[0].getByIndex(1).Position.Y)
 
 
-        xEditWin = xImpressDoc.getChild("impress_win")
-        xDrawinglayerObject = xEditWin.getChild("Unnamed Drawinglayer object 1")
-        xDrawinglayerObject.executeAction("MOVE", mkPropertyValues({"X": "1000", "Y":"1000"}))
+            xEditWin = xImpressDoc.getChild("impress_win")
+            xDrawinglayerObject = xEditWin.getChild("Unnamed Drawinglayer object 1")
+            xDrawinglayerObject.executeAction("MOVE", mkPropertyValues({"X": "1000", "Y":"1000"}))
 
-        self.assertEqual(1400, document.DrawPages[0].getByIndex(0).Position.X)
-        self.assertEqual(628, document.DrawPages[0].getByIndex(0).Position.Y)
-        self.assertEqual(2400, document.DrawPages[0].getByIndex(1).Position.X)
-        self.assertEqual(4685, document.DrawPages[0].getByIndex(1).Position.Y)
+            self.assertEqual(1400, document.DrawPages[0].getByIndex(0).Position.X)
+            self.assertEqual(628, document.DrawPages[0].getByIndex(0).Position.Y)
+            self.assertEqual(2400, document.DrawPages[0].getByIndex(1).Position.X)
+            self.assertEqual(4685, document.DrawPages[0].getByIndex(1).Position.Y)
 
-        self.assertIsNone(document.CurrentSelection)
+            self.assertIsNone(document.CurrentSelection)
 
-        xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
-        self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
+            xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
+            self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
 
-        with self.ui_test.execute_dialog_through_command(".uno:Size") as xDialog:
-            self.assertEqual('25.2', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
-            self.assertEqual('9.13', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
-            self.assertEqual('2.4', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
-            self.assertEqual('4.69', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
-            self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
+            with self.ui_test.execute_dialog_through_command(".uno:Size") as xDialog:
+                self.assertEqual('25.2', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
+                self.assertEqual('9.13', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
+                self.assertEqual('2.4', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
+                self.assertEqual('4.69', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
+                self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
 
-        self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
-        xEditWin.executeAction("DESELECT", tuple())
-        self.assertIsNone(document.CurrentSelection)
+            self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
+            xEditWin.executeAction("DESELECT", tuple())
+            self.assertIsNone(document.CurrentSelection)
 
-        self.ui_test.close_doc()
 
     def test_resize_object(self):
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress") as document:
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        change_measurement_unit(self, 'Centimeter')
+            change_measurement_unit(self, 'Centimeter')
 
-        xImpressDoc = self.xUITest.getTopFocusWindow()
+            xImpressDoc = self.xUITest.getTopFocusWindow()
 
-        document = self.ui_test.get_component()
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
-        self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(1).Size.Width)
-        self.assertEqual(9134, document.DrawPages[0].getByIndex(1).Size.Height)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
+            self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(1).Size.Width)
+            self.assertEqual(9134, document.DrawPages[0].getByIndex(1).Size.Height)
 
-        xEditWin = xImpressDoc.getChild("impress_win")
+            xEditWin = xImpressDoc.getChild("impress_win")
 
-        xDrawinglayerObject = xEditWin.getChild("Unnamed Drawinglayer object 1")
-        xDrawinglayerObject.executeAction("RESIZE", mkPropertyValues({"X": "500", "Y":"4000", "FRAC_X": "0.5", "FRAC_Y": "0.5"}))
+            xDrawinglayerObject = xEditWin.getChild("Unnamed Drawinglayer object 1")
+            xDrawinglayerObject.executeAction("RESIZE", mkPropertyValues({"X": "500", "Y":"4000", "FRAC_X": "0.5", "FRAC_Y": "0.5"}))
 
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
-        self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
-        self.assertEqual(12600, document.DrawPages[0].getByIndex(1).Size.Width)
-        self.assertEqual(4568, document.DrawPages[0].getByIndex(1).Size.Height)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
+            self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
+            self.assertEqual(12600, document.DrawPages[0].getByIndex(1).Size.Width)
+            self.assertEqual(4568, document.DrawPages[0].getByIndex(1).Size.Height)
 
-        self.assertIsNone(document.CurrentSelection)
+            self.assertIsNone(document.CurrentSelection)
 
-        xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
-        self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
+            xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
+            self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
 
-        with self.ui_test.execute_dialog_through_command(".uno:Size") as xDialog:
-            self.assertEqual('12.6', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
-            self.assertEqual('4.57', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
-            self.assertEqual('0.95', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
-            self.assertEqual('3.84', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
-            self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
+            with self.ui_test.execute_dialog_through_command(".uno:Size") as xDialog:
+                self.assertEqual('12.6', get_state_as_dict(xDialog.getChild('MTR_FLD_WIDTH'))['Value'])
+                self.assertEqual('4.57', get_state_as_dict(xDialog.getChild('MTR_FLD_HEIGHT'))['Value'])
+                self.assertEqual('0.95', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_X'))['Value'])
+                self.assertEqual('3.84', get_state_as_dict(xDialog.getChild('MTR_FLD_POS_Y'))['Value'])
+                self.assertEqual('0', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
 
-        self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
-        xEditWin.executeAction("DESELECT", tuple())
-        self.assertIsNone(document.CurrentSelection)
+            self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
+            xEditWin.executeAction("DESELECT", tuple())
+            self.assertIsNone(document.CurrentSelection)
 
-        self.ui_test.close_doc()
 
     def test_rotate_object(self):
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress") as document:
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        xImpressDoc = self.xUITest.getTopFocusWindow()
+            xImpressDoc = self.xUITest.getTopFocusWindow()
 
-        document = self.ui_test.get_component()
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
-        self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(1).Size.Width)
-        self.assertEqual(9134, document.DrawPages[0].getByIndex(1).Size.Height)
-        self.assertEqual(0, document.DrawPages[0].getByIndex(1).RotateAngle)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
+            self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(1).Size.Width)
+            self.assertEqual(9134, document.DrawPages[0].getByIndex(1).Size.Height)
+            self.assertEqual(0, document.DrawPages[0].getByIndex(1).RotateAngle)
 
-        xEditWin = xImpressDoc.getChild("impress_win")
+            xEditWin = xImpressDoc.getChild("impress_win")
 
-        xDrawinglayerObject = xEditWin.getChild("Unnamed Drawinglayer object 1")
-        xDrawinglayerObject.executeAction("ROTATE", mkPropertyValues({"X": "500", "Y":"4000", "ANGLE": "3000"}))
+            xDrawinglayerObject = xEditWin.getChild("Unnamed Drawinglayer object 1")
+            xDrawinglayerObject.executeAction("ROTATE", mkPropertyValues({"X": "500", "Y":"4000", "ANGLE": "3000"}))
 
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
-        self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
-        self.assertEqual(25199, document.DrawPages[0].getByIndex(1).Size.Width)
-        self.assertEqual(9134, document.DrawPages[0].getByIndex(1).Size.Height)
-        self.assertEqual(3000, document.DrawPages[0].getByIndex(1).RotateAngle)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(0).Size.Width)
+            self.assertEqual(2629, document.DrawPages[0].getByIndex(0).Size.Height)
+            self.assertEqual(25199, document.DrawPages[0].getByIndex(1).Size.Width)
+            self.assertEqual(9134, document.DrawPages[0].getByIndex(1).Size.Height)
+            self.assertEqual(3000, document.DrawPages[0].getByIndex(1).RotateAngle)
 
-        self.assertIsNone(document.CurrentSelection)
+            self.assertIsNone(document.CurrentSelection)
 
-        xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
-        self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
+            xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object 1"}))
+            self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
 
-        with self.ui_test.execute_dialog_through_command(".uno:Size") as xDialog:
-            self.assertEqual('30', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
+            with self.ui_test.execute_dialog_through_command(".uno:Size") as xDialog:
+                self.assertEqual('30', get_state_as_dict(xDialog.getChild('NF_ANGLE'))['Value'])
 
-        self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
-        xEditWin.executeAction("DESELECT", tuple())
-        self.assertIsNone(document.CurrentSelection)
+            self.assertEqual("com.sun.star.drawing.SvxShapeCollection", document.CurrentSelection.getImplementationName())
+            xEditWin.executeAction("DESELECT", tuple())
+            self.assertIsNone(document.CurrentSelection)
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/impress_tests/layouts.py b/uitest/impress_tests/layouts.py
index ebbe8e2ec266..1c7c3b43bf8c 100644
--- a/uitest/impress_tests/layouts.py
+++ b/uitest/impress_tests/layouts.py
@@ -11,33 +11,32 @@ class ImpressLayouts(UITestCase):
 
     def test_impress_layouts(self):
 
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress"):
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        layouts= (".uno:AssignLayout?WhatLayout:long=20", ".uno:AssignLayout?WhatLayout:long=19",
-                    ".uno:AssignLayout?WhatLayout:long=0", ".uno:AssignLayout?WhatLayout:long=1",
-                    ".uno:AssignLayout?WhatLayout:long=32", ".uno:AssignLayout?WhatLayout:long=3",
-                    ".uno:AssignLayout?WhatLayout:long=12", ".uno:AssignLayout?WhatLayout:long=15",
-                    ".uno:AssignLayout?WhatLayout:long=14", ".uno:AssignLayout?WhatLayout:long=16",
-                    ".uno:AssignLayout?WhatLayout:long=18", ".uno:AssignLayout?WhatLayout:long=34",
-                    ".uno:AssignLayout?WhatLayout:long=28", ".uno:AssignLayout?WhatLayout:long=27",
-                    ".uno:AssignLayout?WhatLayout:long=29", ".uno:AssignLayout?WhatLayout:long=30")
+            layouts= (".uno:AssignLayout?WhatLayout:long=20", ".uno:AssignLayout?WhatLayout:long=19",
+                        ".uno:AssignLayout?WhatLayout:long=0", ".uno:AssignLayout?WhatLayout:long=1",
+                        ".uno:AssignLayout?WhatLayout:long=32", ".uno:AssignLayout?WhatLayout:long=3",
+                        ".uno:AssignLayout?WhatLayout:long=12", ".uno:AssignLayout?WhatLayout:long=15",
+                        ".uno:AssignLayout?WhatLayout:long=14", ".uno:AssignLayout?WhatLayout:long=16",
+                        ".uno:AssignLayout?WhatLayout:long=18", ".uno:AssignLayout?WhatLayout:long=34",
+                        ".uno:AssignLayout?WhatLayout:long=28", ".uno:AssignLayout?WhatLayout:long=27",
+                        ".uno:AssignLayout?WhatLayout:long=29", ".uno:AssignLayout?WhatLayout:long=30")
 
-        for i in layouts:
-            self.xUITest.executeCommand(i)
+            for i in layouts:
+                self.xUITest.executeCommand(i)
 
-            xImpressDoc = self.xUITest.getTopFocusWindow()
+                xImpressDoc = self.xUITest.getTopFocusWindow()
 
-            xEditWin = xImpressDoc.getChild("impress_win")
+                xEditWin = xImpressDoc.getChild("impress_win")
 
-            # There's a layout with 7 objects
-            for j in range(0,6):
-                xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object " + str(j)}))
-                xEditWin.executeAction("DESELECT", tuple())
+                # There's a layout with 7 objects
+                for j in range(0,6):
+                    xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Unnamed Drawinglayer object " + str(j)}))
+                    xEditWin.executeAction("DESELECT", tuple())
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/impress_tests/start.py b/uitest/impress_tests/start.py
index b6f5cbc517c9..f9e51cf249d8 100644
--- a/uitest/impress_tests/start.py
+++ b/uitest/impress_tests/start.py
@@ -12,43 +12,41 @@ from uitest.framework import UITestCase
 class SimpleImpressTest(UITestCase):
     def test_start_impress(self):
 
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress"):
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        xImpressDoc = self.xUITest.getTopFocusWindow()
+            xImpressDoc = self.xUITest.getTopFocusWindow()
 
-        xEditWin = xImpressDoc.getChild("impress_win")
-        xEditWin.executeAction("SET", mkPropertyValues({"ZOOM": "200"}))
+            xEditWin = xImpressDoc.getChild("impress_win")
+            xEditWin.executeAction("SET", mkPropertyValues({"ZOOM": "200"}))
 
-        self.assertEqual(get_state_as_dict(xEditWin)["Zoom"], "200")
+            self.assertEqual(get_state_as_dict(xEditWin)["Zoom"], "200")
 
-        self.ui_test.close_doc()
 
     def test_select_page(self):
 
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.create_doc_in_start_center_guarded("impress"):
 
-        xTemplateDlg = self.xUITest.getTopFocusWindow()
-        xCancelBtn = xTemplateDlg.getChild("close")
-        self.ui_test.close_dialog_through_button(xCancelBtn)
+            xTemplateDlg = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xTemplateDlg.getChild("close")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
 
-        xImpressDoc = self.xUITest.getTopFocusWindow()
+            xImpressDoc = self.xUITest.getTopFocusWindow()
 
-        xEditWin = xImpressDoc.getChild("impress_win")
+            xEditWin = xImpressDoc.getChild("impress_win")
 
-        self.assertEqual(get_state_as_dict(xEditWin)["CurrentSlide"], "1")
+            self.assertEqual(get_state_as_dict(xEditWin)["CurrentSlide"], "1")
 
-        self.xUITest.executeCommand(".uno:InsertPage")
+            self.xUITest.executeCommand(".uno:InsertPage")
 
-        self.assertEqual(get_state_as_dict(xEditWin)["CurrentSlide"], "2")
+            self.assertEqual(get_state_as_dict(xEditWin)["CurrentSlide"], "2")
 
-        xEditWin.executeAction("GOTO", mkPropertyValues({"PAGE": "1"}))
+            xEditWin.executeAction("GOTO", mkPropertyValues({"PAGE": "1"}))
 
-        self.assertEqual(get_state_as_dict(xEditWin)["CurrentSlide"], "1")
+            self.assertEqual(get_state_as_dict(xEditWin)["CurrentSlide"], "1")
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/math_tests/start.py b/uitest/math_tests/start.py
index 2ad977f73917..700e38c7c87d 100644
--- a/uitest/math_tests/start.py
+++ b/uitest/math_tests/start.py
@@ -18,74 +18,69 @@ class SimpleMathTest(UITestCase):
 
     def test_start_math(self):
 
-        self.ui_test.create_doc_in_start_center("math")
+        with self.ui_test.create_doc_in_start_center_guarded("math"):
 
-        xMathDoc = self.xUITest.getTopFocusWindow()
+            xMathDoc = self.xUITest.getTopFocusWindow()
 
-        self.ui_test.close_doc()
 
     def test_docking_window_listbox(self):
 
-        self.ui_test.create_doc_in_start_center("math")
+        with self.ui_test.create_doc_in_start_center_guarded("math"):
 
-        xMathDoc = self.xUITest.getTopFocusWindow()
+            xMathDoc = self.xUITest.getTopFocusWindow()
 
-        xList = xMathDoc.getChild("listbox")
-        state = get_state_as_dict(xList)
-        self.assertEqual(state["SelectEntryText"], "Unary/Binary Operators")
-        select_pos(xList, "1")
-        state = get_state_as_dict(xList)
-        self.assertEqual(state["SelectEntryText"], "Relations")
+            xList = xMathDoc.getChild("listbox")
+            state = get_state_as_dict(xList)
+            self.assertEqual(state["SelectEntryText"], "Unary/Binary Operators")
+            select_pos(xList, "1")
+            state = get_state_as_dict(xList)
+            self.assertEqual(state["SelectEntryText"], "Relations")
 
-        self.ui_test.close_doc()
 
     def test_math_edit(self):
-        self.ui_test.create_doc_in_start_center("math")
+        with self.ui_test.create_doc_in_start_center_guarded("math"):
 
-        xMathDoc = self.xUITest.getTopFocusWindow()
+            xMathDoc = self.xUITest.getTopFocusWindow()
 
-        xMathEdit = xMathDoc.getChild("math_edit")
+            xMathEdit = xMathDoc.getChild("math_edit")
 
-        type_text(xMathEdit, "E=mc^2")
+            type_text(xMathEdit, "E=mc^2")
 
-        self.ui_test.close_doc()
 
     def test_math_selector(self):
-        self.ui_test.create_doc_in_start_center("math")
+        with self.ui_test.create_doc_in_start_center_guarded("math"):
 
-        xMathDoc = self.xUITest.getTopFocusWindow()
+            xMathDoc = self.xUITest.getTopFocusWindow()
 
-        xMathSelector = xMathDoc.getChild("element_selector")
+            xMathSelector = xMathDoc.getChild("element_selector")
 
-        xElement = xMathSelector.getChild("1")
-        xElement.executeAction("SELECT", tuple())
+            xElement = xMathSelector.getChild("1")
+            xElement.executeAction("SELECT", tuple())
 
-        self.ui_test.close_doc()
 
     @unittest.skip("on windows the f4 does not always work")
     def test_complete_math(self):
-        self.ui_test.create_doc_in_start_center("math")
+        with self.ui_test.create_doc_in_start_center_guarded("math"):
 
-        xMathDoc = self.xUITest.getTopFocusWindow()
+            xMathDoc = self.xUITest.getTopFocusWindow()
 
-        xList = xMathDoc.getChild("listbox")
-        state = get_state_as_dict(xList)
-        self.assertEqual(state["SelectEntryText"], "Unary/Binary Operators")
-        select_pos(xList, "1")
+            xList = xMathDoc.getChild("listbox")
+            state = get_state_as_dict(xList)
+            self.assertEqual(state["SelectEntryText"], "Unary/Binary Operators")
+            select_pos(xList, "1")
 
-        xMathSelector = xMathDoc.getChild("element_selector")
+            xMathSelector = xMathDoc.getChild("element_selector")
 
-        xElement = xMathSelector.getChild("1")
-        xElement.executeAction("SELECT", tuple())
+            xElement = xMathSelector.getChild("1")
+            xElement.executeAction("SELECT", tuple())
 
-        xMathEdit = xMathDoc.getChild("math_edit")
-        type_text(xMathEdit, "1")
-        xMathEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F4"}))
-        type_text(xMathEdit, "2")
+            xMathEdit = xMathDoc.getChild("math_edit")
+            type_text(xMathEdit, "1")
+            xMathEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F4"}))
+            type_text(xMathEdit, "2")
 
-        edit_state = get_state_as_dict(xMathEdit)
-        self.assertEqual("1 <> 2 ", edit_state["Text"])
+            edit_state = get_state_as_dict(xMathEdit)
+            self.assertEqual("1 <> 2 ", edit_state["Text"])
 
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/uitest/uihelper/testDialog.py b/uitest/uitest/uihelper/testDialog.py
index d1bb47856acf..828f1ca6b07f 100644
--- a/uitest/uitest/uihelper/testDialog.py
+++ b/uitest/uitest/uihelper/testDialog.py
@@ -12,22 +12,21 @@ from uitest.uihelper.common import get_state_as_dict
 # and if there is an "OK" button open the dialog again and close it by using the OK button
 # the test only checks if LibreOffice crashes by opening the dialog
 def testDialog(UITestCase, app, dialog):
-    doc = UITestCase.ui_test.create_doc_in_start_center(app)
-    with UITestCase.ui_test.execute_dialog_through_command(dialog['command'], close_button=dialog['closeButton']) as xDialog:
-        if 'skipTestOK' in dialog and dialog['skipTestOK'] == True:
-            xOKBtn = None
-        else:
-            try:
-                xOKBtn = xDialog.getChild("ok")
-                if (get_state_as_dict(xOKBtn)["Enabled"] != "true"):
-                    xOKBtn = None
-            except:
+    with UITestCase.ui_test.create_doc_in_start_center_guarded(app):
+        with UITestCase.ui_test.execute_dialog_through_command(dialog['command'], close_button=dialog['closeButton']) as xDialog:
+            if 'skipTestOK' in dialog and dialog['skipTestOK'] == True:
                 xOKBtn = None
+            else:
+                try:
+                    xOKBtn = xDialog.getChild("ok")
+                    if (get_state_as_dict(xOKBtn)["Enabled"] != "true"):
+                        xOKBtn = None
+                except:
+                    xOKBtn = None
 
-    if (xOKBtn != None):
-        print("check also OK button")
-        with UITestCase.ui_test.execute_dialog_through_command(dialog['command']):
-            pass
-    UITestCase.ui_test.close_doc()
+        if (xOKBtn != None):
+            print("check also OK button")
+            with UITestCase.ui_test.execute_dialog_through_command(dialog['command']):
+                pass
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list