Terminal application for Ubuntu devices

Merge lp:~hiroshidi/ubuntu-terminal-app/autopilot-tests-panels into lp:ubuntu-terminal-app

Proposed by Dmitry Zagnoyko on 2013-06-19
Status: Merged
Approved by: Dmitry Zagnoyko on 2013-06-20
Approved revision: 17
Merged at revision: 15
Proposed branch: lp:~hiroshidi/ubuntu-terminal-app/autopilot-tests-panels
Merge into: lp:ubuntu-terminal-app
Diff against target: 352 lines (+233/-25) 5 files modified
To merge this branch: bzr merge lp:~hiroshidi/ubuntu-terminal-app/autopilot-tests-panels
Reviewer Review Type Date Requested Status
Nicholas Skaggs 2013-06-19 Approve on 2013-06-19
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2013-06-19
Review via email: mp+170388@code.launchpad.net

Commit Message

add autopilot test for panels and the circle menu
add ubuntusdk emu from lp:~nskaggs/+junk/ubuntusdk_autopilot_emulator

Description of the Change

Added Autopilot Testcase for:
- Control keys panel - LP: #1188835
- Function keys panel - LP: #1188836
- Text control panel - LP: #1188837
- Circle-menu - LP: #1188838

To post a comment you must log in.
Nicholas Skaggs (nskaggs) wrote :

Looks good Dmitry! Can you incorporate the emulator WIP for this? lp:~nskaggs/+junk/ubuntusdk_autopilot_emulator. We're going to continue to iterate on this to have many of the common functions (like tab switching, toolbar access, etc) and we want to be able to keep tests up to date on best practices as they continue to evolve :-)

That said, this is otherwise a nice basic testcase -- good base to build on.

review: Needs Fixing
17. By Dmitry Zagnoyko on 2013-06-19

Merged ubuntusdk autopilot testcase emulator. Merged branch: lp:~nskaggs/+junk/ubuntusdk_autopilot_emulator

Nicholas Skaggs (nskaggs) wrote :

Let's push this in. I need to add the popover function to the sdk somehow.. work for me to gt right :-) Thanks Dmitry!

review: Approve

Preview Diff

1=== modified file 'Terminal.qml'
2--- Terminal.qml 2013-05-24 16:18:10 +0000
3+++ Terminal.qml 2013-06-19 18:58:26 +0000
4@@ -82,6 +82,7 @@
5
6 CtrlKeys {
7 id: kbCtrl
8+ objectName: "kbCtrl"
9 visible: false
10 width: parent.width
11 anchors{
12@@ -97,6 +98,7 @@
13
14 FnKeys {
15 id: kbFn
16+ objectName: "kbFn"
17 visible: false
18 width: parent.width
19 anchors{
20@@ -113,6 +115,7 @@
21
22 ScrlKeys {
23 id: kbScrl
24+ objectName: "kbScrl"
25 visible: false
26 width: parent.width
27 anchors{
28@@ -141,6 +144,7 @@
29
30 CircleMenu {
31 id: cmenu
32+ objectName: "cmenu"
33 z: 99
34 visible: false
35 anchors.centerIn: parent
36@@ -181,6 +185,7 @@
37
38 KTerminal {
39 id: kterm
40+ objectName: "kterm"
41
42 //////////////////////////////////////
43 /// FONT SIZE = 24 (FINE FOR GNEXUS)
44@@ -195,6 +200,7 @@
45
46 session: KSession {
47 id: ksession
48+ objectName: "ksession"
49 kbScheme: "linux"
50 }
51 }
52
53=== modified file 'tests/autopilot/ubuntu_terminal_app/emulators/main_window.py'
54--- tests/autopilot/ubuntu_terminal_app/emulators/main_window.py 2013-05-31 13:10:55 +0000
55+++ tests/autopilot/ubuntu_terminal_app/emulators/main_window.py 2013-06-19 18:58:26 +0000
56@@ -7,18 +7,21 @@
57
58 """Terminal app autopilot emulators."""
59
60-
61 class MainWindow(object):
62 """An emulator class that makes it easy to interact with the
63- terminal-app.
64-
65- """
66- def __init__(self, app):
67+ terminal-app."""
68+ def __init__(self, autopilot, app):
69 self.app = app
70-
71- def get_qml_view(self):
72- """Get the main QML view"""
73- return self.app.select_single("QQuickView")
74-
75- def get_toolbar(self):
76- return self.app.select_single("Toolbar")
77+ self.autopilot = autopilot
78+
79+ def click_popup_item(self, popupLable):
80+ """Clicks the toolbar popup item with popupLable"""
81+ li = self.app.select_single("ActionSelectionPopover")
82+ row = li.select_single("QQuickColumn")
83+ loaderList = row.select_many("QQuickLoader")
84+ for loader in loaderList:
85+ labelList = loader.select_many("Label")
86+ for label in labelList:
87+ if label.text == popupLable:
88+ self.autopilot.pointing_device.click_object(label)
89+
90
91=== added file 'tests/autopilot/ubuntu_terminal_app/emulators/ubuntusdk.py'
92--- tests/autopilot/ubuntu_terminal_app/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
93+++ tests/autopilot/ubuntu_terminal_app/emulators/ubuntusdk.py 2013-06-19 18:58:26 +0000
94@@ -0,0 +1,154 @@
95+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
96+#
97+# Copyright (C) 2013 Canonical Ltd
98+#
99+# This program is free software: you can redistribute it and/or modify
100+# it under the terms of the GNU General Public License version 3 as
101+# published by the Free Software Foundation.
102+#
103+# This program is distributed in the hope that it will be useful,
104+# but WITHOUT ANY WARRANTY; without even the implied warranty of
105+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106+# GNU General Public License for more details.
107+#
108+# You should have received a copy of the GNU General Public License
109+# along with this program. If not, see <http://www.gnu.org/licenses/>.
110+#
111+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
112+
113+from testtools.matchers import Equals, NotEquals, Not, Is
114+from autopilot.matchers import Eventually
115+
116+class ubuntusdk(object):
117+ """An emulator class that makes it easy to interact with the ubuntu sdk applications."""
118+
119+ def __init__(self, autopilot, app):
120+ self.app = app
121+ self.autopilot = autopilot
122+
123+ def get_qml_view(self):
124+ """Get the main QML view"""
125+ return self.app.select_single("QQuickView")
126+
127+ def get_object(self, typeName, name):
128+ """Get a specific object"""
129+ return self.app.select_single(typeName, objectName=name)
130+
131+ def get_objects(self, typeName, name):
132+ """Get more than one object"""
133+ return self.app.select_many(typeName, objectName=name)
134+
135+ def switch_to_tab(self, tab):
136+ """Switch to the specified tab number"""
137+ tabs = self.get_tabs()
138+ currentTab = tabs.selectedTabIndex
139+
140+ #perform operations until tab == currentTab
141+ while tab != currentTab:
142+ if tab > currentTab:
143+ self._previous_tab()
144+ if tab < currentTab:
145+ self._next_tab()
146+ currentTab = tabs.selectedTabIndex
147+
148+ def toggle_toolbar(self):
149+ """Toggle the toolbar between revealed and hidden"""
150+ #check and see if the toolbar is open or not
151+ if self.get_toolbar().opened:
152+ self.hide_toolbar()
153+ else:
154+ self.open_toolbar()
155+
156+ def get_toolbar(self):
157+ """Returns the toolbar in the main events view."""
158+ return self.app.select_single("Toolbar")
159+
160+ def get_toolbar_button(self, buttonLabel):
161+ """Returns the toolbar button at position index"""
162+ toolbar = self.get_toolbar()
163+ if not toolbar.opened:
164+ self.open_toolbar()
165+ row = toolbar.select_single("QQuickRow")
166+ loaderList = row.select_many("QQuickLoader")
167+ for loader in loaderList:
168+ buttonList = loader.select_many("Button")
169+ for button in buttonList:
170+ if button.text == buttonLabel:
171+ return button
172+
173+ def click_toolbar_button(self, buttonLabel):
174+ """Clicks the toolbar button with buttonLabel"""
175+ #The toolbar button is assumed to be the following format
176+ #ToolbarActions {
177+ # Action {
178+ # objectName: "name"
179+ # text: value
180+ button = self.get_toolbar_button(buttonLabel)
181+ self.autopilot.pointing_device.click_object(button)
182+
183+ def open_toolbar(self):
184+ """Open the toolbar"""
185+ qmlView = self.get_qml_view()
186+
187+ lineX = qmlView.x + qmlView.width * 0.50
188+ startY = qmlView.y + qmlView.height - 1
189+ stopY = qmlView.y + qmlView.height * 0.95
190+
191+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
192+
193+ def hide_toolbar(self):
194+ """Hide the toolbar"""
195+ qmlView = self.get_qml_view()
196+
197+ lineX = qmlView.x + qmlView.width * 0.50
198+ startY = qmlView.y + qmlView.height * 0.95
199+ stopY = qmlView.y + qmlView.height - 1
200+
201+ self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
202+
203+ def set_popup_value(self, popover, button, value):
204+ """Changes the given popover selector to the request value
205+ At the moment this only works for values that are currently visible. To
206+ access the remaining items, a help method to drag and recheck is needed."""
207+ #The popover is assumed to be the following format
208+ # Popover {
209+ # Column {
210+ # ListView {
211+ # delegate: Standard {
212+ # objectName: "name"
213+ # text: value
214+
215+ self.autopilot.pointing_device.click_object(button)
216+ #we'll get all matching objects, incase the popover is reused between buttons
217+ itemList = lambda: self.get_objects("Standard", popover)
218+
219+ for item in itemList():
220+ if item.get_properties()['text'] == value:
221+ self.autopilot.pointing_device.click_object(item)
222+
223+ def get_tabs(self):
224+ """Return all tabs"""
225+ return self.get_object("Tabs", "rootTabs")
226+
227+ def _previous_tab(self):
228+ """Switch to the previous tab"""
229+ qmlView = self.get_qml_view()
230+
231+ startX = qmlView.x + qmlView.width * 0.35
232+ stopX = qmlView.x + qmlView.width * 0.50
233+ lineY = qmlView.y + qmlView.height * 0.05
234+
235+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
236+ self.autopilot.pointing_device.click()
237+ self.autopilot.pointing_device.click()
238+
239+ def _next_tab(self):
240+ """Switch to the next tab"""
241+ qmlView = self.get_qml_view()
242+
243+ startX = qmlView.x + qmlView.width * 0.50
244+ stopX = qmlView.x + qmlView.width * 0.35
245+ lineY = qmlView.y + qmlView.height * 0.05
246+
247+ self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
248+ self.autopilot.pointing_device.click()
249
250=== modified file 'tests/autopilot/ubuntu_terminal_app/tests/__init__.py'
251--- tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2013-05-31 13:10:55 +0000
252+++ tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2013-06-19 18:58:26 +0000
253@@ -14,6 +14,7 @@
254 from autopilot.testcase import AutopilotTestCase
255
256 from ubuntu_terminal_app.emulators.main_window import MainWindow
257+from ubuntu_terminal_app.emulators.ubuntusdk import ubuntusdk
258
259
260 class TerminalTestCase(AutopilotTestCase):
261@@ -52,4 +53,9 @@
262
263 @property
264 def main_window(self):
265- return MainWindow(self.app)
266+ return MainWindow(self, self.app)
267+
268+ @property
269+ def ubuntu_sdk(self):
270+ return ubuntusdk(self, self.app)
271+
272
273=== modified file 'tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py'
274--- tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py 2013-05-31 13:10:55 +0000
275+++ tests/autopilot/ubuntu_terminal_app/tests/test_terminal.py 2013-06-19 18:58:26 +0000
276@@ -14,25 +14,64 @@
277
278 from ubuntu_terminal_app.tests import TerminalTestCase
279
280+import time
281
282 class TestMainWindow(TerminalTestCase):
283
284 def setUp(self):
285 super(TestMainWindow, self).setUp()
286 self.assertThat(
287- self.main_window.get_qml_view().visible, Eventually(Equals(True)))
288+ self.ubuntu_sdk.get_qml_view().visible, Eventually(Equals(True)))
289
290 def tearDown(self):
291 super(TestMainWindow, self).tearDown()
292
293- def test_toolbar_shows(self):
294- """Make sure that dragging from the bottom reveals the hidden
295- toolbar."""
296- toolbar = self.main_window.get_toolbar()
297-
298- x, y, w, h = toolbar.globalRect
299- tx = x + (w / 2)
300- ty = y + (h - 2)
301-
302- self.pointing_device.drag(tx, ty, tx, ty - h)
303- self.assertThat(toolbar.state, Eventually(Equals("spread")))
304+ def test_Control_Panel_shows(self):
305+ """Make sure that Control Keys Panel is visible
306+ when clicking the toolbar popup items."""
307+ self.ubuntu_sdk.click_toolbar_button("Panels")
308+ self.main_window.click_popup_item("Control keys")
309+ panelCtrl = self.ubuntu_sdk.get_object("CtrlKeys", "kbCtrl")
310+ self.assertThat(panelCtrl.visible, Eventually(Equals(True)))
311+
312+ def test_Function_Panel_shows(self):
313+ """Make sure that Function Keys Panel is visible
314+ when clicking the toolbar popup items."""
315+ self.ubuntu_sdk.click_toolbar_button("Panels")
316+ self.main_window.click_popup_item("Function keys")
317+ panelFunc = self.ubuntu_sdk.get_object("FnKeys", "kbFn")
318+ self.assertThat(panelFunc.visible, Eventually(Equals(True)))
319+
320+ def test_TextCtrl_Panel_shows(self):
321+ """Make sure that Text Control Keys Panel is visible
322+ when clicking the toolbar popup items."""
323+ self.ubuntu_sdk.click_toolbar_button("Panels")
324+ self.main_window.click_popup_item("Text ctrl keys")
325+ panelScrl = self.ubuntu_sdk.get_object("ScrlKeys", "kbScrl")
326+ self.assertThat(panelScrl.visible, Eventually(Equals(True)))
327+
328+ def test_Panels_hide(self):
329+ """Make sure that all panels are hide
330+ when clicking the toolbar popup items."""
331+ self.ubuntu_sdk.click_toolbar_button("Panels")
332+ self.main_window.click_popup_item("Hide extra panel")
333+ panelCtrl = self.ubuntu_sdk.get_object("CtrlKeys", "kbCtrl")
334+ panelFunc = self.ubuntu_sdk.get_object("FnKeys", "kbFn")
335+ panelScrl = self.ubuntu_sdk.get_object("ScrlKeys", "kbScrl")
336+ self.assertThat(panelCtrl.visible, Eventually(Equals(False)))
337+ self.assertThat(panelFunc.visible, Eventually(Equals(False)))
338+ self.assertThat(panelScrl.visible, Eventually(Equals(False)))
339+
340+ def test_CircleMenu_shows(self):
341+ """Make sure that Circle Menu is visible
342+ on long tap"""
343+ kterm = self.ubuntu_sdk.get_object("KTerminalDisplay", "kterm")
344+ menu = self.ubuntu_sdk.get_object("CircleMenu", "cmenu")
345+ self.pointing_device.click_object(kterm)
346+ self.pointing_device.press()
347+ time.sleep(1)
348+ self.pointing_device.release()
349+ self.assertThat(menu.visible, Eventually(Equals(True)))
350+
351+
352+

Subscribers

People subscribed via source and target branches