Merge lp:~nskaggs/ubuntu-sdk-tutorials/autopilot into lp:ubuntu-sdk-tutorials

Proposed by Nicholas Skaggs
Status: Merged
Merged at revision: 15
Proposed branch: lp:~nskaggs/ubuntu-sdk-tutorials/autopilot
Merge into: lp:ubuntu-sdk-tutorials
Diff against target: 284 lines (+175/-28)
5 files modified
CurrencyConverter/CurrencyConverter.qml (+2/-2)
CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py (+0/-8)
CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py (+165/-0)
CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py (+5/-1)
CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py (+3/-17)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-sdk-tutorials/autopilot
Reviewer Review Type Date Requested Status
David Planella Approve
Review via email: mp+168828@code.launchpad.net

Description of the change

Update autopilot tests to use the ubuntu sdk emulator and fix the error with selecting

To post a comment you must log in.
Revision history for this message
David Planella (dpm) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CurrencyConverter/CurrencyConverter.qml'
2--- CurrencyConverter/CurrencyConverter.qml 2013-06-05 16:58:12 +0000
3+++ CurrencyConverter/CurrencyConverter.qml 2013-06-11 23:01:26 +0000
4@@ -16,7 +16,7 @@
5
6 width: units.gu(100)
7 height: units.gu(75)
8-
9+
10 property real margins: units.gu(2)
11 property real buttonWidth: units.gu(9)
12
13@@ -85,7 +85,7 @@
14 height: parent.height - header.height
15 model: currencies
16 delegate: Standard {
17- objectName: "currencySelectorList"
18+ objectName: "popoverCurrencySelector"
19 text: currency
20 onClicked: {
21 caller.currencyIndex = index
22
23=== modified file 'CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py'
24--- CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 2013-06-05 16:58:12 +0000
25+++ CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 2013-06-11 23:01:26 +0000
26@@ -23,10 +23,6 @@
27 def __init__(self, app):
28 self.app = app
29
30- def get_qml_view(self):
31- """Get the main QML view"""
32- return self.app.select_single("QQuickView")
33-
34 def get_clear_button(self):
35 """Returns the clear button object"""
36 return self.app.select_single("Button", objectName="clearBtn")
37@@ -46,7 +42,3 @@
38 def get_to_currency_button(self):
39 """Returns the select for the to currency field"""
40 return self.app.select_single("Button", objectName="selectorTo")
41-
42- def get_object(self, typeName, name):
43- """Returns an object using select_single method from autopilot """
44- return self.app.select_single(typeName, objectName=name)
45
46=== added file 'CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py'
47--- CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
48+++ CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py 2013-06-11 23:01:26 +0000
49@@ -0,0 +1,165 @@
50+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
51+#
52+# Copyright (C) 2013 Canonical Ltd
53+#
54+# This program is free software: you can redistribute it and/or modify
55+# it under the terms of the GNU General Public License version 3 as
56+# published by the Free Software Foundation.
57+#
58+# This program is distributed in the hope that it will be useful,
59+# but WITHOUT ANY WARRANTY; without even the implied warranty of
60+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61+# GNU General Public License for more details.
62+#
63+# You should have received a copy of the GNU General Public License
64+# along with this program. If not, see <http://www.gnu.org/licenses/>.
65+#
66+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
67+
68+from testtools.matchers import Equals, NotEquals, Not, Is
69+from autopilot.matchers import Eventually
70+
71+class ubuntusdk(object):
72+ """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
73+
74+ def __init__(self, autopilot, app):
75+ self.app = app
76+ self.autopilot = autopilot
77+
78+ def get_qml_view(self):
79+ """Get the main QML view"""
80+ return self.app.select_single("QQuickView")
81+
82+ def get_object(self, typeName, name):
83+ """Get a specific object"""
84+ return self.app.select_single(typeName, objectName=name)
85+
86+ def get_objects(self, typeName, name):
87+ """Get more than one object"""
88+ return self.app.select_many(typeName, objectName=name)
89+
90+ def switch_to_tab(self, tab):
91+ """Switch to the specified tab number"""
92+ tabs = self.get_tabs()
93+ currentTab = tabs.selectedTabIndex
94+
95+ #perform operations until tab == currentTab
96+ while tab != currentTab:
97+ if tab > currentTab:
98+ self._previous_tab()
99+ if tab < currentTab:
100+ self._next_tab()
101+ currentTab = tabs.selectedTabIndex
102+
103+ def toggle_toolbar(self):
104+ """Toggle the toolbar between revealed and hidden"""
105+ #check and see if the toolbar is open or not
106+ if self.get_toolbar().opened:
107+ self.hide_toolbar()
108+ else:
109+ self.open_toolbar()
110+
111+ def get_toolbar(self):
112+ """Returns the toolbar in the main events view."""
113+ return self.app.select_single("Toolbar")
114+
115+ def get_toolbar_button(self, button):
116+ """Returns the toolbar button at position index"""
117+ toolbar = self.get_toolbar()
118+ item = toolbar.get_children_by_type("QQuickItem")[0]
119+ row = item.get_children_by_type("QQuickRow")[0]
120+ buttonLoaders = row.get_children_by_type("QQuickLoader")
121+ buttonLoader = buttonLoaders[button]
122+ return buttonLoader
123+
124+ def click_toolbar_button(self, value):
125+ """Clicks the toolbar button with value"""
126+ #The toolbar button is assumed to be the following format
127+ #ToolbarActions {
128+ # Action {
129+ # objectName: "name"
130+ # text: value
131+ toolbar = self.get_toolbar()
132+ if not toolbar.opened:
133+ self.open_toolbar()
134+ item = toolbar.get_children_by_type("QQuickItem")[0]
135+ row = item.get_children_by_type("QQuickRow")[0]
136+ buttonList = row.get_children_by_type("QQuickLoader")
137+ for button in buttonList:
138+ itemList = lambda: self.get_objects("Action", button)
139+
140+ for item in itemList():
141+ if item.get_properties()['text'] == value:
142+ self.autopilot.pointing_device.click_object(item)
143+
144+ def open_toolbar(self):
145+ """Open the toolbar"""
146+ qmlView = self.get_qml_view()
147+
148+ lineX = qmlView.x + qmlView.width * 0.50
149+ startY = qmlView.y + qmlView.height - 1
150+ stopY = qmlView.y + qmlView.height - 200
151+
152+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
153+ self.autopilot.pointing_device.click()
154+ self.autopilot.pointing_device.click()
155+
156+ def hide_toolbar(self):
157+ """Hide the toolbar"""
158+ qmlView = self.get_qml_view()
159+
160+ lineX = qmlView.x + qmlView.width * 0.50
161+ startY = qmlView.y + qmlView.height - 200
162+ stopY = qmlView.y + qmlView.height - 1
163+
164+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
165+ self.autopilot.pointing_device.click()
166+ self.autopilot.pointing_device.click()
167+
168+ def set_popup_value(self, popover, button, value):
169+ """Changes the given popover selector to the request value
170+ At the moment this only works for values that are currently visible. To
171+ access the remaining items, a help method to drag and recheck is needed."""
172+ #The popover is assumed to be the following format
173+ # Popover {
174+ # Column {
175+ # ListView {
176+ # delegate: Standard {
177+ # objectName: "name"
178+ # text: value
179+
180+ self.autopilot.pointing_device.click_object(button)
181+ #we'll get all matching objects, incase the popover is reused between buttons
182+ itemList = lambda: self.get_objects("Standard", popover)
183+
184+ for item in itemList():
185+ if item.get_properties()['text'] == value:
186+ self.autopilot.pointing_device.click_object(item)
187+
188+ def get_tabs(self):
189+ """Return all tabs"""
190+ return self.get_object("Tabs", "rootTabs")
191+
192+ def _previous_tab(self):
193+ """Switch to the previous tab"""
194+ qmlView = self.get_qml_view()
195+
196+ startX = qmlView.x + qmlView.width * 0.20
197+ stopX = qmlView.x + qmlView.width * 0.50
198+ lineY = qmlView.y + qmlView.height * 0.05
199+
200+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
201+ self.autopilot.pointing_device.click()
202+ self.autopilot.pointing_device.click()
203+
204+ def _next_tab(self):
205+ """Switch to the next tab"""
206+ qmlView = self.get_qml_view()
207+
208+ startX = qmlView.x + qmlView.width * 0.50
209+ stopX = qmlView.x + qmlView.width * 0.20
210+ lineY = qmlView.y + qmlView.height * 0.05
211+
212+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
213+ self.autopilot.pointing_device.click()
214+ self.autopilot.pointing_device.click()
215
216=== modified file 'CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py'
217--- CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py 2013-06-05 16:58:12 +0000
218+++ CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py 2013-06-11 23:01:26 +0000
219@@ -27,7 +27,7 @@
220 from autopilot.testcase import AutopilotTestCase
221
222 from CurrencyConverter.emulators.main_window import MainWindow
223-
224+from CurrencyConverter.emulators.ubuntusdk import ubuntusdk
225
226 class CurrencyConverterTestCase(AutopilotTestCase):
227
228@@ -67,3 +67,7 @@
229 @property
230 def main_window(self):
231 return MainWindow(self.app)
232+
233+ @property
234+ def ubuntusdk(self):
235+ return ubuntusdk(self, self.app)
236
237=== modified file 'CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py'
238--- CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py 2013-06-05 16:58:12 +0000
239+++ CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py 2013-06-11 23:01:26 +0000
240@@ -33,25 +33,11 @@
241 def setUp(self):
242 super(TestCurrencyConverter, self).setUp()
243 self.assertThat(
244- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
245+ self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))
246
247 def tearDown(self):
248 super(TestCurrencyConverter, self).tearDown()
249
250- def _set_currency(self, button, currency):
251- """Changes the given currency selector to the requested currency
252-
253- This only works for currencies that are currently visible. To
254- access the remaining items, a help method to drag and recheck is
255- needed."""
256- self.pointing_device.click_object(button)
257- item_list = lambda: self.main_window.get_object("Standard","currencySelectorList")
258-
259- self.assertThat(item_list, Eventually(NotEquals(None)))
260- for item in item_list():
261- if item.get_properties()['text'] == currency:
262- self.pointing_device.click_object(item)
263-
264 """ Test if the currency rate is converted """
265 def test_convert_currency(self):
266 fromField = self.main_window.get_from_currency_field()
267@@ -78,7 +64,7 @@
268 oldToValue = toField.text
269
270 #change the from currency
271- self._set_currency(fromCurrencyButton, 'HUF')
272+ self.ubuntusdk.set_popup_value("popoverCurrencySelector", fromCurrencyButton, 'HUF')
273
274 #verify fromField was updated and toField is still the same
275 self.assertThat(fromField.text, Eventually(NotEquals(oldFromValue)))
276@@ -89,7 +75,7 @@
277 oldToValue = toField.text
278
279 #change the to currency
280- self._set_currency(toCurrencyButton, 'BGN')
281+ self.ubuntusdk.set_popup_value("popoverCurrencySelector", toCurrencyButton, 'BGN')
282
283 #verify fromField is the same and toField is updated
284 self.assertThat(fromField.text, Eventually(Equals(oldFromValue)))

Subscribers

People subscribed via source and target branches