sw/qa/uitest/writer_tests/tdf156165.py |   70 +++++++++++++++------------------
 1 file changed, 33 insertions(+), 37 deletions(-)

New commits:
commit c14dd7d8ddbdb348aaefce575976c1e52b9967f8
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Dec 4 12:03:56 2023 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Dec 4 13:06:16 2023 +0100

    uitest: sw: refactor test to reset config change at the end
    
    Change-Id: I6447f6e97da7fc5d8946c0658f4bc11fbbfbbba7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160299
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/uitest/writer_tests/tdf156165.py 
b/sw/qa/uitest/writer_tests/tdf156165.py
index de90eebdd54b..02353a533d47 100644
--- a/sw/qa/uitest/writer_tests/tdf156165.py
+++ b/sw/qa/uitest/writer_tests/tdf156165.py
@@ -15,22 +15,23 @@ from time import sleep
 
 class tdf156165(UITestCase):
 
-   def test_tdf156165(self):
+    def change_autocorrect_option(self, enabled):
+        with 
self.ui_test.execute_dialog_through_command(".uno:AutoCorrectDlg") as xDialog:
+            xTabs = xDialog.getChild("tabcontrol")
+            select_pos(xTabs, "2")
+            xList = xDialog.getChild('list')
+            xCheckbox = xList.getChild("17")
+            self.assertEqual("Replace Custom Styles", 
get_state_as_dict(xCheckbox)["Text"])
+
+            xCheckbox.executeAction("CLICK", tuple())
+            self.assertEqual(enabled, 
get_state_as_dict(xCheckbox)["IsChecked"])
+
+    def test_tdf156165(self):
         with self.ui_test.load_file(get_url_for_data_file("tdf156165.odt")):
             xMainWindow = self.xUITest.getTopFocusWindow()
             writer_edit = xMainWindow.getChild("writer_edit")
             style=xMainWindow.getChild('applystyle')
 
-            with 
self.ui_test.execute_dialog_through_command(".uno:AutoCorrectDlg") as xDialog:
-                xTabs = xDialog.getChild("tabcontrol")
-                select_pos(xTabs, "2")
-                options=xDialog.getChild('list')
-                checkbox=options.getChild("17")
-                self.assertEqual("Replace Custom Styles", 
get_state_as_dict(checkbox)["Text"])
-
-                # Replace Custom Styles is default to be false
-                self.assertEqual("false", 
get_state_as_dict(checkbox)["IsChecked"])
-
             # Replace Custom Styles when applying manually with it disabled, 
should not change style
             writer_edit.executeAction("SELECT", mkPropertyValues({"END_POS": 
"0", "START_POS": "12"}))
             self.xUITest.executeCommand(".uno:AutoFormatApply")
@@ -47,34 +48,29 @@ class tdf156165(UITestCase):
             writer_edit.executeAction("SELECT", mkPropertyValues({"END_POS": 
"0", "START_POS": "12"}))
             self.assertEqual(get_state_as_dict(style)["Text"], "eSelah") # 
original line
 
-            with 
self.ui_test.execute_dialog_through_command(".uno:AutoCorrectDlg") as xDialog:
-                xTabs = xDialog.getChild("tabcontrol")
-                select_pos(xTabs, "2")
-                options=xDialog.getChild('list')
-                checkbox=options.getChild("17")
-                self.assertEqual("Replace Custom Styles", 
get_state_as_dict(checkbox)["Text"])
-
-                # set Replace Custom Styles to True
-                checkbox.executeAction("CLICK", tuple())
-                self.assertEqual("true", 
get_state_as_dict(checkbox)["IsChecked"])
+            try:
+                self.change_autocorrect_option("true")
 
-            # Replace Custom Styles when applying manually with it enabled, 
should change style
-            writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
-            writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
-            writer_edit.executeAction("SELECT", mkPropertyValues({"END_POS": 
"0", "START_POS": "12"}))
-            self.xUITest.executeCommand(".uno:AutoFormatApply")
-            sleep(1)
-            self.assertEqual(get_state_as_dict(style)["Text"], "Body Text")
+                # Replace Custom Styles when applying manually with it 
enabled, should change style
+                writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
+                writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
+                writer_edit.executeAction("SELECT", 
mkPropertyValues({"END_POS": "0", "START_POS": "12"}))
+                self.xUITest.executeCommand(".uno:AutoFormatApply")
+                sleep(1)
+                self.assertEqual(get_state_as_dict(style)["Text"], "Body Text")
 
-            # Replace Custom Styles when typing with it enabled, should not 
change style
-            writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
-            writer_edit.executeAction("SELECT", mkPropertyValues({"END_POS": 
"12", "START_POS": "12"}))
-            writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"RETURN"}))
-            sleep(1)
-            self.assertEqual(get_state_as_dict(style)["Text"], "eSelah") # new 
line
-            writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"UP"}))
-            writer_edit.executeAction("SELECT", mkPropertyValues({"END_POS": 
"0", "START_POS": "12"}))
-            self.assertEqual(get_state_as_dict(style)["Text"], "eSelah") # 
original line
+                # Replace Custom Styles when typing with it enabled, should 
not change style
+                writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"DOWN"}))
+                writer_edit.executeAction("SELECT", 
mkPropertyValues({"END_POS": "12", "START_POS": "12"}))
+                writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"RETURN"}))
+                sleep(1)
+                self.assertEqual(get_state_as_dict(style)["Text"], "eSelah") # 
new line
+                writer_edit.executeAction("TYPE", mkPropertyValues({"KEYCODE": 
"UP"}))
+                writer_edit.executeAction("SELECT", 
mkPropertyValues({"END_POS": "0", "START_POS": "12"}))
+                self.assertEqual(get_state_as_dict(style)["Text"], "eSelah") # 
original line
 
+            finally:
+                # reset to default
+                self.change_autocorrect_option("false")
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to