1
# blackbox testing of autopilot API against our hello_color.py test GTK program
2
# Author: Martin Pitt <martin.pitt@ubuntu.com>
3
# Copyright (C) 2013 Canonical Ltd
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 3 as
7
# published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
from autopilot.testcase import AutopilotTestCase
22
tests_dir = os.path.dirname(os.path.dirname(os.path.dirname(
23
os.path.realpath(__file__))))
24
test_app = os.path.join(tests_dir, 'hello_color.py')
27
class XPathQueryTest(AutopilotTestCase):
31
super(XPathQueryTest, self).setUp()
32
self.app = self.launch_test_application(test_app, app_type='gtk')
34
def xtest_have_path(self):
35
"""All children have a unique path"""
38
self._get_widgets(self.app, widgets)
41
for widget in widgets:
42
path = widget.get_class_query_string()
43
self.assertNotIn(path, seen_paths)
46
# we can resolve the path back to the widget
47
state = self.app.get_state_by_path(path)
48
# state is an array with one (path, props) element
50
self.assertEqual(props['id'], widget.id)
51
self.assertEqual(props['visible'], widget.visible)
53
def xtest_select_full_path(self):
54
"""Select widgets with full XPath"""
56
# three buttons in main dialog's ButtonBox
57
state = self.app.get_state_by_path('/Root/GtkWindow/GtkBox/GtkButtonBox/GtkButton')
58
self.assertEqual(len(state), 3)
59
labels = [str(props[1]['label']) for props in state]
61
self.assertEqual(labels, ['Greet', 'gtk-delete', 'gtk-quit'])
63
# select button with particular label
64
for l in ['Greet', 'gtk-delete', 'gtk-quit']:
65
state = self.app.get_state_by_path('/Root/GtkWindow/GtkBox/GtkButtonBox/GtkButton[label=%s]' % l)
66
self.assertEqual(len(state), 1)
67
self.assertEqual(state[0][1]['label'], l)
69
def xtest_select_path_pattern(self):
70
"""Select widgets with XPath path pattern"""
72
# three buttons in main dialog's ButtonBox
73
state = self.app.get_state_by_path('//GtkWindow//GtkButton')
74
self.assertEqual(len(state), 3)
75
labels = [str(props[1]['label']) for props in state]
77
self.assertEqual(labels, ['Greet', 'gtk-delete', 'gtk-quit'])
79
# at least four buttons in the whole tree
80
state = self.app.get_state_by_path('/Root//GtkButton')
81
self.assertGreaterEqual(len(state), 4)
83
def test_select_by_attribute(self):
84
"""Select widgets with attribute pattern"""
86
state = self.app.get_state_by_path('//*[label=gtk-delete]')
87
self.assertEqual(len(state), 1, state)
88
self.assertEqual(state[0][1]['label'], 'gtk-delete')
89
self.assertTrue(state[0][0].endswith('/GtkButton'), state[0][0])
91
# https://launchpad.net/bugs/1179806
92
@unittest.expectedFailure
93
def test_select_by_attribute_spaces(self):
94
"""Select widgets with attribute pattern containing spaces"""
96
# none of these work ATM, but are supposed to:
97
#state = self.app.get_state_by_path('//*[label=Hello Color!]')
98
#state = self.app.get_state_by_path('//*[label=Hello Color!]')
99
state = self.app.get_state_by_path('//*[label="Hello Color!"]')
100
self.assertEqual(len(state), 1, str(state))
101
self.assertEqual(state[0][1]['label'], 'Hello Color!')
102
self.assertTrue(state[0][0].endswith('/GtkLabel'), state[0][0])
105
def _get_widgets(klass, obj, widget_set):
106
"""Recursively add all children of obj to widget_set"""
108
for c in obj.get_children():
110
klass._get_widgets(c, widget_set)