~xeranas/ubuntu-docviewer-app/unknown_file_type_test

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_docviewer_app/emulators/ubuntusdk.py

  • Committer: Tarmac
  • Author(s): Granger Anthony, nskaggs
  • Date: 2013-07-03 20:33:26 UTC
  • mfrom: (11.1.3 autopilot-hacking)
  • Revision ID: tarmac-20130703203326-6l232tsj1khrmw8i
Base for all future autopilot testcases.

Approved by Ubuntu Phone Apps Jenkins Bot, Anthony Granger.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
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
# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
 
18
 
 
19
from testtools.matchers import Equals, NotEquals, Not, Is
 
20
from autopilot.matchers import Eventually
 
21
 
 
22
class ubuntusdk(object):
 
23
    """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
 
24
 
 
25
    def __init__(self, autopilot, app):
 
26
        self.app = app
 
27
        self.autopilot = autopilot
 
28
 
 
29
    def get_qml_view(self):
 
30
        """Get the main QML view"""
 
31
        return self.app.select_single("QQuickView")
 
32
 
 
33
    def get_object(self, typeName, name):
 
34
        """Get a specific object"""
 
35
        return self.app.select_single(typeName, objectName=name)
 
36
 
 
37
    def get_objects(self, typeName, name):
 
38
        """Get more than one object"""
 
39
        return self.app.select_many(typeName, objectName=name)
 
40
 
 
41
    def switch_to_tab(self, tab):
 
42
        """Switch to the specified tab number"""
 
43
        tabs = self.get_tabs()
 
44
        currentTab = tabs.selectedTabIndex
 
45
 
 
46
        #perform operations until tab == currentTab
 
47
        while tab != currentTab:
 
48
            if tab > currentTab:
 
49
                self._previous_tab()
 
50
            if tab < currentTab:
 
51
                self._next_tab()
 
52
            currentTab = tabs.selectedTabIndex
 
53
 
 
54
    def toggle_toolbar(self):
 
55
        """Toggle the toolbar between revealed and hidden"""
 
56
        #check and see if the toolbar is open or not
 
57
        if self.get_toolbar().opened:
 
58
            self.hide_toolbar()
 
59
        else:
 
60
            self.open_toolbar()
 
61
 
 
62
    def get_toolbar(self):
 
63
        """Returns the toolbar in the main events view."""
 
64
        return self.app.select_single("Toolbar")
 
65
 
 
66
    def get_toolbar_button(self, button):
 
67
        """Returns the toolbar button at position index"""
 
68
        toolbar = self.get_toolbar()
 
69
        item = toolbar.get_children_by_type("QQuickItem")[0]
 
70
        row = item.get_children_by_type("QQuickRow")[0]
 
71
        buttonLoaders = row.get_children_by_type("QQuickLoader")
 
72
        buttonLoader = buttonLoaders[button]
 
73
        return buttonLoader
 
74
 
 
75
    def click_toolbar_button(self, value):
 
76
        """Clicks the toolbar button with value"""
 
77
        #The toolbar button is assumed to be the following format
 
78
        #ToolbarActions {
 
79
        #           Action {
 
80
        #               objectName: "name"
 
81
        #                text: value
 
82
        toolbar = self.get_toolbar()
 
83
        if not toolbar.opened:
 
84
            self.open_toolbar()
 
85
        item = toolbar.get_children_by_type("QQuickItem")[0]
 
86
        row = item.get_children_by_type("QQuickRow")[0]
 
87
        buttonList = row.get_children_by_type("QQuickLoader")
 
88
        for button in buttonList:
 
89
            itemList = lambda: self.get_objects("Action", button)
 
90
 
 
91
            for item in itemList():
 
92
                if item.get_properties()['text'] == value:
 
93
                    self.autopilot.pointing_device.click_object(item)
 
94
 
 
95
    def open_toolbar(self):
 
96
        """Open the toolbar"""
 
97
        qmlView = self.get_qml_view()
 
98
 
 
99
        lineX = qmlView.x + qmlView.width * 0.50
 
100
        startY = qmlView.y + qmlView.height - 1
 
101
        stopY = qmlView.y + qmlView.height - 200
 
102
 
 
103
        self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
 
104
        self.autopilot.pointing_device.click()
 
105
        self.autopilot.pointing_device.click()
 
106
 
 
107
    def hide_toolbar(self):
 
108
        """Hide the toolbar"""
 
109
        qmlView = self.get_qml_view()
 
110
 
 
111
        lineX = qmlView.x + qmlView.width * 0.50
 
112
        startY = qmlView.y + qmlView.height - 200
 
113
        stopY = qmlView.y + qmlView.height - 1
 
114
 
 
115
        self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
 
116
        self.autopilot.pointing_device.click()
 
117
        self.autopilot.pointing_device.click()
 
118
 
 
119
    def set_popup_value(self, popover, button, value):
 
120
        """Changes the given popover selector to the request value
 
121
        At the moment this only works for values that are currently visible. To
 
122
        access the remaining items, a help method to drag and recheck is needed."""
 
123
        #The popover is assumed to be the following format
 
124
        #    Popover {
 
125
        #        Column {
 
126
        #            ListView {
 
127
        #                delegate: Standard {
 
128
        #                    objectName: "name"
 
129
        #                    text: value
 
130
 
 
131
        self.autopilot.pointing_device.click_object(button)
 
132
        #we'll get all matching objects, incase the popover is reused between buttons
 
133
        itemList = lambda: self.get_objects("Standard", popover)
 
134
 
 
135
        for item in itemList():
 
136
            if item.get_properties()['text'] == value:
 
137
                self.autopilot.pointing_device.click_object(item)
 
138
 
 
139
    def get_tabs(self):
 
140
        """Return all tabs"""
 
141
        return self.get_object("Tabs", "rootTabs")
 
142
 
 
143
    def _previous_tab(self):
 
144
        """Switch to the previous tab"""
 
145
        qmlView = self.get_qml_view()
 
146
 
 
147
        startX = qmlView.x + qmlView.width * 0.20
 
148
        stopX = qmlView.x + qmlView.width * 0.50
 
149
        lineY = qmlView.y + qmlView.height * 0.05
 
150
 
 
151
        self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
 
152
        self.autopilot.pointing_device.click()
 
153
        self.autopilot.pointing_device.click()
 
154
 
 
155
    def _next_tab(self):
 
156
        """Switch to the next tab"""
 
157
        qmlView = self.get_qml_view()
 
158
 
 
159
        startX = qmlView.x + qmlView.width * 0.50
 
160
        stopX = qmlView.x + qmlView.width * 0.20
 
161
        lineY = qmlView.y + qmlView.height * 0.05
 
162
 
 
163
        self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
 
164
        self.autopilot.pointing_device.click()
 
165
        self.autopilot.pointing_device.click()