Merge lp:~nskaggs/sudoku-app/add-emulator-autopilot into lp:sudoku-app

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 72
Merged at revision: 73
Proposed branch: lp:~nskaggs/sudoku-app/add-emulator-autopilot
Merge into: lp:sudoku-app
Diff against target: 326 lines (+208/-71)
5 files modified
tests/autopilot/sudoku_app/__init__.py (+0/-49)
tests/autopilot/sudoku_app/emulators/main_window.py (+0/-7)
tests/autopilot/sudoku_app/emulators/ubuntusdk.py (+151/-0)
tests/autopilot/sudoku_app/tests/__init__.py (+55/-1)
tests/autopilot/sudoku_app/tests/test_sudoku.py (+2/-14)
To merge this branch: bzr merge lp:~nskaggs/sudoku-app/add-emulator-autopilot
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Sudoku Touch developers Pending
Review via email: mp+174245@code.launchpad.net

Commit message

Add the ubuntu sdk emulator for use with autopilot

Description of the change

Add the ubuntu sdk emulator for use with autopilot

To post a comment you must log in.
71. By Nicholas Skaggs

fix import issue

72. By Nicholas Skaggs

fix mainwindow function call deprecation

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/sudoku_app/__init__.py'
2--- tests/autopilot/sudoku_app/__init__.py 2013-07-08 18:15:44 +0000
3+++ tests/autopilot/sudoku_app/__init__.py 2013-07-11 17:01:25 +0000
4@@ -4,52 +4,3 @@
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License version 3, as published
7 # by the Free Software Foundation.
8-
9-"""Sudoku app autopilot tests."""
10-
11-import os.path
12-
13-from autopilot.input import Mouse, Touch, Pointer
14-from autopilot.platform import model
15-from autopilot.testcase import AutopilotTestCase
16-
17-from sudoku_app.emulators.main_window import MainWindow
18-
19-
20-class SudokuTestCase(AutopilotTestCase):
21-
22- """A common test case class that provides several useful methods for
23- sudoku-app tests.
24-
25- """
26- if model() == 'Desktop':
27- scenarios = [('with mouse', dict(input_device_class=Mouse))]
28- else:
29- scenarios = [('with touch', dict(input_device_class=Touch))]
30-
31- local_location = "../../sudoku-app.qml"
32-
33- def setUp(self):
34- self.pointing_device = Pointer(self.input_device_class.create())
35- super(SudokuTestCase, self).setUp()
36- if os.path.exists(self.local_location):
37- self.launch_test_local()
38- else:
39- self.launch_test_installed()
40-
41- def launch_test_local(self):
42- self.app = self.launch_test_application(
43- "qmlscene",
44- self.local_location,
45- app_type='qt')
46-
47- def launch_test_installed(self):
48- self.app = self.launch_test_application(
49- "qmlscene",
50- "/usr/share/sudoku-app/sudoku-app.qml",
51- "--desktop_file_hint=/usr/share/applications/sudoku-app.desktop",
52- app_type='qt')
53-
54- @property
55- def main_window(self):
56- return MainWindow(self.app)
57
58=== modified file 'tests/autopilot/sudoku_app/emulators/main_window.py'
59--- tests/autopilot/sudoku_app/emulators/main_window.py 2013-07-08 18:54:35 +0000
60+++ tests/autopilot/sudoku_app/emulators/main_window.py 2013-07-11 17:01:25 +0000
61@@ -15,10 +15,3 @@
62 """
63 def __init__(self, app):
64 self.app = app
65-
66- def get_qml_view(self):
67- """Get the main QML view"""
68- return self.app.select_single("QQuickView")
69-
70- def get_toolbar(self):
71- return self.app.select_single("Toolbar")
72
73=== added file 'tests/autopilot/sudoku_app/emulators/ubuntusdk.py'
74--- tests/autopilot/sudoku_app/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
75+++ tests/autopilot/sudoku_app/emulators/ubuntusdk.py 2013-07-11 17:01:25 +0000
76@@ -0,0 +1,151 @@
77+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
78+#
79+# Copyright (C) 2013 Canonical Ltd
80+#
81+# This program is free software: you can redistribute it and/or modify
82+# it under the terms of the GNU General Public License version 3 as
83+# published by the Free Software Foundation.
84+#
85+# This program is distributed in the hope that it will be useful,
86+# but WITHOUT ANY WARRANTY; without even the implied warranty of
87+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88+# GNU General Public License for more details.
89+#
90+# You should have received a copy of the GNU General Public License
91+# along with this program. If not, see <http://www.gnu.org/licenses/>.
92+#
93+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
94+
95+from testtools.matchers import Equals, NotEquals, Not, Is
96+from autopilot.matchers import Eventually
97+
98+class ubuntusdk(object):
99+ """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
100+
101+ def __init__(self, autopilot, app):
102+ self.app = app
103+ self.autopilot = autopilot
104+
105+ def get_qml_view(self):
106+ """Get the main QML view"""
107+ return self.app.select_single("QQuickView")
108+
109+ def get_object(self, typeName, name):
110+ """Get a specific object"""
111+ return self.app.select_single(typeName, objectName=name)
112+
113+ def get_objects(self, typeName, name):
114+ """Get more than one object"""
115+ return self.app.select_many(typeName, objectName=name)
116+
117+ def switch_to_tab(self, tab):
118+ """Switch to the specified tab number"""
119+ tabs = self.get_tabs()
120+ currentTab = tabs.selectedTabIndex
121+
122+ #perform operations until tab == currentTab
123+ while tab != currentTab:
124+ if tab > currentTab:
125+ self._previous_tab()
126+ if tab < currentTab:
127+ self._next_tab()
128+ currentTab = tabs.selectedTabIndex
129+
130+ def toggle_toolbar(self):
131+ """Toggle the toolbar between revealed and hidden"""
132+ #check and see if the toolbar is open or not
133+ if self.get_toolbar().opened:
134+ self.hide_toolbar()
135+ else:
136+ self.open_toolbar()
137+
138+ def get_toolbar(self):
139+ """Returns the toolbar in the main events view."""
140+ return self.app.select_single("Toolbar")
141+
142+ def get_toolbar_button(self, buttonObject):
143+ """Returns the toolbar button with objectName buttonObject"""
144+ toolbar = self.get_toolbar()
145+ if not toolbar.opened:
146+ self.open_toolbar()
147+ buttonList = toolbar.select_many("ActionItem")
148+ for button in buttonList:
149+ if button.objectName == buttonObject:
150+ return button
151+
152+ def click_toolbar_button(self, buttonObject):
153+ """Clicks the toolbar button with objectName buttonObject"""
154+ #The toolbar button is assumed to be the following format
155+ #Toolbar {
156+ # ...
157+ # ActionItem {
158+ # objectName: "name"
159+ button = self.get_toolbar_button(buttonObject)
160+ self.autopilot.pointing_device.click_object(button)
161+ return button
162+
163+ def open_toolbar(self):
164+ """Open the toolbar"""
165+ qmlView = self.get_qml_view()
166+
167+ lineX = int(qmlView.x + qmlView.width * 0.50)
168+ startY = int(qmlView.y + qmlView.height - 1)
169+ stopY = int(qmlView.y + qmlView.height * 0.95)
170+
171+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
172+
173+ def hide_toolbar(self):
174+ """Hide the toolbar"""
175+ qmlView = self.get_qml_view()
176+
177+ lineX = int(qmlView.x + qmlView.width * 0.50)
178+ startY = int(qmlView.y + qmlView.height * 0.95)
179+ stopY = int(qmlView.y + qmlView.height - 1)
180+
181+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
182+
183+ def set_popup_value(self, popover, button, value):
184+ """Changes the given popover selector to the request value
185+ At the moment this only works for values that are currently visible. To
186+ access the remaining items, a help method to drag and recheck is needed."""
187+ #The popover is assumed to be the following format
188+ #Component {
189+ # id: actionSelectionPopover
190+ #
191+ #ActionSelectionPopover {
192+ # actions: ActionList {
193+ # Action {
194+
195+ popList = self.get_object("ActionSelectionPopover", popover)
196+ itemList = popList.select_many("Label")
197+ for item in itemList:
198+ if item.text == value:
199+ self.autopilot.pointing_device.click_object(item)
200+ return item
201+
202+ def get_tabs(self):
203+ """Return all tabs"""
204+ return self.get_object("Tabs", "rootTabs")
205+
206+ def _previous_tab(self):
207+ """Switch to the previous tab"""
208+ qmlView = self.get_qml_view()
209+
210+ startX = int(qmlView.x + qmlView.width * 0.35)
211+ stopX = int(qmlView.x + qmlView.width * 0.50)
212+ lineY = int(qmlView.y + qmlView.height * 0.05)
213+
214+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
215+ self.autopilot.pointing_device.click()
216+ self.autopilot.pointing_device.click()
217+
218+ def _next_tab(self):
219+ """Switch to the next tab"""
220+ qmlView = self.get_qml_view()
221+
222+ startX = int(qmlView.x + qmlView.width * 0.50)
223+ stopX = int(qmlView.x + qmlView.width * 0.35)
224+ lineY = int(qmlView.y + qmlView.height * 0.05)
225+
226+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
227+ self.autopilot.pointing_device.click()
228
229=== modified file 'tests/autopilot/sudoku_app/tests/__init__.py'
230--- tests/autopilot/sudoku_app/tests/__init__.py 2013-07-08 18:15:44 +0000
231+++ tests/autopilot/sudoku_app/tests/__init__.py 2013-07-11 17:01:25 +0000
232@@ -3,4 +3,58 @@
233 #
234 # This program is free software: you can redistribute it and/or modify it
235 # under the terms of the GNU General Public License version 3, as published
236-# by the Free Software Foundation.
237\ No newline at end of file
238+# by the Free Software Foundation.
239+
240+"""Sudoku app autopilot tests."""
241+
242+import os.path
243+
244+from autopilot.input import Mouse, Touch, Pointer
245+from autopilot.platform import model
246+from autopilot.testcase import AutopilotTestCase
247+
248+from sudoku_app.emulators.main_window import MainWindow
249+from sudoku_app.emulators.ubuntusdk import ubuntusdk
250+
251+
252+class SudokuTestCase(AutopilotTestCase):
253+
254+ """A common test case class that provides several useful methods for
255+ sudoku-app tests.
256+
257+ """
258+ if model() == 'Desktop':
259+ scenarios = [('with mouse', dict(input_device_class=Mouse))]
260+ else:
261+ scenarios = [('with touch', dict(input_device_class=Touch))]
262+
263+ local_location = "../../sudoku-app.qml"
264+
265+ def setUp(self):
266+ self.pointing_device = Pointer(self.input_device_class.create())
267+ super(SudokuTestCase, self).setUp()
268+ if os.path.exists(self.local_location):
269+ self.launch_test_local()
270+ else:
271+ self.launch_test_installed()
272+
273+ def launch_test_local(self):
274+ self.app = self.launch_test_application(
275+ "qmlscene",
276+ self.local_location,
277+ app_type='qt')
278+
279+ def launch_test_installed(self):
280+ self.app = self.launch_test_application(
281+ "qmlscene",
282+ "/usr/share/sudoku-app/sudoku-app.qml",
283+ "--desktop_file_hint=/usr/share/applications/sudoku-app.desktop",
284+ app_type='qt')
285+
286+ @property
287+ def main_window(self):
288+ return MainWindow(self.app)
289+
290+ @property
291+ def ubuntusdk(self):
292+ return ubuntusdk(self, self.app)
293
294=== modified file 'tests/autopilot/sudoku_app/tests/test_sudoku.py'
295--- tests/autopilot/sudoku_app/tests/test_sudoku.py 2013-07-08 18:15:44 +0000
296+++ tests/autopilot/sudoku_app/tests/test_sudoku.py 2013-07-11 17:01:25 +0000
297@@ -12,7 +12,7 @@
298 from autopilot.matchers import Eventually
299 from testtools.matchers import Equals
300
301-from sudoku_app import SudokuTestCase
302+from sudoku_app.tests import SudokuTestCase
303
304
305 class TestMainWindow(SudokuTestCase):
306@@ -20,19 +20,7 @@
307 def setUp(self):
308 super(TestMainWindow, self).setUp()
309 self.assertThat(
310- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
311+ self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))
312
313 def tearDown(self):
314 super(TestMainWindow, self).tearDown()
315-
316- def test_toolbar_shows(self):
317- """Make sure that dragging from the bottom reveals the hidden
318- toolbar."""
319- toolbar = self.main_window.get_toolbar()
320-
321- x, y, w, h = toolbar.globalRect
322- tx = x + (w / 2)
323- ty = y + (h - 2)
324-
325- self.pointing_device.drag(tx, ty, tx, ty - h)
326- self.assertThat(toolbar.state, Eventually(Equals("spread")))

Subscribers

People subscribed via source and target branches