[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - sc/qa uitest/uitest
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Tue Jun 8 21:07:43 UTC 2021
sc/qa/uitest/chart/chartLegend.py | 183 ++++++++++++++++----------------------
uitest/uitest/uihelper/guarded.py | 31 ++++++
2 files changed, 109 insertions(+), 105 deletions(-)
New commits:
commit 625747e90c7a864a39cad132d1c7eba18ca96aa3
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Jun 3 22:20:04 2021 +0200
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Jun 8 23:07:07 2021 +0200
UITest: introduce guarded context managers
They should be used wherever we need to make sure to execute
some action in tests regardless of the assertion success. They
follow their plain counterparts, and execute finalizing code
at all outcomes. This e.g. allows to assert when a dialog is
open, and have it properly closed on failure, so that the test
is not left in hung state.
Only two wrappers are implemented now: load_file and
execute_dialog_through_action.
sc/qa/uitest/chart/chartLegend.py is updated to use them.
Change-Id: Ib9cf44304f0d3ab8fa3377922ed36d2d866031b0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116692
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116867
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
diff --git a/sc/qa/uitest/chart/chartLegend.py b/sc/qa/uitest/chart/chartLegend.py
index 7e2e085d135b..23957eb5655a 100644
--- a/sc/qa/uitest/chart/chartLegend.py
+++ b/sc/qa/uitest/chart/chartLegend.py
@@ -13,6 +13,7 @@ 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.debug import sleep
+from uitest.uihelper import guarded
import org.libreoffice.unotest
import pathlib
@@ -23,119 +24,91 @@ def get_url_for_data_file(file_name):
class chartLegend(UITestCase):
def test_chart_display_legend_dialog(self):
- calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf98390.ods"))
- xCalcDoc = self.xUITest.getTopFocusWindow()
- gridwin = xCalcDoc.getChild("grid_window")
- document = self.ui_test.get_component()
-
- gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
- gridwin.executeAction("ACTIVATE", tuple())
- xChartMainTop = self.xUITest.getTopFocusWindow()
- xChartMain = xChartMainTop.getChild("chart_window")
- xSeriesObj = xChartMain.getChild("CID/D=0:CS=0:CT=0:Series=0")
- self.ui_test.execute_dialog_through_action(xSeriesObj, "COMMAND", mkPropertyValues({"COMMAND": "InsertMenuLegend"}))
- xDialog = self.xUITest.getTopFocusWindow()
-
- left = xDialog.getChild("left")
- right = xDialog.getChild("right")
- top = xDialog.getChild("top")
- bottom = xDialog.getChild("bottom")
-
- left.executeAction("CLICK", tuple())
-
- xOKBtn = xDialog.getChild("ok")
- self.ui_test.close_dialog_through_button(xOKBtn)
-
- #reopen and verify InsertMenuLegend dialog
- gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
- gridwin.executeAction("ACTIVATE", tuple())
- xChartMainTop = self.xUITest.getTopFocusWindow()
- xChartMain = xChartMainTop.getChild("chart_window")
- xSeriesObj = xChartMain.getChild("CID/D=0:CS=0:CT=0:Series=0")
- self.ui_test.execute_dialog_through_action(xSeriesObj, "COMMAND", mkPropertyValues({"COMMAND": "InsertMenuLegend"}))
- xDialog = self.xUITest.getTopFocusWindow()
-
- left = xDialog.getChild("left")
- right = xDialog.getChild("right")
- top = xDialog.getChild("top")
- bottom = xDialog.getChild("bottom")
- show = xDialog.getChild("show")
-
- self.assertEqual(get_state_as_dict(left)["Checked"], "true")
- self.assertEqual(get_state_as_dict(right)["Checked"], "false")
- self.assertEqual(get_state_as_dict(top)["Checked"], "false")
- self.assertEqual(get_state_as_dict(bottom)["Checked"], "false")
-
- show.executeAction("CLICK", tuple())
-
- xOKBtn = xDialog.getChild("ok")
- self.ui_test.close_dialog_through_button(xOKBtn)
-
- #reopen and verify InsertMenuLegend dialog
- gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
- gridwin.executeAction("ACTIVATE", tuple())
- xChartMainTop = self.xUITest.getTopFocusWindow()
- xChartMain = xChartMainTop.getChild("chart_window")
- xSeriesObj = xChartMain.getChild("CID/D=0:CS=0:CT=0:Series=0")
- self.ui_test.execute_dialog_through_action(xSeriesObj, "COMMAND", mkPropertyValues({"COMMAND": "InsertMenuLegend"}))
- xDialog = self.xUITest.getTopFocusWindow()
-
- left = xDialog.getChild("left")
- right = xDialog.getChild("right")
- top = xDialog.getChild("top")
- bottom = xDialog.getChild("bottom")
- show = xDialog.getChild("show")
-
- self.assertEqual(get_state_as_dict(left)["Checked"], "true")
- self.assertEqual(get_state_as_dict(right)["Checked"], "false")
- self.assertEqual(get_state_as_dict(top)["Checked"], "false")
- self.assertEqual(get_state_as_dict(bottom)["Checked"], "false")
-
- self.assertEqual(get_state_as_dict(show)["Selected"], "false")
-
- xOKBtn = xDialog.getChild("ok")
- self.ui_test.close_dialog_through_button(xOKBtn)
- self.ui_test.close_doc()
+ with guarded.load_file(self, get_url_for_data_file("tdf98390.ods")) as calc_doc:
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ gridwin = xCalcDoc.getChild("grid_window")
+ document = self.ui_test.get_component()
+
+ gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
+ gridwin.executeAction("ACTIVATE", tuple())
+ xChartMainTop = self.xUITest.getTopFocusWindow()
+ xChartMain = xChartMainTop.getChild("chart_window")
+ xSeriesObj = xChartMain.getChild("CID/D=0:CS=0:CT=0:Series=0")
+ with guarded.execute_dialog_through_action(self, xSeriesObj, "COMMAND", mkPropertyValues({"COMMAND": "InsertMenuLegend"})) as xDialog:
+ left = xDialog.getChild("left")
+ right = xDialog.getChild("right")
+ top = xDialog.getChild("top")
+ bottom = xDialog.getChild("bottom")
+
+ left.executeAction("CLICK", tuple())
+
+ #reopen and verify InsertMenuLegend dialog
+ gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
+ gridwin.executeAction("ACTIVATE", tuple())
+ xChartMainTop = self.xUITest.getTopFocusWindow()
+ xChartMain = xChartMainTop.getChild("chart_window")
+ xSeriesObj = xChartMain.getChild("CID/D=0:CS=0:CT=0:Series=0")
+ with guarded.execute_dialog_through_action(self, xSeriesObj, "COMMAND", mkPropertyValues({"COMMAND": "InsertMenuLegend"})) as xDialog:
+ left = xDialog.getChild("left")
+ right = xDialog.getChild("right")
+ top = xDialog.getChild("top")
+ bottom = xDialog.getChild("bottom")
+ show = xDialog.getChild("show")
+
+ self.assertEqual(get_state_as_dict(left)["Checked"], "true")
+ self.assertEqual(get_state_as_dict(right)["Checked"], "false")
+ self.assertEqual(get_state_as_dict(top)["Checked"], "false")
+ self.assertEqual(get_state_as_dict(bottom)["Checked"], "false")
+
+ show.executeAction("CLICK", tuple())
+
+ #reopen and verify InsertMenuLegend dialog
+ gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
+ gridwin.executeAction("ACTIVATE", tuple())
+ xChartMainTop = self.xUITest.getTopFocusWindow()
+ xChartMain = xChartMainTop.getChild("chart_window")
+ xSeriesObj = xChartMain.getChild("CID/D=0:CS=0:CT=0:Series=0")
+ with guarded.execute_dialog_through_action(self, xSeriesObj, "COMMAND", mkPropertyValues({"COMMAND": "InsertMenuLegend"})) as xDialog:
+ left = xDialog.getChild("left")
+ right = xDialog.getChild("right")
+ top = xDialog.getChild("top")
+ bottom = xDialog.getChild("bottom")
+ show = xDialog.getChild("show")
+
+ self.assertEqual(get_state_as_dict(left)["Checked"], "true")
+ self.assertEqual(get_state_as_dict(right)["Checked"], "false")
+ self.assertEqual(get_state_as_dict(top)["Checked"], "false")
+ self.assertEqual(get_state_as_dict(bottom)["Checked"], "false")
+
+ self.assertEqual(get_state_as_dict(show)["Selected"], "false")
def test_legends_move_with_arrows_keys(self):
- calc_doc = self.ui_test.load_file(get_url_for_data_file("dataLabels.ods"))
- xCalcDoc = self.xUITest.getTopFocusWindow()
- gridwin = xCalcDoc.getChild("grid_window")
+ with guarded.load_file(self, get_url_for_data_file("dataLabels.ods")) as calc_doc:
+ xCalcDoc = self.xUITest.getTopFocusWindow()
+ gridwin = xCalcDoc.getChild("grid_window")
- change_measurement_unit(self, "Centimeter")
+ change_measurement_unit(self, "Centimeter")
- gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
- gridwin.executeAction("ACTIVATE", tuple())
- xChartMainTop = self.xUITest.getTopFocusWindow()
- xChartMain = xChartMainTop.getChild("chart_window")
+ gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 1"}))
+ gridwin.executeAction("ACTIVATE", tuple())
+ xChartMainTop = self.xUITest.getTopFocusWindow()
+ xChartMain = xChartMainTop.getChild("chart_window")
- # Select the legends
- xLegends = xChartMain.getChild("CID/D=0:Legend=")
- xLegends.executeAction("SELECT", tuple())
+ # Select the legends
+ xLegends = xChartMain.getChild("CID/D=0:Legend=")
+ xLegends.executeAction("SELECT", tuple())
- self.ui_test.execute_dialog_through_action(xLegends, "COMMAND", mkPropertyValues({"COMMAND": "TransformDialog"}))
+ with guarded.execute_dialog_through_action(self, xLegends, "COMMAND", mkPropertyValues({"COMMAND": "TransformDialog"})) as xDialog:
+ self.assertEqual("4.61", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
+ self.assertEqual("1.54", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
- xDialog = self.xUITest.getTopFocusWindow()
- self.assertEqual("4.61", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
- self.assertEqual("1.54", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
+ xChartMain.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
+ xChartMain.executeAction("TYPE", mkPropertyValues({"KEYCODE": "LEFT"}))
- xOkBtn = xDialog.getChild("ok")
- xOkBtn.executeAction("CLICK", tuple())
-
- xChartMain.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
- xChartMain.executeAction("TYPE", mkPropertyValues({"KEYCODE": "LEFT"}))
-
- self.ui_test.execute_dialog_through_action(xLegends, "COMMAND", mkPropertyValues({"COMMAND": "TransformDialog"}))
-
- # Check the position has changed after moving the label using the arrows keys
- xDialog = self.xUITest.getTopFocusWindow()
- self.assertEqual("4.51", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
- self.assertEqual("1.44", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
-
- xOkBtn = xDialog.getChild("ok")
- xOkBtn.executeAction("CLICK", tuple())
-
- self.ui_test.close_doc()
+ # Check the position has changed after moving the label using the arrows keys
+ with guarded.execute_dialog_through_action(self, xLegends, "COMMAND", mkPropertyValues({"COMMAND": "TransformDialog"})) as xDialog:
+ self.assertEqual("4.51", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_X"))['Value'])
+ self.assertEqual("1.44", get_state_as_dict(xDialog.getChild("MTR_FLD_POS_Y"))['Value'])
# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/uitest/uihelper/guarded.py b/uitest/uitest/uihelper/guarded.py
new file mode 100644
index 000000000000..b7e5ce099d1e
--- /dev/null
+++ b/uitest/uitest/uihelper/guarded.py
@@ -0,0 +1,31 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+from contextlib import contextmanager
+
+# Calls UITest.close_doc at exit
+ at contextmanager
+def load_file(testCase, url):
+ component = testCase.ui_test.load_file(url)
+ try:
+ yield component
+ finally:
+ testCase.ui_test.close_doc()
+
+# Calls UITest.close_dialog_through_button at exit
+ at contextmanager
+def execute_dialog_through_action(testCase, ui_object, action, parameters = None, event_name = "DialogExecute", close_button = "ok"):
+ testCase.ui_test.execute_dialog_through_action(ui_object, action, parameters, event_name)
+ xDialog = testCase.xUITest.getTopFocusWindow()
+ try:
+ yield xDialog
+ finally:
+ testCase.ui_test.close_dialog_through_button(xDialog.getChild(close_button))
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
More information about the Libreoffice-commits
mailing list