1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
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/>.
17
# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
19
from testtools.matchers import Equals, NotEquals, Not, Is
20
from autopilot.matchers import Eventually
22
class ubuntusdk(object):
23
"""An emulator class that makes it easy to interact with the ubuntu sdk applications."""
25
def __init__(self, autopilot, app):
27
self.autopilot = autopilot
29
def get_qml_view(self):
30
"""Get the main QML view"""
31
return self.app.select_single("QQuickView")
33
def get_object(self, typeName, name):
34
"""Get a specific object"""
35
return self.app.select_single(typeName, objectName=name)
37
def get_objects(self, typeName, name):
38
"""Get more than one object"""
39
return self.app.select_many(typeName, objectName=name)
41
def switch_to_tab(self, tab):
42
"""Switch to the specified tab number"""
43
tabs = self.get_tabs()
44
currentTab = tabs.selectedTabIndex
46
#perform operations until tab == currentTab
47
while tab != currentTab:
52
currentTab = tabs.selectedTabIndex
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:
62
def get_toolbar(self):
63
"""Returns the toolbar in the main events view."""
64
return self.app.select_single("Toolbar")
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]
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
82
toolbar = self.get_toolbar()
83
if not toolbar.opened:
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)
91
for item in itemList():
92
if item.get_properties()['text'] == value:
93
self.autopilot.pointing_device.click_object(item)
95
def open_toolbar(self):
96
"""Open the toolbar"""
97
qmlView = self.get_qml_view()
99
lineX = qmlView.x + qmlView.width * 0.50
100
startY = qmlView.y + qmlView.height - 1
101
stopY = qmlView.y + qmlView.height - 200
103
self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
104
self.autopilot.pointing_device.click()
105
self.autopilot.pointing_device.click()
107
def hide_toolbar(self):
108
"""Hide the toolbar"""
109
qmlView = self.get_qml_view()
111
lineX = qmlView.x + qmlView.width * 0.50
112
startY = qmlView.y + qmlView.height - 200
113
stopY = qmlView.y + qmlView.height - 1
115
self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
116
self.autopilot.pointing_device.click()
117
self.autopilot.pointing_device.click()
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
127
# delegate: Standard {
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)
135
for item in itemList():
136
if item.get_properties()['text'] == value:
137
self.autopilot.pointing_device.click_object(item)
140
"""Return all tabs"""
141
return self.get_object("Tabs", "rootTabs")
143
def _previous_tab(self):
144
"""Switch to the previous tab"""
145
qmlView = self.get_qml_view()
147
startX = qmlView.x + qmlView.width * 0.20
148
stopX = qmlView.x + qmlView.width * 0.50
149
lineY = qmlView.y + qmlView.height * 0.05
151
self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
152
self.autopilot.pointing_device.click()
153
self.autopilot.pointing_device.click()
156
"""Switch to the next tab"""
157
qmlView = self.get_qml_view()
159
startX = qmlView.x + qmlView.width * 0.50
160
stopX = qmlView.x + qmlView.width * 0.20
161
lineY = qmlView.y + qmlView.height * 0.05
163
self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
164
self.autopilot.pointing_device.click()
165
self.autopilot.pointing_device.click()