~pitti/autopilot-gtk/gtktextbuffer

« back to all changes in this revision

Viewing changes to tests/autopilot/tests/test_xpath_query.py

  • Committer: Tarmac
  • Author(s): Martin Pitt
  • Date: 2013-06-26 17:03:00 UTC
  • mfrom: (43.2.25 ap-gtk-tests)
  • Revision ID: tarmac-20130626170300-1yfj1vyv21n257xr
Add integration test suite (LP: #1083612). Fixes: https://bugs.launchpad.net/bugs/1083612.

Approved by Francis Ginther, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
 
 
17
import os.path
 
18
import unittest
 
19
 
 
20
from autopilot.testcase import AutopilotTestCase
 
21
 
 
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')
 
25
 
 
26
 
 
27
class XPathQueryTest(AutopilotTestCase):
 
28
    """XPath queries"""
 
29
 
 
30
    def setUp(self):
 
31
        super(XPathQueryTest, self).setUp()
 
32
        self.app = self.launch_test_application(test_app, app_type='gtk')
 
33
 
 
34
    def xtest_have_path(self):
 
35
        """All children have a unique path"""
 
36
 
 
37
        widgets = set()
 
38
        self._get_widgets(self.app, widgets)
 
39
 
 
40
        seen_paths = set()
 
41
        for widget in widgets:
 
42
            path = widget.get_class_query_string()
 
43
            self.assertNotIn(path, seen_paths)
 
44
            seen_paths.add(path)
 
45
 
 
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
 
49
            props = state[0][1]
 
50
            self.assertEqual(props['id'], widget.id)
 
51
            self.assertEqual(props['visible'], widget.visible)
 
52
 
 
53
    def xtest_select_full_path(self):
 
54
        """Select widgets with full XPath"""
 
55
 
 
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]
 
60
        labels.sort()
 
61
        self.assertEqual(labels, ['Greet', 'gtk-delete', 'gtk-quit'])
 
62
 
 
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)
 
68
 
 
69
    def xtest_select_path_pattern(self):
 
70
        """Select widgets with XPath path pattern"""
 
71
 
 
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]
 
76
        labels.sort()
 
77
        self.assertEqual(labels, ['Greet', 'gtk-delete', 'gtk-quit'])
 
78
 
 
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)
 
82
 
 
83
    def test_select_by_attribute(self):
 
84
        """Select widgets with attribute pattern"""
 
85
 
 
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])
 
90
 
 
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"""
 
95
 
 
96
        # none of these work ATM, but are supposed to:
 
97
        #state = self.app.get_state_by_path('//*[label=Hello&#x20;Color!]')
 
98
        #state = self.app.get_state_by_path('//*[label=Hello&#x0020;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])
 
103
 
 
104
    @classmethod
 
105
    def _get_widgets(klass, obj, widget_set):
 
106
        """Recursively add all children of obj to widget_set"""
 
107
 
 
108
        for c in obj.get_children():
 
109
            widget_set.add(c)
 
110
            klass._get_widgets(c, widget_set)