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
=== modified file 'launcher/src/docviewer-launcher.pri'
--- launcher/src/docviewer-launcher.pri 2013-04-25 16:33:39 +0000
+++ launcher/src/docviewer-launcher.pri 2013-06-28 21:59:24 +0000
@@ -4,7 +4,7 @@
4#4#
5#-------------------------------------------------5#-------------------------------------------------
66
7QT += gui qml quick7QT += gui qml quick widgets
88
9TARGET = ubuntu-docviewer-app9TARGET = ubuntu-docviewer-app
1010
1111
=== modified file 'launcher/src/main.cpp'
--- launcher/src/main.cpp 2013-05-31 13:53:18 +0000
+++ launcher/src/main.cpp 2013-06-28 21:59:24 +0000
@@ -1,6 +1,7 @@
1#include <iostream>1#include <iostream>
22
3#include <QGuiApplication>3#include <QApplication>
4#include <QDir>
45
5#include <QtQml/qqmlengine.h>6#include <QtQml/qqmlengine.h>
6#include <QtQml/qqmlcomponent.h>7#include <QtQml/qqmlcomponent.h>
@@ -18,7 +19,7 @@
1819
19int main(int argc, char *argv[])20int main(int argc, char *argv[])
20{21{
21 QGuiApplication launcher(argc, argv);22 QApplication launcher(argc, argv); //Testability work only with QApplication and not with QGuiApplication
2223
23 QQmlEngine engine;24 QQmlEngine engine;
24 QQmlComponent *component = new QQmlComponent(&engine);25 QQmlComponent *component = new QQmlComponent(&engine);
@@ -35,7 +36,21 @@
35 QString argument = "";36 QString argument = "";
36 if (launcher.arguments().size() >= 2)37 if (launcher.arguments().size() >= 2)
37 {38 {
38 argument = launcher.arguments().at(1);39 int i = 0;
40 for (i = 1; i < launcher.arguments().size(); i++)
41 {
42 if (launcher.arguments().at(i).at(0) != '-')
43 {
44 argument = launcher.arguments().at(i);
45 break;
46 }
47 }
48
49 if (i == launcher.arguments().size())
50 {
51 displayUsage();
52 return 0;
53 }
39 }54 }
40 else55 else
41 {56 {
@@ -43,8 +58,8 @@
43 return 0;58 return 0;
44 }59 }
4560
4661 QString absolutePath = QDir(argument).absolutePath();
47 File *file = new File(&argument);62 File *file = new File(&absolutePath);
4863
49 engine.rootContext()->setContextProperty("file", file);64 engine.rootContext()->setContextProperty("file", file);
5065
5166
=== modified file 'tests/autopilot/ubuntu_docviewer_app/emulators/main_window.py'
--- tests/autopilot/ubuntu_docviewer_app/emulators/main_window.py 2013-05-31 11:28:00 +0000
+++ tests/autopilot/ubuntu_docviewer_app/emulators/main_window.py 2013-06-28 21:59:24 +0000
@@ -16,9 +16,5 @@
16 def __init__(self, app):16 def __init__(self, app):
17 self.app = app17 self.app = app
1818
19 def get_qml_view(self):
20 """Get the main QML view"""
21 return self.app.select_single("QQuickView")
22
23 def get_toolbar(self):19 def get_toolbar(self):
24 return self.app.select_single("Toolbar")20 return self.app.select_single("Toolbar")
2521
=== added file 'tests/autopilot/ubuntu_docviewer_app/emulators/ubuntusdk.py'
--- tests/autopilot/ubuntu_docviewer_app/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_docviewer_app/emulators/ubuntusdk.py 2013-06-28 21:59:24 +0000
@@ -0,0 +1,165 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2013 Canonical Ltd
4#
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.
8#
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.
13#
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/>.
16#
17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
18
19from testtools.matchers import Equals, NotEquals, Not, Is
20from autopilot.matchers import Eventually
21
22class ubuntusdk(object):
23 """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
24
25 def __init__(self, autopilot, app):
26 self.app = app
27 self.autopilot = autopilot
28
29 def get_qml_view(self):
30 """Get the main QML view"""
31 return self.app.select_single("QQuickView")
32
33 def get_object(self, typeName, name):
34 """Get a specific object"""
35 return self.app.select_single(typeName, objectName=name)
36
37 def get_objects(self, typeName, name):
38 """Get more than one object"""
39 return self.app.select_many(typeName, objectName=name)
40
41 def switch_to_tab(self, tab):
42 """Switch to the specified tab number"""
43 tabs = self.get_tabs()
44 currentTab = tabs.selectedTabIndex
45
46 #perform operations until tab == currentTab
47 while tab != currentTab:
48 if tab > currentTab:
49 self._previous_tab()
50 if tab < currentTab:
51 self._next_tab()
52 currentTab = tabs.selectedTabIndex
53
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:
58 self.hide_toolbar()
59 else:
60 self.open_toolbar()
61
62 def get_toolbar(self):
63 """Returns the toolbar in the main events view."""
64 return self.app.select_single("Toolbar")
65
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]
73 return buttonLoader
74
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
78 #ToolbarActions {
79 # Action {
80 # objectName: "name"
81 # text: value
82 toolbar = self.get_toolbar()
83 if not toolbar.opened:
84 self.open_toolbar()
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)
90
91 for item in itemList():
92 if item.get_properties()['text'] == value:
93 self.autopilot.pointing_device.click_object(item)
94
95 def open_toolbar(self):
96 """Open the toolbar"""
97 qmlView = self.get_qml_view()
98
99 lineX = qmlView.x + qmlView.width * 0.50
100 startY = qmlView.y + qmlView.height - 1
101 stopY = qmlView.y + qmlView.height - 200
102
103 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
104 self.autopilot.pointing_device.click()
105 self.autopilot.pointing_device.click()
106
107 def hide_toolbar(self):
108 """Hide the toolbar"""
109 qmlView = self.get_qml_view()
110
111 lineX = qmlView.x + qmlView.width * 0.50
112 startY = qmlView.y + qmlView.height - 200
113 stopY = qmlView.y + qmlView.height - 1
114
115 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
116 self.autopilot.pointing_device.click()
117 self.autopilot.pointing_device.click()
118
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
124 # Popover {
125 # Column {
126 # ListView {
127 # delegate: Standard {
128 # objectName: "name"
129 # text: value
130
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)
134
135 for item in itemList():
136 if item.get_properties()['text'] == value:
137 self.autopilot.pointing_device.click_object(item)
138
139 def get_tabs(self):
140 """Return all tabs"""
141 return self.get_object("Tabs", "rootTabs")
142
143 def _previous_tab(self):
144 """Switch to the previous tab"""
145 qmlView = self.get_qml_view()
146
147 startX = qmlView.x + qmlView.width * 0.20
148 stopX = qmlView.x + qmlView.width * 0.50
149 lineY = qmlView.y + qmlView.height * 0.05
150
151 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
152 self.autopilot.pointing_device.click()
153 self.autopilot.pointing_device.click()
154
155 def _next_tab(self):
156 """Switch to the next tab"""
157 qmlView = self.get_qml_view()
158
159 startX = qmlView.x + qmlView.width * 0.50
160 stopX = qmlView.x + qmlView.width * 0.20
161 lineY = qmlView.y + qmlView.height * 0.05
162
163 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
164 self.autopilot.pointing_device.click()
165 self.autopilot.pointing_device.click()
0166
=== added directory 'tests/autopilot/ubuntu_docviewer_app/files'
=== added file 'tests/autopilot/ubuntu_docviewer_app/files/plaintext.txt'
--- tests/autopilot/ubuntu_docviewer_app/files/plaintext.txt 1970-01-01 00:00:00 +0000
+++ tests/autopilot/ubuntu_docviewer_app/files/plaintext.txt 2013-06-28 21:59:24 +0000
@@ -0,0 +1,1 @@
1TEST
02
=== modified file 'tests/autopilot/ubuntu_docviewer_app/tests/__init__.py'
--- tests/autopilot/ubuntu_docviewer_app/tests/__init__.py 2013-05-31 11:28:00 +0000
+++ tests/autopilot/ubuntu_docviewer_app/tests/__init__.py 2013-06-28 21:59:24 +0000
@@ -9,12 +9,14 @@
99
10import os.path10import os.path
1111
12from pprint import pprint
13
12from autopilot.input import Mouse, Touch, Pointer14from autopilot.input import Mouse, Touch, Pointer
13from autopilot.platform import model15from autopilot.platform import model
14from autopilot.testcase import AutopilotTestCase16from autopilot.testcase import AutopilotTestCase
1517
16from ubuntu_docviewer_app.emulators.main_window import MainWindow18from ubuntu_docviewer_app.emulators.main_window import MainWindow
1719from ubuntu_docviewer_app.emulators.ubuntusdk import ubuntusdk
1820
19class DocviewerTestCase(AutopilotTestCase):21class DocviewerTestCase(AutopilotTestCase):
2022
@@ -22,34 +24,37 @@
22 docviewer-app tests.24 docviewer-app tests.
2325
24 """26 """
27
25 if model() == 'Desktop':28 if model() == 'Desktop':
26 scenarios = [('with mouse', dict(input_device_class=Mouse))]29 scenarios = [('with mouse', dict(input_device_class=Mouse))]
27 else:30 else:
28 scenarios = [('with touch', dict(input_device_class=Touch))]31 scenarios = [('with touch', dict(input_device_class=Touch))]
2932
30 local_location = "../../ubuntu-docviewer-app.qml"33 local_location = "../../ubuntu-docviewer-app"
3134
32 def setUp(self):35 def setUp(self):
33 self.pointing_device = Pointer(self.input_device_class.create())36 self.pointing_device = Pointer(self.input_device_class.create())
34 super(DocviewerTestCase, self).setUp()37 super(DocviewerTestCase, self).setUp()
35 if os.path.exists(self.local_location):38
36 self.launch_test_local()39 def launch_test_local(self, arg):
37 else:
38 self.launch_test_installed()
39
40 def launch_test_local(self):
41 self.app = self.launch_test_application(40 self.app = self.launch_test_application(
42 "qmlscene",
43 self.local_location,41 self.local_location,
42 arg,
44 app_type='qt')43 app_type='qt')
4544
46 def launch_test_installed(self):45 def launch_test_installed(self, arg):
47 self.app = self.launch_test_application(46 self.app = self.launch_test_application(
48 "qmlscene",47 "qmlscene",
49 "/usr/share/ubuntu-docviewer-app/ubuntu-docviewer-app.qml",48 "/usr/share/ubuntu-docviewer-app/ubuntu-docviewer-app.qml",
50 "--desktop_file_hint=/usr/share/applications/ubuntu-docviewer-app.desktop",49 "--desktop_file_hint=/usr/share/applications/ubuntu-docviewer-app.desktop",
50 arg,
51 app_type='qt')51 app_type='qt')
5252
53 @property53 @property
54 def main_window(self):54 def main_window(self):
55 return MainWindow(self.app)55 return MainWindow(self.app)
56
57 @property
58 def ubuntusdk(self):
59 return ubuntusdk(self, self.app)
60
5661
=== modified file 'tests/autopilot/ubuntu_docviewer_app/tests/test_docviewer.py'
--- tests/autopilot/ubuntu_docviewer_app/tests/test_docviewer.py 2013-05-31 11:28:00 +0000
+++ tests/autopilot/ubuntu_docviewer_app/tests/test_docviewer.py 2013-06-28 21:59:24 +0000
@@ -19,20 +19,19 @@
1919
20 def setUp(self):20 def setUp(self):
21 super(TestMainWindow, self).setUp()21 super(TestMainWindow, self).setUp()
22 self.assertThat(
23 self.main_window.get_qml_view().visible, Eventually(Equals(True)))
2422
25 def tearDown(self):23 def tearDown(self):
26 super(TestMainWindow, self).tearDown()24 super(TestMainWindow, self).tearDown()
2725
28 def test_toolbar_shows(self):26 def test_open_text_file(self):
29 """Make sure that dragging from the bottom reveals the hidden27
30 toolbar."""28 filePath = 'ubuntu_docviewer_app/files/plaintext.txt'
31 toolbar = self.main_window.get_toolbar()29
3230 self.launch_test_local(filePath)
33 x, y, w, h = toolbar.globalRect31
34 tx = x + (w / 2)32 self.assertThat(
35 ty = y + (h - 2)33 self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))
3634
37 self.pointing_device.drag(tx, ty, tx, ty - h)35 #verify textbox is no longer empty
38 self.assertThat(toolbar.state, Eventually(Equals("spread")))36 # or
37 #verify the file size displayed is not 0 (maybe easier ?)

Subscribers

People subscribed via source and target branches