diff options
Diffstat (limited to 'uitest/uitest/uihelper')
-rw-r--r-- | uitest/uitest/uihelper/__init__.py | 0 | ||||
-rw-r--r-- | uitest/uitest/uihelper/calc.py | 16 | ||||
-rw-r--r-- | uitest/uitest/uihelper/common.py | 58 | ||||
-rw-r--r-- | uitest/uitest/uihelper/keyboard.py | 13 | ||||
-rw-r--r-- | uitest/uitest/uihelper/testDialog.py | 32 |
5 files changed, 119 insertions, 0 deletions
diff --git a/uitest/uitest/uihelper/__init__.py b/uitest/uitest/uihelper/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/uitest/uitest/uihelper/__init__.py diff --git a/uitest/uitest/uihelper/calc.py b/uitest/uitest/uihelper/calc.py new file mode 100644 index 000000000..e34304c69 --- /dev/null +++ b/uitest/uitest/uihelper/calc.py @@ -0,0 +1,16 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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 libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import type_text + +def enter_text_to_cell(gridwin, cell, text): + gridwin.executeAction("SELECT", mkPropertyValues({"CELL": cell})) + type_text(gridwin, text) + gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/uitest/uitest/uihelper/common.py b/uitest/uitest/uihelper/common.py new file mode 100644 index 000000000..ffdf90d48 --- /dev/null +++ b/uitest/uitest/uihelper/common.py @@ -0,0 +1,58 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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 libreoffice.uno.propertyvalue import convert_property_values_to_dict, mkPropertyValues +import org.libreoffice.unotest +import pathlib + +def get_state_as_dict(ui_object): + return convert_property_values_to_dict(ui_object.getState()) + +def type_text(ui_object, text): + ui_object.executeAction("TYPE", mkPropertyValues({"TEXT": text})) + +def select_pos(ui_object, pos): + assert isinstance(pos, str), "select_pos: POS must be of type str" + ui_object.executeAction("SELECT", mkPropertyValues({"POS": pos})) + +def select_by_text(ui_object, text): + ui_object.executeAction("SELECT", mkPropertyValues({"TEXT": text})) + +def select_text(ui_object, from_pos, to): + ui_object.executeAction("SELECT", mkPropertyValues({"FROM": from_pos, "TO": to})) + +def get_url_for_data_file(file_name): + return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri() + +def change_measurement_unit(UITestCase, unit): + with UITestCase.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialogOpt: + 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") + + # Impress + elif 'units' in xDialogOpt.getChildren(): + xUnit = xDialogOpt.getChild("units") + + select_by_text(xUnit, unit) + + # tdf#137930: Check apply button doesn't reset the value + xApplyBtn = xDialogOpt.getChild("apply") + xApplyBtn.executeAction("CLICK", tuple()) + UITestCase.assertEqual(unit, get_state_as_dict(xUnit)['SelectEntryText']) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/uitest/uitest/uihelper/keyboard.py b/uitest/uitest/uihelper/keyboard.py new file mode 100644 index 000000000..f2be76de4 --- /dev/null +++ b/uitest/uitest/uihelper/keyboard.py @@ -0,0 +1,13 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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 libreoffice.uno.propertyvalue import mkPropertyValues + +def select_all(ui_object): + ui_object.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"})) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/uitest/uitest/uihelper/testDialog.py b/uitest/uitest/uihelper/testDialog.py new file mode 100644 index 000000000..0e4436436 --- /dev/null +++ b/uitest/uitest/uihelper/testDialog.py @@ -0,0 +1,32 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# 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 uitest.framework import UITestCase +from uitest.uihelper.common import get_state_as_dict + +# opens the dialogs, closes it with the given close button +# 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): + with 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: + xOKBtn = None + + 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: |