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
=== modified file 'tests/autopilot/sudoku_app/__init__.py'
--- tests/autopilot/sudoku_app/__init__.py 2013-07-08 18:15:44 +0000
+++ tests/autopilot/sudoku_app/__init__.py 2013-07-11 17:01:25 +0000
@@ -4,52 +4,3 @@
4# This program is free software: you can redistribute it and/or modify it4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
7
8"""Sudoku app autopilot tests."""
9
10import os.path
11
12from autopilot.input import Mouse, Touch, Pointer
13from autopilot.platform import model
14from autopilot.testcase import AutopilotTestCase
15
16from sudoku_app.emulators.main_window import MainWindow
17
18
19class SudokuTestCase(AutopilotTestCase):
20
21 """A common test case class that provides several useful methods for
22 sudoku-app tests.
23
24 """
25 if model() == 'Desktop':
26 scenarios = [('with mouse', dict(input_device_class=Mouse))]
27 else:
28 scenarios = [('with touch', dict(input_device_class=Touch))]
29
30 local_location = "../../sudoku-app.qml"
31
32 def setUp(self):
33 self.pointing_device = Pointer(self.input_device_class.create())
34 super(SudokuTestCase, self).setUp()
35 if os.path.exists(self.local_location):
36 self.launch_test_local()
37 else:
38 self.launch_test_installed()
39
40 def launch_test_local(self):
41 self.app = self.launch_test_application(
42 "qmlscene",
43 self.local_location,
44 app_type='qt')
45
46 def launch_test_installed(self):
47 self.app = self.launch_test_application(
48 "qmlscene",
49 "/usr/share/sudoku-app/sudoku-app.qml",
50 "--desktop_file_hint=/usr/share/applications/sudoku-app.desktop",
51 app_type='qt')
52
53 @property
54 def main_window(self):
55 return MainWindow(self.app)
567
=== modified file 'tests/autopilot/sudoku_app/emulators/main_window.py'
--- tests/autopilot/sudoku_app/emulators/main_window.py 2013-07-08 18:54:35 +0000
+++ tests/autopilot/sudoku_app/emulators/main_window.py 2013-07-11 17:01:25 +0000
@@ -15,10 +15,3 @@
15 """15 """
16 def __init__(self, app):16 def __init__(self, app):
17 self.app = app17 self.app = app
18
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):
24 return self.app.select_single("Toolbar")
2518
=== added file 'tests/autopilot/sudoku_app/emulators/ubuntusdk.py'
--- tests/autopilot/sudoku_app/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/sudoku_app/emulators/ubuntusdk.py 2013-07-11 17:01:25 +0000
@@ -0,0 +1,151 @@
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, buttonObject):
67 """Returns the toolbar button with objectName buttonObject"""
68 toolbar = self.get_toolbar()
69 if not toolbar.opened:
70 self.open_toolbar()
71 buttonList = toolbar.select_many("ActionItem")
72 for button in buttonList:
73 if button.objectName == buttonObject:
74 return button
75
76 def click_toolbar_button(self, buttonObject):
77 """Clicks the toolbar button with objectName buttonObject"""
78 #The toolbar button is assumed to be the following format
79 #Toolbar {
80 # ...
81 # ActionItem {
82 # objectName: "name"
83 button = self.get_toolbar_button(buttonObject)
84 self.autopilot.pointing_device.click_object(button)
85 return button
86
87 def open_toolbar(self):
88 """Open the toolbar"""
89 qmlView = self.get_qml_view()
90
91 lineX = int(qmlView.x + qmlView.width * 0.50)
92 startY = int(qmlView.y + qmlView.height - 1)
93 stopY = int(qmlView.y + qmlView.height * 0.95)
94
95 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
96
97 def hide_toolbar(self):
98 """Hide the toolbar"""
99 qmlView = self.get_qml_view()
100
101 lineX = int(qmlView.x + qmlView.width * 0.50)
102 startY = int(qmlView.y + qmlView.height * 0.95)
103 stopY = int(qmlView.y + qmlView.height - 1)
104
105 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
106
107 def set_popup_value(self, popover, button, value):
108 """Changes the given popover selector to the request value
109 At the moment this only works for values that are currently visible. To
110 access the remaining items, a help method to drag and recheck is needed."""
111 #The popover is assumed to be the following format
112 #Component {
113 # id: actionSelectionPopover
114 #
115 #ActionSelectionPopover {
116 # actions: ActionList {
117 # Action {
118
119 popList = self.get_object("ActionSelectionPopover", popover)
120 itemList = popList.select_many("Label")
121 for item in itemList:
122 if item.text == value:
123 self.autopilot.pointing_device.click_object(item)
124 return item
125
126 def get_tabs(self):
127 """Return all tabs"""
128 return self.get_object("Tabs", "rootTabs")
129
130 def _previous_tab(self):
131 """Switch to the previous tab"""
132 qmlView = self.get_qml_view()
133
134 startX = int(qmlView.x + qmlView.width * 0.35)
135 stopX = int(qmlView.x + qmlView.width * 0.50)
136 lineY = int(qmlView.y + qmlView.height * 0.05)
137
138 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
139 self.autopilot.pointing_device.click()
140 self.autopilot.pointing_device.click()
141
142 def _next_tab(self):
143 """Switch to the next tab"""
144 qmlView = self.get_qml_view()
145
146 startX = int(qmlView.x + qmlView.width * 0.50)
147 stopX = int(qmlView.x + qmlView.width * 0.35)
148 lineY = int(qmlView.y + qmlView.height * 0.05)
149
150 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
151 self.autopilot.pointing_device.click()
0152
=== modified file 'tests/autopilot/sudoku_app/tests/__init__.py'
--- tests/autopilot/sudoku_app/tests/__init__.py 2013-07-08 18:15:44 +0000
+++ tests/autopilot/sudoku_app/tests/__init__.py 2013-07-11 17:01:25 +0000
@@ -3,4 +3,58 @@
3#3#
4# This program is free software: you can redistribute it and/or modify it4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
7\ No newline at end of file6\ No newline at end of file
7# by the Free Software Foundation.
8
9"""Sudoku app autopilot tests."""
10
11import os.path
12
13from autopilot.input import Mouse, Touch, Pointer
14from autopilot.platform import model
15from autopilot.testcase import AutopilotTestCase
16
17from sudoku_app.emulators.main_window import MainWindow
18from sudoku_app.emulators.ubuntusdk import ubuntusdk
19
20
21class SudokuTestCase(AutopilotTestCase):
22
23 """A common test case class that provides several useful methods for
24 sudoku-app tests.
25
26 """
27 if model() == 'Desktop':
28 scenarios = [('with mouse', dict(input_device_class=Mouse))]
29 else:
30 scenarios = [('with touch', dict(input_device_class=Touch))]
31
32 local_location = "../../sudoku-app.qml"
33
34 def setUp(self):
35 self.pointing_device = Pointer(self.input_device_class.create())
36 super(SudokuTestCase, self).setUp()
37 if os.path.exists(self.local_location):
38 self.launch_test_local()
39 else:
40 self.launch_test_installed()
41
42 def launch_test_local(self):
43 self.app = self.launch_test_application(
44 "qmlscene",
45 self.local_location,
46 app_type='qt')
47
48 def launch_test_installed(self):
49 self.app = self.launch_test_application(
50 "qmlscene",
51 "/usr/share/sudoku-app/sudoku-app.qml",
52 "--desktop_file_hint=/usr/share/applications/sudoku-app.desktop",
53 app_type='qt')
54
55 @property
56 def main_window(self):
57 return MainWindow(self.app)
58
59 @property
60 def ubuntusdk(self):
61 return ubuntusdk(self, self.app)
862
=== modified file 'tests/autopilot/sudoku_app/tests/test_sudoku.py'
--- tests/autopilot/sudoku_app/tests/test_sudoku.py 2013-07-08 18:15:44 +0000
+++ tests/autopilot/sudoku_app/tests/test_sudoku.py 2013-07-11 17:01:25 +0000
@@ -12,7 +12,7 @@
12from autopilot.matchers import Eventually12from autopilot.matchers import Eventually
13from testtools.matchers import Equals13from testtools.matchers import Equals
1414
15from sudoku_app import SudokuTestCase15from sudoku_app.tests import SudokuTestCase
1616
1717
18class TestMainWindow(SudokuTestCase):18class TestMainWindow(SudokuTestCase):
@@ -20,19 +20,7 @@
20 def setUp(self):20 def setUp(self):
21 super(TestMainWindow, self).setUp()21 super(TestMainWindow, self).setUp()
22 self.assertThat(22 self.assertThat(
23 self.main_window.get_qml_view().visible, Eventually(Equals(True)))23 self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))
2424
25 def tearDown(self):25 def tearDown(self):
26 super(TestMainWindow, self).tearDown()26 super(TestMainWindow, self).tearDown()
27
28 def test_toolbar_shows(self):
29 """Make sure that dragging from the bottom reveals the hidden
30 toolbar."""
31 toolbar = self.main_window.get_toolbar()
32
33 x, y, w, h = toolbar.globalRect
34 tx = x + (w / 2)
35 ty = y + (h - 2)
36
37 self.pointing_device.drag(tx, ty, tx, ty - h)
38 self.assertThat(toolbar.state, Eventually(Equals("spread")))

Subscribers

People subscribed via source and target branches