Merge lp:~rpadovani/ubuntu-clock-app/start_preset_autopilot into lp:ubuntu-clock-app/saucy

Proposed by Riccardo Padovani on 2013-07-13
Status: Merged
Approved by: Nicholas Skaggs on 2013-07-15
Approved revision: 141
Merged at revision: 143
Proposed branch: lp:~rpadovani/ubuntu-clock-app/start_preset_autopilot
Merge into: lp:ubuntu-clock-app/saucy
Diff against target: 271 lines (+189/-2)
5 files modified
tests/autopilot/ubuntu_clock_app/emulators/main_window.py (+47/-0)
tests/autopilot/ubuntu_clock_app/tests/__init__.py (+15/-1)
tests/autopilot/ubuntu_clock_app/tests/test_timer.py (+121/-0)
timer/AnalogTimer.qml (+1/-0)
timer/TimerPage.qml (+5/-1)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-clock-app/start_preset_autopilot
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2013-07-15
Nicholas Skaggs (community) 2013-07-14 Approve on 2013-07-15
Ubuntu Clock Developers 2013-07-13 Pending
Review via email: mp+174592@code.launchpad.net

Commit message

Added autopilot to create a new preset. (#1188800)
Added autopilot to delete a new preset. (#1188801)
Added autopilot to run a preset. (#1188807)

Description of the change

Added autopilot to create a new preset. (#1188800)
Added autopilot to delete a new preset. (#1188801)
Added autopilot to run a preset. (#1188807)

To post a comment you must log in.
141. By Riccardo Padovani on 2013-07-14

Some improvments to delete_preset test

Nicholas Skaggs (nskaggs) wrote :

This looks good to me. Thank you again Riccardo. At some point we'll convert this to the sdk emulator, but this works for now. I'd want to make sure the things like moving to a specific tab are more maintainable -- and the sdk emulator should fix that.

review: Approve
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/ubuntu_clock_app/emulators/main_window.py'
2--- tests/autopilot/ubuntu_clock_app/emulators/main_window.py 2013-07-10 19:38:56 +0000
3+++ tests/autopilot/ubuntu_clock_app/emulators/main_window.py 2013-07-14 22:20:33 +0000
4@@ -30,6 +30,9 @@
5
6 def get_object(self, typeName, name):
7 return self.app.select_single(typeName, objectName=name)
8+
9+ def get_object_by_id(self, typeName, objectId):
10+ return self.app.select_single(typeName, id=objectId)
11
12 def get_stopwatch_tab_button(self):
13 """Returns the stopwatch tab."""
14@@ -54,3 +57,47 @@
15 def get_laps(self):
16 """Returns the select for the lap count"""
17 return self.app.select_single("ListModel", objectName="laps")
18+
19+ def get_timer_tab_button(self):
20+ """Returns the timer tab."""
21+ return self.app.select_single("AbstractButton", buttonIndex=2)
22+
23+ def get_toolbar_timer(self):
24+ """Returns the toolbar of timer tab"""
25+ return self.app.select_single("ToolbarItems")
26+
27+ def get_toolbar_timer_button(self, button_idx):
28+ """Returns a button of toolbar of timer tab"""
29+ toolbar = self.app.select_single("ToolbarItems")
30+ button = toolbar.get_children()
31+ return button[button_idx]
32+
33+ def get_toolbar_timer_add_preset_button(self):
34+ """Returns the button for add preset of toolbar of timer tab"""
35+ return self.get_toolbar_timer_button(1)
36+
37+ def get_timer_name_preset(self):
38+ """Returns the TextField where insert the name of the preset"""
39+ return self.app.select_single("TextField", objectName="namePreset")
40+
41+ def get_timer_hour_hand(self):
42+ """Returns the hour hand of clock in timer tab"""
43+ return self.app.select_single("AnalogTouchHand", objectName="hourHand")
44+
45+ def get_timer_clock_center_label(self):
46+ """Returns the label in the center of clock"""
47+ return self.app.select_single("Label", objectName="addPresetTextDone")
48+
49+ def get_preset_label_text(self):
50+ """Returns the label with the preset text"""
51+ preset = self.app.select_many("Label", objectName="presetTextLabel")
52+ return preset[0] #last preset, the one created by autopilot
53+
54+ def get_preset_label_timer(self):
55+ """Returns the label with the preset timer"""
56+ preset = self.app.select_many("Label", objectName="presetTimerLabel")
57+ return preset[0] #last preset, the one created by autopilot
58+
59+ def get_label_timer(self):
60+ """Return the label with the timer countdown"""
61+ return self.app.select_single("Label", objectName="labelTimer")
62
63=== modified file 'tests/autopilot/ubuntu_clock_app/tests/__init__.py'
64--- tests/autopilot/ubuntu_clock_app/tests/__init__.py 2013-06-27 17:18:33 +0000
65+++ tests/autopilot/ubuntu_clock_app/tests/__init__.py 2013-07-14 22:20:33 +0000
66@@ -79,7 +79,21 @@
67 stopwatch_tab_button = self.main_window.get_stopwatch_tab_button()
68
69 self.assertThat(stopwatch_tab_button.opacity, Eventually(GreaterThan(0.35)))
70- self.pointing_device.click_object(stopwatch_tab_button)
71+ self.pointing_device.click_object(stopwatch_tab_button)
72+
73+ def move_to_timer_tab(self):
74+ tabs_bar = self.get_tabs()
75+
76+ x, y, w, h = tabs_bar.globalRect
77+ tx = x + w / 10
78+ ty = y + h / 2
79+ self.pointing_device.drag(tx, ty, w - 9, ty)
80+
81+ timer_tab_button = self.main_window.get_timer_tab_button()
82+
83+ self.assertThat(timer_tab_button.opacity, Eventually(GreaterThan(0.35)))
84+ self.pointing_device.click_object(timer_tab_button)
85+
86
87 @property
88 def main_window(self):
89
90=== added file 'tests/autopilot/ubuntu_clock_app/tests/test_timer.py'
91--- tests/autopilot/ubuntu_clock_app/tests/test_timer.py 1970-01-01 00:00:00 +0000
92+++ tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2013-07-14 22:20:33 +0000
93@@ -0,0 +1,121 @@
94+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
95+#
96+# Copyright (C) 2013 Canonical Ltd
97+#
98+# This program is free software: you can redistribute it and/or modify
99+# it under the terms of the GNU General Public License version 3 as
100+# published by the Free Software Foundation.
101+#
102+# This program is distributed in the hope that it will be useful,
103+# but WITHOUT ANY WARRANTY; without even the implied warranty of
104+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105+# GNU General Public License for more details.
106+#
107+# You should have received a copy of the GNU General Public License
108+# along with this program. If not, see <http://www.gnu.org/licenses/>.
109+#
110+# Authored by: Riccardo Padovani <rpadovani@ubuntu-it.org>
111+
112+"""Tests for the Clock App - Timer"""
113+
114+from __future__ import absolute_import
115+
116+from testtools.matchers import Equals, NotEquals
117+from autopilot.matchers import Eventually
118+
119+from ubuntu_clock_app.tests import ClockAppTestCase
120+
121+class TestTimer(ClockAppTestCase):
122+ """Tests the timer page features"""
123+
124+ """ This is needed to wait for the application to start.
125+ In the testfarm, the application may take some time to show up."""
126+ def setUp(self):
127+ super(TestTimer, self).setUp()
128+ self.assertThat(self.main_window.get_qml_view().visible, Eventually(Equals(True)))
129+
130+ self.move_to_timer_tab()
131+
132+ # Test if the current Tab is the Timer Tab
133+ CurrentTab = self.main_window.get_object("Tab", "TimerTab")
134+ self.assertThat(CurrentTab.title, Eventually(Equals("Timer")))
135+
136+ def show_toolbar(self):
137+ toolbar_timer = self.main_window.get_toolbar_timer()
138+
139+ x, y, w, h = toolbar_timer.globalRect
140+ tx = x + (w / 2)
141+ ty = y - (h / 2)
142+
143+ self.pointing_device.drag(tx, ty + (h / 3), tx, ty - h)
144+
145+ def test_add_preset(self):
146+ """Test to check if button to add a preset working"""
147+
148+ # Show the toolbar
149+ self.show_toolbar()
150+
151+ # Click the add preset button
152+ add_preset_button = self.main_window.get_toolbar_timer_add_preset_button()
153+ self.pointing_device.click_object(add_preset_button)
154+
155+ # Write in the label
156+ label = self.main_window.get_timer_name_preset()
157+ self.pointing_device.click_object(label)
158+ self.keyboard.type("test")
159+
160+ # Set hour
161+ hour = self.main_window.get_timer_hour_hand()
162+ x, y, w, h = hour.globalRect
163+ tx = x + (w / 2)
164+ ty = y + (h / 2)
165+ self.pointing_device.drag(tx, ty - (h / 4), tx + (w / 2), ty + (h / 2))
166+
167+ # Press "Done" button
168+ label = self.main_window.get_timer_clock_center_label()
169+ self.pointing_device.click_object(label)
170+
171+ # Check if the preset has been saved
172+ preset_text_label = self.main_window.get_preset_label_text()
173+ preset_timer_label = self.main_window.get_preset_label_timer()
174+
175+ self.assertThat(preset_text_label.text, Eventually(Equals("test")))
176+ self.assertThat(preset_timer_label.text, Eventually(Equals("23:00:00")))
177+
178+ def test_delete_preset(self):
179+ """Test if the swipe of a preset deletes it"""
180+
181+ # Create a new preset
182+ self.test_add_preset()
183+
184+ # Get the label of test and its id
185+ preset_text_label = self.main_window.get_preset_label_text()
186+ preset_text_label_id = preset_text_label.id
187+
188+ # Delete the preset
189+ x, y, w, h = preset_text_label.globalRect
190+ tx = x + (w / 2)
191+ ty = y + (h / 2)
192+ self.pointing_device.drag(tx - w, ty, tx + 10 * w , ty)
193+
194+ # Check has been deleted
195+ label = lambda: self.main_window.get_object_by_id('Label', preset_text_label_id)
196+ self.assertThat(label, Eventually(Equals(None)))
197+
198+ def test_run_preset(self):
199+ """Tests if a preset can runs"""
200+
201+ # Create a new preset
202+ self.test_add_preset()
203+
204+ # Click to select the preset
205+ preset_text_label = self.main_window.get_preset_label_text()
206+ self.pointing_device.click_object(preset_text_label)
207+
208+ # Click to start the preset
209+ label = self.main_window.get_timer_clock_center_label()
210+ self.pointing_device.click_object(label)
211+
212+ # Check if timer is started
213+ label_timer = self.main_window.get_label_timer()
214+ self.assertThat(label_timer.text, Eventually(NotEquals("23:00:00")))
215\ No newline at end of file
216
217=== modified file 'timer/AnalogTimer.qml'
218--- timer/AnalogTimer.qml 2013-07-12 17:07:55 +0000
219+++ timer/AnalogTimer.qml 2013-07-14 22:20:33 +0000
220@@ -86,6 +86,7 @@
221 // Hour hand with touch/mouse drag support
222 AnalogTouchHand {
223 id: hourHand
224+ objectName: "hourHand"
225
226 onTimerValueChanged: hours = timerValue;
227
228
229=== modified file 'timer/TimerPage.qml'
230--- timer/TimerPage.qml 2013-07-12 17:07:55 +0000
231+++ timer/TimerPage.qml 2013-07-14 22:20:33 +0000
232@@ -222,12 +222,15 @@
233
234 delegate: ListItem.Standard {
235 Label {
236+ id: presetTextLabel // Needs by autopilot
237+ objectName: "presetTextLabel"
238 fontSize: "large";
239 text: label
240 anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: units.gu(3) }
241 }
242
243 Label {
244+ objectName: "presetTimerLabel"
245 fontSize: "large"
246 text: getstringTimer(seconds);
247 anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: units.gu(2) }
248@@ -269,6 +272,7 @@
249
250 Label {
251 id: addPresetTextDone
252+ objectName: "addPresetTextDone"
253
254 //anchors.centerIn: parent
255 color: Constants.green
256@@ -292,6 +296,7 @@
257 // Element to set the name of a saved preset.
258 TextField {
259 id: namePreset
260+ objectName: "namePreset"
261
262 visible: false
263 hasClearButton: true
264@@ -308,7 +313,6 @@
265 ToolbarButton {
266 action: Action {
267 id: addPreset
268- objectName: "add-preset"
269
270 iconSource: Qt.resolvedUrl("../images/add_icon.png")
271 text: i18n.tr("Add Preset")

Subscribers

People subscribed via source and target branches