diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-03 22:20:04 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-06-06 17:38:15 +0200 |
commit | 89aaa17a0a4413f07da2bc5084b0164f15dc01ac (patch) | |
tree | f7e207793fbab64e00af5a9ce6dfe2212af5e331 /uitest | |
parent | 3b75f9add7ed80e803b0771d86892d6ca0f47e71 (diff) |
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@collabora.com>
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/uitest/uihelper/guarded.py | 31 |
1 files changed, 31 insertions, 0 deletions
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 +@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 +@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: |