Merge lp:~chocanto/ubuntu-docviewer-app/autopilot-tests into lp:ubuntu-docviewer-app/trunk

Proposed by Anthony Granger
Status: Merged
Approved by: Anthony Granger
Approved revision: 14
Merged at revision: 12
Proposed branch: lp:~chocanto/ubuntu-docviewer-app/autopilot-tests
Merge into: lp:ubuntu-docviewer-app/trunk
Diff against target: 363 lines (+214/-33)
7 files modified
launcher/src/docviewer-launcher.pri (+1/-1)
launcher/src/main.cpp (+20/-5)
tests/autopilot/ubuntu_docviewer_app/emulators/main_window.py (+0/-4)
tests/autopilot/ubuntu_docviewer_app/emulators/ubuntusdk.py (+165/-0)
tests/autopilot/ubuntu_docviewer_app/files/plaintext.txt (+1/-0)
tests/autopilot/ubuntu_docviewer_app/tests/__init__.py (+15/-10)
tests/autopilot/ubuntu_docviewer_app/tests/test_docviewer.py (+12/-13)
To merge this branch: bzr merge lp:~chocanto/ubuntu-docviewer-app/autopilot-tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Anthony Granger Approve
Review via email: mp+172169@code.launchpad.net

Commit message

Base for all future autopilot testcases.

Description of the change

Base for all future autopilot testcases.

To post a comment you must log in.
Revision history for this message
Anthony Granger (chocanto) :
review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

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

Subscribers

People subscribed via source and target branches