Merge lp:~nskaggs/ubuntu-sdk-tutorials/autopilot into lp:ubuntu-sdk-tutorials

Proposed by Nicholas Skaggs
Status: Merged
Approved by: David Planella
Approved revision: no longer in the source branch.
Merged at revision: 14
Proposed branch: lp:~nskaggs/ubuntu-sdk-tutorials/autopilot
Merge into: lp:ubuntu-sdk-tutorials
Diff against target: 348 lines (+273/-0)
6 files modified
CurrencyConverter/CurrencyConverter.qml (+7/-0)
CurrencyConverter/tests/autopilot/CurrencyConverter/__init__.py (+19/-0)
CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py (+17/-0)
CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py (+52/-0)
CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py (+69/-0)
CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py (+109/-0)
To merge this branch: bzr merge lp:~nskaggs/ubuntu-sdk-tutorials/autopilot
Reviewer Review Type Date Requested Status
David Planella Approve
Review via email: mp+167603@code.launchpad.net

Description of the change

Add autopilot tests

To post a comment you must log in.
Revision history for this message
David Planella (dpm) wrote :

Looks good to me, and I trust you know what you're doing! ;-)

review: Approve
14. By David Planella

Added autopilot tests to currency converter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CurrencyConverter/CurrencyConverter.qml'
2--- CurrencyConverter/CurrencyConverter.qml 2013-06-04 17:39:45 +0000
3+++ CurrencyConverter/CurrencyConverter.qml 2013-06-05 17:00:51 +0000
4@@ -85,6 +85,7 @@
5 height: parent.height - header.height
6 model: currencies
7 delegate: Standard {
8+ objectName: "currencySelectorList"
9 text: currency
10 onClicked: {
11 caller.currencyIndex = index
12@@ -110,6 +111,7 @@
13
14 Button {
15 id: selectorFrom
16+ objectName: "selectorFrom"
17 property int currencyIndex: 0
18 property TextField input: inputFrom
19 text: currencies.getCurrency(currencyIndex)
20@@ -118,6 +120,7 @@
21
22 TextField {
23 id: inputFrom
24+ objectName: "inputFrom"
25 errorHighlight: false
26 validator: DoubleValidator {notation: DoubleValidator.StandardNotation}
27 width: pageLayout.width - 2 * root.margins - root.buttonWidth
28@@ -139,6 +142,7 @@
29 spacing: units.gu(1)
30 Button {
31 id: selectorTo
32+ objectName: "selectorTo"
33 property int currencyIndex: 1
34 property TextField input: inputTo
35 text: currencies.getCurrency(currencyIndex)
36@@ -147,6 +151,7 @@
37
38 TextField {
39 id: inputTo
40+ objectName: "inputTo"
41 errorHighlight: false
42 validator: DoubleValidator {notation: DoubleValidator.StandardNotation}
43 width: pageLayout.width - 2 * root.margins - root.buttonWidth
44@@ -165,6 +170,8 @@
45 }
46
47 Button {
48+ id: clearBtn
49+ objectName: "clearBtn"
50 text: i18n.tr("Clear")
51 width: units.gu(12)
52 onClicked: {
53
54=== added directory 'CurrencyConverter/tests'
55=== added directory 'CurrencyConverter/tests/autopilot'
56=== added directory 'CurrencyConverter/tests/autopilot/CurrencyConverter'
57=== added file 'CurrencyConverter/tests/autopilot/CurrencyConverter/__init__.py'
58--- CurrencyConverter/tests/autopilot/CurrencyConverter/__init__.py 1970-01-01 00:00:00 +0000
59+++ CurrencyConverter/tests/autopilot/CurrencyConverter/__init__.py 2013-06-05 17:00:51 +0000
60@@ -0,0 +1,19 @@
61+# -#- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -#-
62+#
63+# Copyright (C) 2013 Canonical Ltd
64+#
65+# This program is free software: you can redistribute it and/or modify
66+# it under the terms of the GNU General Public License version 3 as
67+# published by the Free Software Foundation.
68+#
69+# This program is distributed in the hope that it will be useful,
70+# but WITHOUT ANY WARRANTY; without even the implied warranty of
71+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72+# GNU General Public License for more details.
73+#
74+# You should have received a copy of the GNU General Public License
75+# along with this program. If not, see <http://www.gnu.org/licenses/>.
76+#
77+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
78+
79+"""CurrencyConverter autopilot tests and emulators - top level package."""
80
81=== added directory 'CurrencyConverter/tests/autopilot/CurrencyConverter/emulators'
82=== added file 'CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py'
83--- CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py 1970-01-01 00:00:00 +0000
84+++ CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py 2013-06-05 17:00:51 +0000
85@@ -0,0 +1,17 @@
86+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
87+#
88+# Copyright (C) 2013 Canonical Ltd
89+#
90+# This program is free software: you can redistribute it and/or modify
91+# it under the terms of the GNU General Public License version 3 as
92+# published by the Free Software Foundation.
93+#
94+# This program is distributed in the hope that it will be useful,
95+# but WITHOUT ANY WARRANTY; without even the implied warranty of
96+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97+# GNU General Public License for more details.
98+#
99+# You should have received a copy of the GNU General Public License
100+# along with this program. If not, see <http://www.gnu.org/licenses/>.
101+#
102+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
103
104=== added file 'CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py'
105--- CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 1970-01-01 00:00:00 +0000
106+++ CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 2013-06-05 17:00:51 +0000
107@@ -0,0 +1,52 @@
108+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
109+#
110+# Copyright (C) 2013 Canonical Ltd
111+#
112+# This program is free software: you can redistribute it and/or modify
113+# it under the terms of the GNU General Public License version 3 as
114+# published by the Free Software Foundation.
115+#
116+# This program is distributed in the hope that it will be useful,
117+# but WITHOUT ANY WARRANTY; without even the implied warranty of
118+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119+# GNU General Public License for more details.
120+#
121+# You should have received a copy of the GNU General Public License
122+# along with this program. If not, see <http://www.gnu.org/licenses/>.
123+#
124+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
125+
126+
127+class MainWindow(object):
128+ """An emulator class that makes it easy to interact with the CurrencyConverter."""
129+
130+ def __init__(self, app):
131+ self.app = app
132+
133+ def get_qml_view(self):
134+ """Get the main QML view"""
135+ return self.app.select_single("QQuickView")
136+
137+ def get_clear_button(self):
138+ """Returns the clear button object"""
139+ return self.app.select_single("Button", objectName="clearBtn")
140+
141+ def get_from_currency_field(self):
142+ """Returns the from currency field"""
143+ return self.app.select_single("TextField", objectName="inputFrom")
144+
145+ def get_to_currency_field(self):
146+ """Returns the to currency field"""
147+ return self.app.select_single("TextField", objectName="inputTo")
148+
149+ def get_from_currency_button(self):
150+ """Returns the select for the from currency field"""
151+ return self.app.select_single("Button", objectName="selectorFrom")
152+
153+ def get_to_currency_button(self):
154+ """Returns the select for the to currency field"""
155+ return self.app.select_single("Button", objectName="selectorTo")
156+
157+ def get_object(self, typeName, name):
158+ """Returns an object using select_single method from autopilot """
159+ return self.app.select_single(typeName, objectName=name)
160
161=== added directory 'CurrencyConverter/tests/autopilot/CurrencyConverter/tests'
162=== added file 'CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py'
163--- CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py 1970-01-01 00:00:00 +0000
164+++ CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py 2013-06-05 17:00:51 +0000
165@@ -0,0 +1,69 @@
166+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
167+#
168+# Copyright (C) 2013 Canonical Ltd
169+#
170+# This program is free software: you can redistribute it and/or modify
171+# it under the terms of the GNU General Public License version 3 as
172+# published by the Free Software Foundation.
173+#
174+# This program is distributed in the hope that it will be useful,
175+# but WITHOUT ANY WARRANTY; without even the implied warranty of
176+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
177+# GNU General Public License for more details.
178+#
179+# You should have received a copy of the GNU General Public License
180+# along with this program. If not, see <http://www.gnu.org/licenses/>.
181+#
182+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
183+
184+
185+"""CurrencyConverter autopilot tests."""
186+
187+import os.path
188+import os
189+
190+from autopilot.input import Mouse, Touch, Pointer
191+from autopilot.platform import model
192+from autopilot.testcase import AutopilotTestCase
193+
194+from CurrencyConverter.emulators.main_window import MainWindow
195+
196+
197+class CurrencyConverterTestCase(AutopilotTestCase):
198+
199+ """A common test case class that provides several useful methods for
200+ CurrencyConverter tests.
201+
202+ """
203+
204+ if model() == 'Desktop':
205+ scenarios = [('with mouse', dict(input_device_class=Mouse))]
206+ else:
207+ scenarios = [('with touch', dict(input_device_class=Touch))]
208+
209+ local_location = "../../CurrencyConverter.qml"
210+
211+ def setUp(self):
212+ self.pointing_device = Pointer(self.input_device_class.create())
213+ super(CurrencyConverterTestCase, self).setUp()
214+ if os.path.exists(self.local_location):
215+ self.launch_test_local()
216+ else:
217+ self.launch_test_installed()
218+
219+ def launch_test_local(self):
220+ self.app = self.launch_test_application(
221+ "qmlscene",
222+ self.local_location,
223+ app_type='qt')
224+
225+ def launch_test_installed(self):
226+ self.app = self.launch_test_application(
227+ "qmlscene",
228+ "/usr/share/CurrencyConverter/CurrencyConverter.qml",
229+ "--desktop_file_hint=/usr/share/applications/CurrencyConverter.desktop",
230+ app_type='qt')
231+
232+ @property
233+ def main_window(self):
234+ return MainWindow(self.app)
235
236=== added file 'CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py'
237--- CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py 1970-01-01 00:00:00 +0000
238+++ CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py 2013-06-05 17:00:51 +0000
239@@ -0,0 +1,109 @@
240+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
241+#
242+# Copyright (C) 2013 Canonical Ltd
243+#
244+# This program is free software: you can redistribute it and/or modify
245+# it under the terms of the GNU General Public License version 3 as
246+# published by the Free Software Foundation.
247+#
248+# This program is distributed in the hope that it will be useful,
249+# but WITHOUT ANY WARRANTY; without even the implied warranty of
250+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
251+# GNU General Public License for more details.
252+#
253+# You should have received a copy of the GNU General Public License
254+# along with this program. If not, see <http://www.gnu.org/licenses/>.
255+#
256+# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
257+
258+
259+""" Tests for CurrencyConverter """
260+
261+from __future__ import absolute_import
262+
263+from testtools.matchers import Equals, NotEquals, Not, Is
264+from autopilot.matchers import Eventually
265+
266+from CurrencyConverter.tests import CurrencyConverterTestCase
267+
268+
269+class TestCurrencyConverter(CurrencyConverterTestCase):
270+ """ Tests the CurrencyConverter page features """
271+
272+ def setUp(self):
273+ super(TestCurrencyConverter, self).setUp()
274+ self.assertThat(
275+ self.main_window.get_qml_view().visible, Eventually(Equals(True)))
276+
277+ def tearDown(self):
278+ super(TestCurrencyConverter, self).tearDown()
279+
280+ def _set_currency(self, button, currency):
281+ """Changes the given currency selector to the requested currency
282+
283+ This only works for currencies that are currently visible. To
284+ access the remaining items, a help method to drag and recheck is
285+ needed."""
286+ self.pointing_device.click_object(button)
287+ item_list = lambda: self.main_window.get_object("Standard","currencySelectorList")
288+
289+ self.assertThat(item_list, Eventually(NotEquals(None)))
290+ for item in item_list():
291+ if item.get_properties()['text'] == currency:
292+ self.pointing_device.click_object(item)
293+
294+ """ Test if the currency rate is converted """
295+ def test_convert_currency(self):
296+ fromField = self.main_window.get_from_currency_field()
297+ toField = self.main_window.get_to_currency_field()
298+ fromCurrencyButton = self.main_window.get_from_currency_button()
299+ toCurrencyButton = self.main_window.get_to_currency_button()
300+
301+ #store current values
302+ oldToValue = toField.text
303+
304+ #input value to convert from
305+ self.pointing_device.click_object(fromField)
306+ self.keyboard.type('1')
307+
308+ #store current values
309+ oldFromValue = fromField.text
310+
311+ #verify fromField was updated and toField is still the same
312+ self.assertThat(toField.text, Eventually(NotEquals(oldToValue)))
313+ self.assertThat(fromField.text, Eventually(Equals(oldFromValue)))
314+
315+ #store current values
316+ oldFromValue = fromField.text
317+ oldToValue = toField.text
318+
319+ #change the from currency
320+ self._set_currency(fromCurrencyButton, 'HUF')
321+
322+ #verify fromField was updated and toField is still the same
323+ self.assertThat(fromField.text, Eventually(NotEquals(oldFromValue)))
324+ self.assertThat(toField.text, Eventually(Equals(oldToValue)))
325+
326+ #store current values
327+ oldFromValue = fromField.text
328+ oldToValue = toField.text
329+
330+ #change the to currency
331+ self._set_currency(toCurrencyButton, 'BGN')
332+
333+ #verify fromField is the same and toField is updated
334+ self.assertThat(fromField.text, Eventually(Equals(oldFromValue)))
335+ self.assertThat(toField.text, Eventually(NotEquals(oldToValue)))
336+
337+ """ Test if the clear button clears the screen """
338+ def test_clear_button(self):
339+ clearButton = self.main_window.get_clear_button()
340+ fromField = self.main_window.get_from_currency_field()
341+ toField = self.main_window.get_to_currency_field()
342+
343+ #click the clear button
344+ self.pointing_device.click_object(clearButton)
345+
346+ #confirm fields have been wiped
347+ self.assertThat(fromField.text, Eventually(Equals('0.0')))
348+ self.assertThat(toField.text, Eventually(Equals('0.0')))

Subscribers

People subscribed via source and target branches