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

Xisco Fauli (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 1 16:36:02 UTC 2020


 sc/qa/uitest/calc_tests/columns.py                   |   62 +------------------
 sc/qa/uitest/calc_tests/formatCells.py               |   17 -----
 sc/qa/uitest/calc_tests/rows.py                      |   62 +------------------
 sc/qa/uitest/calc_tests9/tdf126673.py                |   17 -----
 sc/qa/uitest/chart/chartArea.py                      |   16 ----
 sc/qa/uitest/chart/chartGrid.py                      |   15 ----
 sc/qa/uitest/chart/chartWall.py                      |   16 ----
 sc/qa/uitest/chart/chartXAxis.py                     |   16 ----
 sc/qa/uitest/chart/chartYAxis.py                     |   16 ----
 sc/qa/uitest/chart/formatDataSeries.py               |   16 ----
 sc/qa/uitest/chart/tdf93506_trendline.py             |   16 ----
 sw/qa/uitest/chapterNumbering/chapterNumbering.py    |   15 ----
 sw/qa/uitest/table/tableProperties.py                |   16 ----
 sw/qa/uitest/writer_tests2/formatBulletsNumbering.py |   43 +------------
 sw/qa/uitest/writer_tests2/formatParagraph.py        |   29 --------
 sw/qa/uitest/writer_tests3/lineNumbering.py          |   15 ----
 sw/qa/uitest/writer_tests5/columns.py                |   17 -----
 sw/qa/uitest/writer_tests6/tdf128431.py              |   17 -----
 sw/qa/uitest/writer_tests7/tdf132169.py              |   15 ----
 sw/qa/uitest/writer_tests7/tdf133189.py              |   20 ------
 sw/qa/uitest/writer_tests7/tdf99711.py               |   15 ----
 uitest/uitest/uihelper/common.py                     |   25 +++++++
 22 files changed, 78 insertions(+), 418 deletions(-)

New commits:
commit a2d3b5721fc723608cea13a78ce09f959d0b9b9f
Author:     Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Thu Oct 1 12:40:04 2020 +0200
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Thu Oct 1 18:35:11 2020 +0200

    uitest: factor out common duplicated code
    
    Change-Id: Ib6d4edaf3bd1b0a4078c277d1139d7b0db479e2b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103757
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sc/qa/uitest/calc_tests/columns.py b/sc/qa/uitest/calc_tests/columns.py
index 09d6990686f1..784730ddff5a 100644
--- a/sc/qa/uitest/calc_tests/columns.py
+++ b/sc/qa/uitest/calc_tests/columns.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -19,21 +20,8 @@ class CalcColumns(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
+        change_measurement_unit(self, "Centimeter")
 
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
         #select A1
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
         #column width
@@ -74,21 +62,7 @@ class CalcColumns(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
-
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1", "EXTEND":"1"}))
@@ -129,21 +103,8 @@ class CalcColumns(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
+        change_measurement_unit(self, "Centimeter")
 
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
         #select A1
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
         #column width
@@ -231,21 +192,8 @@ class CalcColumns(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
+        change_measurement_unit(self, "Centimeter")
 
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
         #select C1
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
         #column width
diff --git a/sc/qa/uitest/calc_tests/formatCells.py b/sc/qa/uitest/calc_tests/formatCells.py
index 5d350cf2518a..7508a47aaf4a 100644
--- a/sc/qa/uitest/calc_tests/formatCells.py
+++ b/sc/qa/uitest/calc_tests/formatCells.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_sheet_from_doc
 from libreoffice.calc.conditional_format import get_conditional_format_from_sheet
@@ -299,21 +300,9 @@ class formatCell(UITestCase):
         xCalcDoc = self.xUITest.getTopFocusWindow()
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
+
         #set points pt measurement
-        #Make sure that tools-options-LibreOffice Calc-General-Point
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /point
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Point"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Point")
 
         #select cell A1
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
diff --git a/sc/qa/uitest/calc_tests/rows.py b/sc/qa/uitest/calc_tests/rows.py
index 96cffaf5fd1a..cb456fae8176 100644
--- a/sc/qa/uitest/calc_tests/rows.py
+++ b/sc/qa/uitest/calc_tests/rows.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -18,21 +19,8 @@ class CalcRows(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
+        change_measurement_unit(self, "Centimeter")
 
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
         #select A1
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
         #row height
@@ -73,21 +61,7 @@ class CalcRows(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
-
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A3", "EXTEND":"1"}))
@@ -129,21 +103,8 @@ class CalcRows(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
+        change_measurement_unit(self, "Centimeter")
 
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
         #select A1
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
         #row height
@@ -231,21 +192,8 @@ class CalcRows(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #Make sure that tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
+        change_measurement_unit(self, "Centimeter")
 
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
         #select A3
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A3"}))
         #row height
diff --git a/sc/qa/uitest/calc_tests9/tdf126673.py b/sc/qa/uitest/calc_tests9/tdf126673.py
index 8eb99a123f15..8cdebfe5d6af 100644
--- a/sc/qa/uitest/calc_tests9/tdf126673.py
+++ b/sc/qa/uitest/calc_tests9/tdf126673.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -24,21 +25,7 @@ class tdf126673(UITestCase):
         gridwin = xCalcDoc.getChild("grid_window")
         document = self.ui_test.get_component()
 
-        #set cm Tools-options-StarOffice Calc-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialogOpt = self.xUITest.getTopFocusWindow()
-
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Calc
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General /cm
-        xunitlb = xDialogOpt.getChild("unitlb")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xunitlb.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         #select A2
         gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A2"}))
diff --git a/sc/qa/uitest/chart/chartArea.py b/sc/qa/uitest/chart/chartArea.py
index f04084f33f53..727cf95b9220 100644
--- a/sc/qa/uitest/chart/chartArea.py
+++ b/sc/qa/uitest/chart/chartArea.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -26,20 +27,7 @@ class chartArea(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
-
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
+    change_measurement_unit(self, "Centimeter")
 
     gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
     gridwin.executeAction("ACTIVATE", tuple())
diff --git a/sc/qa/uitest/chart/chartGrid.py b/sc/qa/uitest/chart/chartGrid.py
index 85cd9f8e997a..ae57559b92b3 100644
--- a/sc/qa/uitest/chart/chartGrid.py
+++ b/sc/qa/uitest/chart/chartGrid.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -28,20 +29,8 @@ class chartGrid(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
+    change_measurement_unit(self, "Centimeter")
 
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
     #X Axis Major Grid
     gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
     gridwin.executeAction("ACTIVATE", tuple())
diff --git a/sc/qa/uitest/chart/chartWall.py b/sc/qa/uitest/chart/chartWall.py
index d0546401bf7c..ff5586d964f3 100644
--- a/sc/qa/uitest/chart/chartWall.py
+++ b/sc/qa/uitest/chart/chartWall.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -26,20 +27,7 @@ class chartWall(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
-
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
+    change_measurement_unit(self, "Centimeter")
 
     xWall = document.Sheets[0].Charts[0].getEmbeddedObject().getFirstDiagram().Wall
     self.assertEqual(xWall.LineWidth, 0)
diff --git a/sc/qa/uitest/chart/chartXAxis.py b/sc/qa/uitest/chart/chartXAxis.py
index f49302f223f7..941cd49267d7 100644
--- a/sc/qa/uitest/chart/chartXAxis.py
+++ b/sc/qa/uitest/chart/chartXAxis.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -27,20 +28,7 @@ class chartXAxis(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
-
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
+    change_measurement_unit(self, "Centimeter")
 
     gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
     gridwin.executeAction("ACTIVATE", tuple())
diff --git a/sc/qa/uitest/chart/chartYAxis.py b/sc/qa/uitest/chart/chartYAxis.py
index 2a14d15a9f4c..f0051ba47927 100644
--- a/sc/qa/uitest/chart/chartYAxis.py
+++ b/sc/qa/uitest/chart/chartYAxis.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -27,20 +28,7 @@ class chartYAxis(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
-
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
+    change_measurement_unit(self, "Centimeter")
 
     gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
     gridwin.executeAction("ACTIVATE", tuple())
diff --git a/sc/qa/uitest/chart/formatDataSeries.py b/sc/qa/uitest/chart/formatDataSeries.py
index 3db37320c9c5..8f487e636c49 100644
--- a/sc/qa/uitest/chart/formatDataSeries.py
+++ b/sc/qa/uitest/chart/formatDataSeries.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -27,20 +28,7 @@ class chartFormatDataSeries(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
-
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
+    change_measurement_unit(self, "Centimeter")
 
     gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
     gridwin.executeAction("ACTIVATE", tuple())
diff --git a/sc/qa/uitest/chart/tdf93506_trendline.py b/sc/qa/uitest/chart/tdf93506_trendline.py
index de57a86995fd..8df9fce044ff 100644
--- a/sc/qa/uitest/chart/tdf93506_trendline.py
+++ b/sc/qa/uitest/chart/tdf93506_trendline.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
@@ -28,20 +29,7 @@ class tdf93506(UITestCase):
     gridwin = xCalcDoc.getChild("grid_window")
     document = self.ui_test.get_component()
 
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog, set centimeters
-    xDialog = self.xUITest.getTopFocusWindow()
-
-    xPages = xDialog.getChild("pages")
-    xCalcEntry = xPages.getChild('3')                 # calc
-    xCalcEntry.executeAction("EXPAND", tuple())
-    xCalcGeneralEntry = xCalcEntry.getChild('0')
-    xCalcGeneralEntry.executeAction("SELECT", tuple())          #General
-    xMetric = xDialog.getChild("unitlb")
-    props = {"TEXT": "Centimeter"}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialog.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
+    change_measurement_unit(self, "Centimeter")
 
     gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
     gridwin.executeAction("ACTIVATE", tuple())
diff --git a/sw/qa/uitest/chapterNumbering/chapterNumbering.py b/sw/qa/uitest/chapterNumbering/chapterNumbering.py
index 02e4c39531a1..d7df9062f32d 100644
--- a/sw/qa/uitest/chapterNumbering/chapterNumbering.py
+++ b/sw/qa/uitest/chapterNumbering/chapterNumbering.py
@@ -11,6 +11,7 @@ from uitest.path import get_srcdir_url
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.common import get_state_as_dict, type_text
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 
 #Outline Numbering is now Chapter Numbering
 
@@ -20,19 +21,7 @@ class WriterChapterNumbering(UITestCase):
         self.ui_test.create_doc_in_start_center("writer")
         document = self.ui_test.get_component()
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General - set millimeters
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Millimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Millimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:ChapterNumberingDialog")
         xDialog = self.xUITest.getTopFocusWindow()
diff --git a/sw/qa/uitest/table/tableProperties.py b/sw/qa/uitest/table/tableProperties.py
index c0c1cd9de898..962c78384be4 100644
--- a/sw/qa/uitest/table/tableProperties.py
+++ b/sw/qa/uitest/table/tableProperties.py
@@ -11,6 +11,7 @@ from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.common import get_state_as_dict, type_text
+from uitest.uihelper.common import change_measurement_unit
 from uitest.debug import sleep
 import org.libreoffice.unotest
 import pathlib
@@ -24,21 +25,8 @@ class tableProperties(UITestCase):
         writer_doc = self.ui_test.load_file(get_url_for_data_file("tableToText.odt"))
         document = self.ui_test.get_component()
         xWriterDoc = self.xUITest.getTopFocusWindow()
-        #set cm
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
 
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         #dialog Table Properties - Table
         self.ui_test.execute_dialog_through_command(".uno:TableDialog")
diff --git a/sw/qa/uitest/writer_tests2/formatBulletsNumbering.py b/sw/qa/uitest/writer_tests2/formatBulletsNumbering.py
index a7e3421e267e..9373101a3fd8 100644
--- a/sw/qa/uitest/writer_tests2/formatBulletsNumbering.py
+++ b/sw/qa/uitest/writer_tests2/formatBulletsNumbering.py
@@ -12,6 +12,7 @@ import time
 from uitest.debug import sleep
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 
 class formatBulletsNumbering(UITestCase):
 
@@ -20,19 +21,7 @@ class formatBulletsNumbering(UITestCase):
         document = self.ui_test.get_component()
         xWriterDoc = self.xUITest.getTopFocusWindow()
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General - set millimeters
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Millimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Millimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:BulletsAndNumberingDialog")
         xDialog = self.xUITest.getTopFocusWindow()
@@ -190,19 +179,7 @@ class formatBulletsNumbering(UITestCase):
         xWriterDoc = self.xUITest.getTopFocusWindow()
         xWriterEdit = xWriterDoc.getChild("writer_edit")
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General - set millimeters
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Millimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Millimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:BulletsAndNumberingDialog")
         xDialog = self.xUITest.getTopFocusWindow()
@@ -243,19 +220,7 @@ class formatBulletsNumbering(UITestCase):
         document = self.ui_test.get_component()
         xWriterDoc = self.xUITest.getTopFocusWindow()
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General - set millimeters
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Millimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Millimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:BulletsAndNumberingDialog")
         xDialog = self.xUITest.getTopFocusWindow()
diff --git a/sw/qa/uitest/writer_tests2/formatParagraph.py b/sw/qa/uitest/writer_tests2/formatParagraph.py
index cd07db9a12a5..7d2120f10320 100644
--- a/sw/qa/uitest/writer_tests2/formatParagraph.py
+++ b/sw/qa/uitest/writer_tests2/formatParagraph.py
@@ -12,6 +12,7 @@ import time
 from uitest.debug import sleep
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 
 class formatParagraph(UITestCase):
 
@@ -310,19 +311,7 @@ class formatParagraph(UITestCase):
         document = self.ui_test.get_component()
         xWriterDoc = self.xUITest.getTopFocusWindow()
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:ParagraphDialog")
         xDialog = self.xUITest.getTopFocusWindow()
@@ -511,19 +500,7 @@ class formatParagraph(UITestCase):
         document = self.ui_test.get_component()
         xWriterDoc = self.xUITest.getTopFocusWindow()
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General - set centimeter
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:ParagraphDialog")
         xDialog = self.xUITest.getTopFocusWindow()
diff --git a/sw/qa/uitest/writer_tests3/lineNumbering.py b/sw/qa/uitest/writer_tests3/lineNumbering.py
index 8d1b1103657d..50e48948dade 100644
--- a/sw/qa/uitest/writer_tests3/lineNumbering.py
+++ b/sw/qa/uitest/writer_tests3/lineNumbering.py
@@ -11,6 +11,7 @@ from uitest.path import get_srcdir_url
 from libreoffice.uno.propertyvalue import mkPropertyValues
 from uitest.uihelper.common import get_state_as_dict, type_text
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 
 class WriterLineNumbering(UITestCase):
 
@@ -18,19 +19,7 @@ class WriterLineNumbering(UITestCase):
         self.ui_test.create_doc_in_start_center("writer")
         document = self.ui_test.get_component()
 
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General - set centimeters
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:LineNumberingDialog")
         xDialog = self.xUITest.getTopFocusWindow()
diff --git a/sw/qa/uitest/writer_tests5/columns.py b/sw/qa/uitest/writer_tests5/columns.py
index f2a9fe6bc5f9..0e71c065d057 100644
--- a/sw/qa/uitest/writer_tests5/columns.py
+++ b/sw/qa/uitest/writer_tests5/columns.py
@@ -7,6 +7,7 @@
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import select_pos
+from uitest.uihelper.common import change_measurement_unit
 from uitest.uihelper.calc import enter_text_to_cell
 from libreoffice.calc.document import get_cell_by_position
 from uitest.debug import sleep
@@ -19,21 +20,7 @@ class columns(UITestCase):
         document = self.ui_test.get_component()
         xWriterDoc = self.xUITest.getTopFocusWindow()
 
-        #set cm
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         #dialog Columns
         self.ui_test.execute_dialog_through_command(".uno:FormatColumns")
diff --git a/sw/qa/uitest/writer_tests6/tdf128431.py b/sw/qa/uitest/writer_tests6/tdf128431.py
index 17dde483e6e5..88b140235725 100644
--- a/sw/qa/uitest/writer_tests6/tdf128431.py
+++ b/sw/qa/uitest/writer_tests6/tdf128431.py
@@ -6,6 +6,7 @@
 
 from uitest.framework import UITestCase
 from uitest.uihelper.common import select_pos, get_state_as_dict
+from uitest.uihelper.common import change_measurement_unit
 from com.sun.star.uno import RuntimeException
 from com.sun.star.awt.GradientStyle import LINEAR
 from com.sun.star.drawing.HatchStyle import SINGLE
@@ -21,21 +22,7 @@ class tdf128431(UITestCase):
         self.ui_test.create_doc_in_start_center("writer")
         document = self.ui_test.get_component()
 
-        #set cm Tools-options-StarOffice Writer-General
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")  #optionsdialog
-        xDialog = self.xUITest.getTopFocusWindow()
-
-        xPages = xDialog.getChild("pages")
-        xWriterEntry = xPages.getChild('3')                 # Writer
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())          #General
-        xMetric = xDialog.getChild("metric")
-        props = {"TEXT": "Centimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialog.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Centimeter")
 
         self.ui_test.execute_dialog_through_command(".uno:PageDialog")
         xDialog = self.xUITest.getTopFocusWindow()
diff --git a/sw/qa/uitest/writer_tests7/tdf132169.py b/sw/qa/uitest/writer_tests7/tdf132169.py
index 9c884e4051a9..78487a00c2f8 100644
--- a/sw/qa/uitest/writer_tests7/tdf132169.py
+++ b/sw/qa/uitest/writer_tests7/tdf132169.py
@@ -8,6 +8,7 @@ from uitest.framework import UITestCase
 from uitest.path import get_srcdir_url
 from uitest.uihelper.common import get_state_as_dict, type_text
 from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import change_measurement_unit
 
 def get_url_for_data_file(file_name):
     return get_srcdir_url() + "/sw/qa/uitest/writer_tests/data/" + file_name
@@ -18,19 +19,7 @@ class tdf132169(UITestCase):
         writer_doc = self.ui_test.load_file(get_url_for_data_file("shape.odt"))
 
         #set measurement to points
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")
-        xDialogOpt = self.xUITest.getTopFocusWindow()
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())
-        xMetric = xDialogOpt.getChild("metric")
-        props = {"TEXT": "Point"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Point")
 
         xWriterDoc = self.xUITest.getTopFocusWindow()
         xWriterEdit = xWriterDoc.getChild("writer_edit")
diff --git a/sw/qa/uitest/writer_tests7/tdf133189.py b/sw/qa/uitest/writer_tests7/tdf133189.py
index 8b59fcceb00b..30bd35d4c451 100644
--- a/sw/qa/uitest/writer_tests7/tdf133189.py
+++ b/sw/qa/uitest/writer_tests7/tdf133189.py
@@ -6,23 +6,9 @@
 #
 from uitest.framework import UITestCase
 from uitest.uihelper.common import get_state_as_dict, select_pos
+from uitest.uihelper.common import change_measurement_unit
 from libreoffice.uno.propertyvalue import mkPropertyValues
 
-def change_metric_units(self, unit):
-    self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")
-    xDialogOpt = self.xUITest.getTopFocusWindow()
-    xPages = xDialogOpt.getChild("pages")
-    xWriterEntry = xPages.getChild('3')
-    xWriterEntry.executeAction("EXPAND", tuple())
-    xWriterGeneralEntry = xWriterEntry.getChild('0')
-    xWriterGeneralEntry.executeAction("SELECT", tuple())
-    xMetric = xDialogOpt.getChild("metric")
-    props = {"TEXT": unit}
-    actionProps = mkPropertyValues(props)
-    xMetric.executeAction("SELECT", actionProps)
-    xOKBtn = xDialogOpt.getChild("ok")
-    self.ui_test.close_dialog_through_button(xOKBtn)
-
 class tdf133189(UITestCase):
     def test_tdf133189(self):
         writer_doc = self.ui_test.create_doc_in_start_center("writer")
@@ -40,7 +26,7 @@ class tdf133189(UITestCase):
         xPaperMargin = xWriterEdit.getChild('marginLB')
 
         #change measurement to Inches
-        change_metric_units(self, 'Inch')
+        change_measurement_unit(self, 'Inch')
 
         self.ui_test.execute_dialog_through_command(".uno:PageDialog")
         xDialog = self.xUITest.getTopFocusWindow()
@@ -71,7 +57,7 @@ class tdf133189(UITestCase):
         self.assertEqual(get_state_as_dict(xPaperHeight)['Text'], "8.00″")
 
         #change measurement again to Centimeters
-        change_metric_units(self, 'Centimeter')
+        change_measurement_unit(self, 'Centimeter')
 
         self.ui_test.wait_until_property_is_updated(xPaperMargin, "SelectEntryText", "Normal (1.90 cm)")
         # tdf#129267
diff --git a/sw/qa/uitest/writer_tests7/tdf99711.py b/sw/qa/uitest/writer_tests7/tdf99711.py
index 1a6b7f069392..e99f38cc60b1 100644
--- a/sw/qa/uitest/writer_tests7/tdf99711.py
+++ b/sw/qa/uitest/writer_tests7/tdf99711.py
@@ -8,6 +8,7 @@ from uitest.framework import UITestCase
 from uitest.path import get_srcdir_url
 from uitest.uihelper.common import get_state_as_dict
 from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import change_measurement_unit
 
 def get_url_for_data_file(file_name):
     return get_srcdir_url() + "/sw/qa/uitest/writer_tests/data/" + file_name
@@ -18,19 +19,7 @@ class tdf99711(UITestCase):
         writer_doc = self.ui_test.load_file(get_url_for_data_file("shape.odt"))
 
         #set measurement to millimeters
-        self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")
-        xDialogOpt = self.xUITest.getTopFocusWindow()
-        xPages = xDialogOpt.getChild("pages")
-        xWriterEntry = xPages.getChild('3')
-        xWriterEntry.executeAction("EXPAND", tuple())
-        xWriterGeneralEntry = xWriterEntry.getChild('0')
-        xWriterGeneralEntry.executeAction("SELECT", tuple())
-        xMetric = xDialogOpt.getChild("metric")
-        props = {"TEXT": "Millimeter"}
-        actionProps = mkPropertyValues(props)
-        xMetric.executeAction("SELECT", actionProps)
-        xOKBtn = xDialogOpt.getChild("ok")
-        self.ui_test.close_dialog_through_button(xOKBtn)
+        change_measurement_unit(self, "Millimeter")
 
         xWriterDoc = self.xUITest.getTopFocusWindow()
         xWriterEdit = xWriterDoc.getChild("writer_edit")
diff --git a/uitest/uitest/uihelper/common.py b/uitest/uitest/uihelper/common.py
index 5056ef764983..5d4c448f22a2 100644
--- a/uitest/uitest/uihelper/common.py
+++ b/uitest/uitest/uihelper/common.py
@@ -19,4 +19,29 @@ def select_pos(ui_object, pos):
 def select_text(ui_object, from_pos, to):
     ui_object.executeAction("SELECT", mkPropertyValues({"FROM": from_pos, "TO": to}))
 
+def change_measurement_unit(UITestCase, unit):
+    UITestCase.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog")
+    xDialogOpt = UITestCase.xUITest.getTopFocusWindow()
+
+    xPages = xDialogOpt.getChild("pages")
+    xAppEntry = xPages.getChild('3')
+    xAppEntry.executeAction("EXPAND", tuple())
+    xGeneralEntry = xAppEntry.getChild('0')
+    xGeneralEntry.executeAction("SELECT", tuple())
+
+    # Calc
+    if 'unitlb' in xDialogOpt.getChildren():
+        xUnit = xDialogOpt.getChild("unitlb")
+
+    # Writer
+    elif 'metric' in xDialogOpt.getChildren():
+        xUnit = xDialogOpt.getChild("metric")
+
+    props = {"TEXT": unit}
+    actionProps = mkPropertyValues(props)
+    xUnit.executeAction("SELECT", actionProps)
+
+    xOKBtn = xDialogOpt.getChild("ok")
+    UITestCase.ui_test.close_dialog_through_button(xOKBtn)
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list