Merge lp:~nik90/ubuntu-clock-app/more-stopwatch-tests into lp:ubuntu-clock-app/saucy

Proposed by Nekhelesh Ramananthan on 2013-11-05
Status: Merged
Approved by: Nicholas Skaggs on 2014-01-06
Approved revision: 268
Merged at revision: 282
Proposed branch: lp:~nik90/ubuntu-clock-app/more-stopwatch-tests
Merge into: lp:ubuntu-clock-app/saucy
Prerequisite: lp:~nik90/ubuntu-clock-app/use-default-swipe-delete
Diff against target: 196 lines (+78/-12)
7 files modified
clock/WorldClock.qml (+1/-0)
stopwatch/LapList.qml (+1/-0)
stopwatch/StopwatchPage.qml (+0/-1)
tests/autopilot/ubuntu_clock_app/emulators.py (+13/-4)
tests/autopilot/ubuntu_clock_app/tests/test_clock.py (+3/-2)
tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py (+59/-5)
tests/autopilot/ubuntu_clock_app/tests/test_timer.py (+1/-0)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/more-stopwatch-tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2014-01-06
Nicholas Skaggs (community) 2013-11-05 Approve on 2014-01-06
Ubuntu Clock Developers 2013-11-05 Pending
Review via email: mp+193922@code.launchpad.net

Commit message

Added autopilot tests for creating and deleting stopwatch laps.

Description of the change

This MP adds three autopilot test cases,
-> Test creating laps (stopwatch)
-> Test deleting laps (stopwatch)

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

I was JUST going to ping on the status of this :-) Think we can land this now?

Nekhelesh Ramananthan (nik90) wrote :

Yup it is ready from my pov. So its up to you and jenkins to decide if the code is good and then approve it :-)

Nicholas Skaggs (nskaggs) wrote :

Trying this on my device now.. Did you run it? I got the error below once during a run. Going to keep running to see if it's the only occasional error:

Traceback (most recent call last):
File "/home/phablet/autopilot/ubuntu_clock_app/tests/test_timer.py", line 119, in test_delete_preset
self.test_add_preset()
File "/home/phablet/autopilot/ubuntu_clock_app/tests/test_timer.py", line 91, in test_add_preset
Eventually(Equals(num_of_presets_old + 1)))
File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line 412, in assertThat
raise MismatchError(matchee, matcher, mismatch, verbose)
MismatchError: After 10.0 seconds test failed: 4 != 3

review: Needs Fixing
Nicholas Skaggs (nskaggs) wrote :

The aforementioned error is no longer an issue, however RE: IRC, the test_add_online_world_city isn't testing online cities like you think :- )

I would also add an assert to ensure the stopwatch time moves in test_create_lap, even if you sleep. This will prevent timing issues where you try and hit a lap with no time elapsed :-)

review: Needs Fixing
Nicholas Skaggs (nskaggs) wrote :

Finally, I'm ok with adding the online test, but we are trying to transition away. We might end up disabling it as extraneous. (since we're testing it anyway since it's the same as local)

Nicholas Skaggs (nskaggs) wrote :

Looks much better :-)

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 'clock/WorldClock.qml'
2--- clock/WorldClock.qml 2013-11-07 16:34:43 +0000
3+++ clock/WorldClock.qml 2014-01-06 20:53:15 +0000
4@@ -74,6 +74,7 @@
5 // TODO: Add capability to also search cities provided locally with clock-app
6 SearchBox {
7 id: searchBox
8+ objectName: "worldSearchBox"
9
10 height: units.gu(4)
11 anchors { left: parent.left; right: parent.right }
12
13=== modified file 'stopwatch/LapList.qml'
14--- stopwatch/LapList.qml 2013-10-26 19:26:49 +0000
15+++ stopwatch/LapList.qml 2014-01-06 20:53:15 +0000
16@@ -83,6 +83,7 @@
17 model: lapModel
18
19 delegate: ListItem.Standard {
20+ objectName: "laps" + index
21 Label {
22 text: Utils.numberToLocaleString(lapModel.count - index);
23 anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: units.gu(3) }
24
25=== modified file 'stopwatch/StopwatchPage.qml'
26--- stopwatch/StopwatchPage.qml 2013-10-26 19:26:49 +0000
27+++ stopwatch/StopwatchPage.qml 2014-01-06 20:53:15 +0000
28@@ -43,7 +43,6 @@
29
30 ListModel {
31 id: laps
32- objectName: "laps"
33
34 property int lapStart: 0;
35
36
37=== modified file 'tests/autopilot/ubuntu_clock_app/emulators.py'
38--- tests/autopilot/ubuntu_clock_app/emulators.py 2013-11-07 16:34:43 +0000
39+++ tests/autopilot/ubuntu_clock_app/emulators.py 2014-01-06 20:53:15 +0000
40@@ -73,6 +73,10 @@
41 """Return the page containing the world cities."""
42 return self.wait_select_single("WorldClock")
43
44+ def get_search_box(self):
45+ """Returns the search box used to search for world cities online."""
46+ return self.wait_select_single('SearchBox', objectName="worldSearchBox")
47+
48 def get_world_cities_list(self):
49 """Return the component containing the list of available world cities."""
50 return self.wait_select_single(objectName="worldList")
51@@ -141,15 +145,20 @@
52
53 def get_lap_button(self):
54 """Returns the select for the lap button"""
55- return self.wait_select_single("Button", objectName="lapButton")
56+ return self.wait_select_single("ImageButton", objectName="lapButton")
57
58 def get_reset_button(self):
59 """Returns the select for the reset button"""
60 return self.wait_select_single("ImageButton", objectName="resetButton")
61
62- def get_laps(self):
63- """Returns the select for the lap count"""
64- return self.wait_select_single("ListModel", objectName="laps")
65+ def get_num_of_laps(self):
66+ """Returns the number of laps in the stopwatch page."""
67+ stopwatch_page = self.select_single("StopwatchPage")
68+ return int(stopwatch_page.wait_select_single("QQuickListView").count)
69+
70+ def get_first_laps_list_item(self):
71+ """Returns the first lap list item in the stopwatch page."""
72+ return self.wait_select_single("Standard", objectName="laps0")
73
74 # ALARM Page Emulator Functions
75 def get_addalarm_page(self):
76
77=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_clock.py'
78--- tests/autopilot/ubuntu_clock_app/tests/test_clock.py 2013-11-07 16:34:43 +0000
79+++ tests/autopilot/ubuntu_clock_app/tests/test_clock.py 2014-01-06 20:53:15 +0000
80@@ -25,6 +25,7 @@
81
82 from testtools.matchers import Equals, NotEquals
83 from autopilot.matchers import Eventually
84+from time import sleep
85
86 from ubuntu_clock_app.tests import ClockAppTestCase
87
88@@ -69,8 +70,8 @@
89 city_name = self.main_view.get_city_name(city)
90 self.main_view.select_city(city)
91 saved_city_name = self.main_view.get_city_name(self.main_view.grab_first_saved_city())
92- self.assertThat(saved_city_name, Eventually(Equals(city_name)))
93-
94+ self.assertThat(saved_city_name, Eventually(Equals(city_name)))
95+
96 def test_delete_local_world_city(self):
97 """Test to check if deleting a saved local world city works"""
98
99
100=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py'
101--- tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py 2013-11-01 21:46:43 +0000
102+++ tests/autopilot/ubuntu_clock_app/tests/test_stopwatch.py 2014-01-06 20:53:15 +0000
103@@ -41,20 +41,29 @@
104 def tearDown(self):
105 super(TestStopwatch, self).tearDown()
106
107+ def create_lap(self):
108+ """Function to create a stopwatch lap"""
109+ lap_button = self.main_view.get_lap_button()
110+ self.pointing_device.click_object(lap_button)
111+
112+ def start_stop_stopwatch(self):
113+ """Function to start/stop the stopwatch"""
114+ start_stop_button = self.main_view.get_stopwatch_button()
115+ self.pointing_device.click_object(start_stop_button)
116+
117 def test_start_stop_reset_stopwatch(self):
118 """Test to check the proper functioning of the start/stop/reset of stopwatch"""
119
120- start_stop_button = self.main_view.get_stopwatch_button()
121 stopwatch_label = self.main_view.get_stopwatch_label()
122 reset_button = self.main_view.get_reset_button()
123
124- # Press the start button to start the stopwatch and check if the stopwatch starts ticking
125+ # Start the stopwatch and check if the stopwatch starts ticking
126 stopwatch_label_before = self.main_view.get_stopwatch_label().text
127- self.pointing_device.click_object(start_stop_button)
128+ self.start_stop_stopwatch()
129 self.assertThat(stopwatch_label.text, Eventually(NotEquals("00:00.0")))
130
131- # Press stop and check if the stopwatch has indeed stopped
132- self.pointing_device.click_object(start_stop_button)
133+ # Stop the stopwatch and check it has indeed stopped
134+ self.start_stop_stopwatch()
135 self.assertThat(stopwatch_label_before, NotEquals(self.main_view.get_stopwatch_label().text))
136 stopwatch_label_after = lambda: self.main_view.get_stopwatch_label().text
137 self.assertThat(stopwatch_label_after, Eventually(Equals(self.main_view.get_stopwatch_label().text)))
138@@ -62,3 +71,48 @@
139 # Press reset and check if the stopwatch has been resetted
140 self.pointing_device.click_object(reset_button)
141 self.assertThat(stopwatch_label.text, Eventually(Equals("00:00.0")))
142+
143+ def test_create_lap(self):
144+ """Test to check creating a new stopwatch lap"""
145+
146+ # Start the stopwatch
147+ stopwatch_label = self.main_view.get_stopwatch_label().text
148+ self.start_stop_stopwatch()
149+
150+ # Ensure that the stopwatch actually ticks
151+ self.assertThat(stopwatch_label, Eventually(NotEquals("00:00.0")))
152+
153+ # Create a stopwatch lap by pressing the lap button
154+ num_of_laps_old = self.main_view.get_num_of_laps()
155+ self.create_lap()
156+
157+ # Confirm that the lap is created
158+ self.assertThat(
159+ self.main_view.get_num_of_laps,
160+ Eventually(Equals(num_of_laps_old + 1)))
161+
162+ def test_delete_lap(self):
163+ """Test to check deleting a stopwatch lap"""
164+
165+ # Start the stopwatch
166+ stopwatch_label = self.main_view.get_stopwatch_label().text
167+ self.start_stop_stopwatch()
168+
169+ # Ensure that the stopwatch actually ticks
170+ self.assertThat(stopwatch_label, Eventually(NotEquals("00:00.0")))
171+
172+ # Create a stopwatch lap
173+ self.create_lap()
174+
175+ num_of_laps_old = self.main_view.get_num_of_laps()
176+ self.main_view.drag_page_up("StopwatchPage", self)
177+
178+ # Delete stopwatch lap
179+ first_lap = self.main_view.get_first_laps_list_item()
180+ first_lap.swipe_to_delete()
181+ first_lap.confirm_removal()
182+
183+ # Check that the stopwatch lap has been deleted
184+ self.assertThat(
185+ self.main_view.get_num_of_laps,
186+ Eventually(Equals(num_of_laps_old - 1)))
187
188=== modified file 'tests/autopilot/ubuntu_clock_app/tests/test_timer.py'
189--- tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2013-11-01 21:46:43 +0000
190+++ tests/autopilot/ubuntu_clock_app/tests/test_timer.py 2014-01-06 20:53:15 +0000
191@@ -24,6 +24,7 @@
192 from testtools.matchers import Equals, NotEquals, Is, Not
193 from autopilot.matchers import Eventually
194 from time import sleep
195+
196 from ubuntu_clock_app.tests import ClockAppTestCase
197
198

Subscribers

People subscribed via source and target branches