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, buttonLabel):
67
"""Returns the toolbar button at position index"""
68
toolbar = self.get_toolbar()
69
if not toolbar.opened:
71
row = toolbar.select_single("QQuickRow")
72
loaderList = row.select_many("QQuickLoader")
73
for loader in loaderList:
74
buttonList = loader.select_many("Button")
75
for button in buttonList:
76
if button.text == buttonLabel:
79
def click_toolbar_button(self, buttonLabel):
80
"""Clicks the toolbar button with buttonLabel"""
81
#The toolbar button is assumed to be the following format
86
button = self.get_toolbar_button(buttonLabel)
87
self.autopilot.pointing_device.click_object(button)
89
def open_toolbar(self):
90
"""Open the toolbar"""
91
qmlView = self.get_qml_view()
93
lineX = qmlView.x + qmlView.width * 0.50
94
startY = qmlView.y + qmlView.height - 1
95
stopY = qmlView.y + qmlView.height * 0.95
97
self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
99
def hide_toolbar(self):
100
"""Hide the toolbar"""
101
qmlView = self.get_qml_view()
103
lineX = qmlView.x + qmlView.width * 0.50
104
startY = qmlView.y + qmlView.height * 0.95
105
stopY = qmlView.y + qmlView.height - 1
107
self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
109
def set_popup_value(self, popover, button, value):
110
"""Changes the given popover selector to the request value
111
At the moment this only works for values that are currently visible. To
112
access the remaining items, a help method to drag and recheck is needed."""
113
#The popover is assumed to be the following format
117
# delegate: Standard {
121
self.autopilot.pointing_device.click_object(button)
122
#we'll get all matching objects, incase the popover is reused between buttons
123
itemList = lambda: self.get_objects("Standard", popover)
125
for item in itemList():
126
if item.get_properties()['text'] == value:
127
self.autopilot.pointing_device.click_object(item)
130
"""Return all tabs"""
131
return self.get_object("Tabs", "rootTabs")
133
def _previous_tab(self):
134
"""Switch to the previous tab"""
135
qmlView = self.get_qml_view()
137
startX = qmlView.x + qmlView.width * 0.35
138
stopX = qmlView.x + qmlView.width * 0.50
139
lineY = qmlView.y + qmlView.height * 0.05
141
self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
142
self.autopilot.pointing_device.click()
143
self.autopilot.pointing_device.click()
146
"""Switch to the next tab"""
147
qmlView = self.get_qml_view()
149
startX = qmlView.x + qmlView.width * 0.50
150
stopX = qmlView.x + qmlView.width * 0.35
151
lineY = qmlView.y + qmlView.height * 0.05
153
self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
154
self.autopilot.pointing_device.click()