1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# -*- 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
from contextlib import contextmanager
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()
@contextmanager
def change_measurement_unit(UITestCase, unit):
try:
launch_option_dialog(UITestCase, unit)
yield
finally:
# change to default value
launch_option_dialog(UITestCase, 'Inch')
def launch_option_dialog(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:
|