Merge lp:~nskaggs/ubuntu-sdk-tutorials/update-currency-tests into lp:ubuntu-sdk-tutorials
- update-currency-tests
- Merge into trunk
Proposed by
Nicholas Skaggs
Status: | Merged |
---|---|
Merged at revision: | 137 |
Proposed branch: | lp:~nskaggs/ubuntu-sdk-tutorials/update-currency-tests |
Merge into: | lp:ubuntu-sdk-tutorials |
Diff against target: |
781 lines (+167/-447) 14 files modified
getting-started/CurrencyConverter/Main.qml (+0/-2) getting-started/CurrencyConverter/Makefile (+6/-6) getting-started/CurrencyConverter/tests/acceptance/currencyconverter/__init__.py (+76/-2) getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/__init__.py (+37/-43) getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/test_currencyconverter.py (+29/-74) getting-started/CurrencyConverter/tests/acceptance/run (+12/-0) getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py (+0/-17) getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py (+0/-44) getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py (+0/-165) getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py (+0/-25) getting-started/CurrencyConverter/tests/autopilot/run (+0/-12) getting-started/CurrencyConverter/tests/integration/tst_currencyconverter.qml (+6/-6) getting-started/CurrencyConverter/tests/unit/tst_convert.qml (+1/-1) getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml (+0/-50) |
To merge this branch: | bzr merge lp:~nskaggs/ubuntu-sdk-tutorials/update-currency-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Holbach (community) | Needs Fixing | ||
Review via email: mp+252776@code.launchpad.net |
Commit message
Description of the change
update tests for currency converter
To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : | # |
make test works now. Merging with dholbach's blessing.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === renamed file 'getting-started/CurrencyConverter/main.qml' => 'getting-started/CurrencyConverter/Main.qml' |
2 | --- getting-started/CurrencyConverter/main.qml 2015-01-08 17:45:23 +0000 |
3 | +++ getting-started/CurrencyConverter/Main.qml 2015-03-12 17:38:35 +0000 |
4 | @@ -10,8 +10,6 @@ |
5 | |
6 | MainView { |
7 | id: root |
8 | - // objectName for functional testing purposes (autopilot-qt5) |
9 | - objectName: "mainView" |
10 | |
11 | // Note! applicationName needs to match the "name" field of the click manifest |
12 | applicationName: "currencyconverter.yourname" |
13 | |
14 | === modified file 'getting-started/CurrencyConverter/Makefile' |
15 | --- getting-started/CurrencyConverter/Makefile 2015-01-08 17:45:23 +0000 |
16 | +++ getting-started/CurrencyConverter/Makefile 2015-03-12 17:38:35 +0000 |
17 | @@ -3,9 +3,7 @@ |
18 | # Notes for autopilot tests: |
19 | # --------------------------------------------------------------- |
20 | # In order to run autopilot tests: |
21 | -# sudo apt-add-repository ppa:autopilot/ppa |
22 | -# sudo apt-get update |
23 | -# sudo apt-get install python-autopilot autopilot-qt |
24 | +# sudo apt-get install python3-autopilot autopilot-desktop |
25 | # |
26 | # Notes for translations: |
27 | # --------------------------------------------------------------- |
28 | @@ -30,9 +28,11 @@ |
29 | |
30 | all: po/template.pot |
31 | |
32 | -autopilot: |
33 | - chmod +x tests/autopilot/run |
34 | - tests/autopilot/run |
35 | +test: |
36 | + qmltestrunner -input tests/unit |
37 | + qmltestrunner -input tests/integration |
38 | + chmod +x tests/acceptance/run |
39 | + tests/acceptance/run |
40 | |
41 | check: |
42 | qmltestrunner -input tests/unit |
43 | |
44 | === renamed directory 'getting-started/CurrencyConverter/tests/autopilot' => 'getting-started/CurrencyConverter/tests/acceptance' |
45 | === renamed directory 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter' => 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter' |
46 | === modified file 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter/__init__.py' |
47 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/__init__.py 2013-06-05 16:58:12 +0000 |
48 | +++ getting-started/CurrencyConverter/tests/acceptance/currencyconverter/__init__.py 2015-03-12 17:38:35 +0000 |
49 | @@ -1,6 +1,6 @@ |
50 | # -#- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -#- |
51 | # |
52 | -# Copyright (C) 2013 Canonical Ltd |
53 | +# Copyright (C) 2013-2015 Canonical Ltd |
54 | # |
55 | # This program is free software: you can redistribute it and/or modify |
56 | # it under the terms of the GNU General Public License version 3 as |
57 | @@ -16,4 +16,78 @@ |
58 | # |
59 | # Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com> |
60 | |
61 | -"""CurrencyConverter autopilot tests and emulators - top level package.""" |
62 | +import ubuntuuitoolkit |
63 | +import logging |
64 | +import random |
65 | + |
66 | +logger = logging.getLogger(__name__) |
67 | + |
68 | + |
69 | +class CurrencyConverter(object): |
70 | + |
71 | + """Autopilot helper object for the currencyconverter application.""" |
72 | + |
73 | + def __init__(self, app_proxy, test_type): |
74 | + self.app = app_proxy |
75 | + self.test_type = test_type |
76 | + self.main_view = self.app.select_single(Main) |
77 | + |
78 | + @property |
79 | + def pointing_device(self): |
80 | + return self.app.pointing_device |
81 | + |
82 | + |
83 | +class Main(ubuntuuitoolkit.MainView): |
84 | + |
85 | + """Autopilot helper for the MainView.""" |
86 | + |
87 | + def __init__(self, *args): |
88 | + super(Main, self).__init__(*args) |
89 | + self.visible.wait_for(True) |
90 | + self.wait_for_network() |
91 | + |
92 | + def wait_for_network(self): |
93 | + self.select_single("ActivityIndicator").running.wait_for(False) |
94 | + |
95 | + def set_random_to_value(self): |
96 | + """Sets a random value in the to currency field""" |
97 | + self.get_to_currency_field()._set_field_to_random_value() |
98 | + |
99 | + def set_random_from_value(self): |
100 | + """Sets a random value in the from currency field""" |
101 | + self.get_from_currency_field()._set_field_to_random_value() |
102 | + |
103 | + def get_clear_button(self): |
104 | + """Returns the clear button object""" |
105 | + return self.select_single("Button", objectName="clearBtn") |
106 | + |
107 | + def use_clear_button(self): |
108 | + """Clicks the clear button""" |
109 | + self.pointing_device.click_object(self.get_clear_button()) |
110 | + |
111 | + def get_from_currency_field(self): |
112 | + """Returns the from currency field""" |
113 | + return self.select_single(TextField, objectName="inputFrom") |
114 | + |
115 | + def get_to_currency_field(self): |
116 | + """Returns the to currency field""" |
117 | + return self.select_single(TextField, objectName="inputTo") |
118 | + |
119 | + def get_from_currency_button(self): |
120 | + """Returns the select for the from currency field""" |
121 | + return self.select_single("Button", objectName="selectorFrom") |
122 | + |
123 | + def get_to_currency_button(self): |
124 | + """Returns the select for the to currency field""" |
125 | + return self.select_single("Button", objectName="selectorTo") |
126 | + |
127 | + |
128 | +class TextField(ubuntuuitoolkit.TextField): |
129 | + """Autopilot helper for the Textfield.""" |
130 | + |
131 | + def _set_field_to_random_value(self): |
132 | + value = str(random.random()) |
133 | + self.write(value) |
134 | + |
135 | + def get_value(self): |
136 | + return float(self.text) |
137 | |
138 | === modified file 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/__init__.py' |
139 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py 2013-06-11 20:36:45 +0000 |
140 | +++ getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/__init__.py 2015-03-12 17:38:35 +0000 |
141 | @@ -1,6 +1,6 @@ |
142 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
143 | # |
144 | -# Copyright (C) 2013 Canonical Ltd |
145 | +# Copyright (C) 2013-2015 Canonical Ltd |
146 | # |
147 | # This program is free software: you can redistribute it and/or modify |
148 | # it under the terms of the GNU General Public License version 3 as |
149 | @@ -20,54 +20,48 @@ |
150 | """CurrencyConverter autopilot tests.""" |
151 | |
152 | import os.path |
153 | -import os |
154 | - |
155 | -from autopilot.input import Mouse, Touch, Pointer |
156 | -from autopilot.platform import model |
157 | from autopilot.testcase import AutopilotTestCase |
158 | - |
159 | -from CurrencyConverter.emulators.main_window import MainWindow |
160 | -from CurrencyConverter.emulators.ubuntusdk import ubuntusdk |
161 | +from autopilot import logging as autopilot_logging |
162 | +import logging |
163 | +import currencyconverter |
164 | +import ubuntuuitoolkit |
165 | +from ubuntuuitoolkit import base |
166 | + |
167 | +logger = logging.getLogger(__name__) |
168 | + |
169 | |
170 | class CurrencyConverterTestCase(AutopilotTestCase): |
171 | - |
172 | """A common test case class that provides several useful methods for |
173 | - CurrencyConverter tests. |
174 | - |
175 | - """ |
176 | - |
177 | - if model() == 'Desktop': |
178 | - scenarios = [('with mouse', dict(input_device_class=Mouse))] |
179 | - else: |
180 | - scenarios = [('with touch', dict(input_device_class=Touch))] |
181 | - |
182 | - local_location = "../../CurrencyConverter.qml" |
183 | + CurrencyConverter tests.""" |
184 | + |
185 | + local_location = os.path.dirname(os.path.dirname(os.getcwd())) |
186 | + local_location_qml = os.path.join(local_location, 'Main.qml') |
187 | + |
188 | + def get_launcher_and_type(self): |
189 | + if os.path.exists(self.local_location_qml): |
190 | + launcher = self.launch_test_local |
191 | + test_type = 'local' |
192 | + else: |
193 | + launcher = self.launch_test_click |
194 | + test_type = 'click' |
195 | + return launcher, test_type |
196 | |
197 | def setUp(self): |
198 | - self.pointing_device = Pointer(self.input_device_class.create()) |
199 | super(CurrencyConverterTestCase, self).setUp() |
200 | - if os.path.exists(self.local_location): |
201 | - self.launch_test_local() |
202 | - else: |
203 | - self.launch_test_installed() |
204 | + self.launcher, self.test_type = self.get_launcher_and_type() |
205 | + self.app = currencyconverter.CurrencyConverter(self.launcher(), |
206 | + self.test_type) |
207 | |
208 | + @autopilot_logging.log_action(logger.info) |
209 | def launch_test_local(self): |
210 | - self.app = self.launch_test_application( |
211 | - "qmlscene", |
212 | - self.local_location, |
213 | - app_type='qt') |
214 | - |
215 | - def launch_test_installed(self): |
216 | - self.app = self.launch_test_application( |
217 | - "qmlscene", |
218 | - "/usr/share/CurrencyConverter/CurrencyConverter.qml", |
219 | - "--desktop_file_hint=/usr/share/applications/CurrencyConverter.desktop", |
220 | - app_type='qt') |
221 | - |
222 | - @property |
223 | - def main_window(self): |
224 | - return MainWindow(self.app) |
225 | - |
226 | - @property |
227 | - def ubuntusdk(self): |
228 | - return ubuntusdk(self, self.app) |
229 | + return self.launch_test_application( |
230 | + base.get_qmlscene_launch_command(), |
231 | + self.local_location_qml, |
232 | + app_type='qt', |
233 | + emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase) |
234 | + |
235 | + @autopilot_logging.log_action(logger.info) |
236 | + def launch_test_click(self): |
237 | + return self.launch_click_package( |
238 | + "com.ubuntu.developer.yourname.currencyconverter", |
239 | + emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase) |
240 | |
241 | === renamed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py' => 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/test_currencyconverter.py' |
242 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py 2013-06-11 20:36:45 +0000 |
243 | +++ getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/test_currencyconverter.py 2015-03-12 17:38:35 +0000 |
244 | @@ -1,6 +1,6 @@ |
245 | # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
246 | # |
247 | -# Copyright (C) 2013 Canonical Ltd |
248 | +# Copyright (C) 2013-2015 Canonical Ltd |
249 | # |
250 | # This program is free software: you can redistribute it and/or modify |
251 | # it under the terms of the GNU General Public License version 3 as |
252 | @@ -19,77 +19,32 @@ |
253 | |
254 | """ Tests for CurrencyConverter """ |
255 | |
256 | -from __future__ import absolute_import |
257 | - |
258 | -from testtools.matchers import Equals, NotEquals, Not, Is |
259 | -from autopilot.matchers import Eventually |
260 | - |
261 | -from CurrencyConverter.tests import CurrencyConverterTestCase |
262 | - |
263 | - |
264 | -class TestCurrencyConverter(CurrencyConverterTestCase): |
265 | - """ Tests the CurrencyConverter page features """ |
266 | - |
267 | - def setUp(self): |
268 | - super(TestCurrencyConverter, self).setUp() |
269 | - self.assertThat( |
270 | - self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True))) |
271 | - |
272 | - def tearDown(self): |
273 | - super(TestCurrencyConverter, self).tearDown() |
274 | - |
275 | - """ Test if the currency rate is converted """ |
276 | - def test_convert_currency(self): |
277 | - fromField = self.main_window.get_from_currency_field() |
278 | - toField = self.main_window.get_to_currency_field() |
279 | - fromCurrencyButton = self.main_window.get_from_currency_button() |
280 | - toCurrencyButton = self.main_window.get_to_currency_button() |
281 | - |
282 | - #store current values |
283 | - oldToValue = toField.text |
284 | - |
285 | - #input value to convert from |
286 | - self.pointing_device.click_object(fromField) |
287 | - self.keyboard.type('1') |
288 | - |
289 | - #store current values |
290 | - oldFromValue = fromField.text |
291 | - |
292 | - #verify fromField was updated and toField is still the same |
293 | - self.assertThat(toField.text, Eventually(NotEquals(oldToValue))) |
294 | - self.assertThat(fromField.text, Eventually(Equals(oldFromValue))) |
295 | - |
296 | - #store current values |
297 | - oldFromValue = fromField.text |
298 | - oldToValue = toField.text |
299 | - |
300 | - #change the from currency |
301 | - self.ubuntusdk.set_popup_value("popoverCurrencySelector", fromCurrencyButton, 'HUF') |
302 | - |
303 | - #verify fromField was updated and toField is still the same |
304 | - self.assertThat(fromField.text, Eventually(NotEquals(oldFromValue))) |
305 | - self.assertThat(toField.text, Eventually(Equals(oldToValue))) |
306 | - |
307 | - #store current values |
308 | - oldFromValue = fromField.text |
309 | - oldToValue = toField.text |
310 | - |
311 | - #change the to currency |
312 | - self.ubuntusdk.set_popup_value("popoverCurrencySelector", toCurrencyButton, 'BGN') |
313 | - |
314 | - #verify fromField is the same and toField is updated |
315 | - self.assertThat(fromField.text, Eventually(Equals(oldFromValue))) |
316 | - self.assertThat(toField.text, Eventually(NotEquals(oldToValue))) |
317 | - |
318 | - """ Test if the clear button clears the screen """ |
319 | +from currencyconverter.tests import CurrencyConverterTestCase |
320 | + |
321 | + |
322 | +class TestMainWindow(CurrencyConverterTestCase): |
323 | + |
324 | + def test_from_currency_convert(self): |
325 | + """ Setting from currency value should update to currency """ |
326 | + |
327 | + self.app.main_view.set_random_from_value() |
328 | + to_value = self.app.main_view.get_to_currency_field().get_value() |
329 | + self.assertGreater(to_value, 0) |
330 | + |
331 | + def test_to_currency_convert(self): |
332 | + """ Setting to currency value should update from currency """ |
333 | + |
334 | + self.app.main_view.set_random_to_value() |
335 | + from_value = self.app.main_view.get_from_currency_field().get_value() |
336 | + self.assertGreater(from_value, 0) |
337 | + |
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'))) |
349 | + """ Test if the clear button clears the screen """ |
350 | + |
351 | + self.app.main_view.set_random_from_value() |
352 | + self.app.main_view.use_clear_button() |
353 | + |
354 | + self.assertEquals(self.app.main_view.get_from_currency_field().text, |
355 | + '0.0') |
356 | + self.assertEquals(self.app.main_view.get_to_currency_field().text, |
357 | + '0.0') |
358 | |
359 | === added file 'getting-started/CurrencyConverter/tests/acceptance/run' |
360 | --- getting-started/CurrencyConverter/tests/acceptance/run 1970-01-01 00:00:00 +0000 |
361 | +++ getting-started/CurrencyConverter/tests/acceptance/run 2015-03-12 17:38:35 +0000 |
362 | @@ -0,0 +1,12 @@ |
363 | +#!/bin/bash |
364 | + |
365 | +if [[ -z `which autopilot3` ]]; then |
366 | + echo "Autopilot3 is not installed. Skip" |
367 | + exit |
368 | +fi |
369 | + |
370 | +SCRIPTPATH=`dirname $0` |
371 | +pushd ${SCRIPTPATH} |
372 | +autopilot3 run -v currencyconverter |
373 | +popd |
374 | + |
375 | |
376 | === removed directory 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators' |
377 | === removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py' |
378 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py 2013-06-05 16:58:12 +0000 |
379 | +++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py 1970-01-01 00:00:00 +0000 |
380 | @@ -1,17 +0,0 @@ |
381 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
382 | -# |
383 | -# Copyright (C) 2013 Canonical Ltd |
384 | -# |
385 | -# This program is free software: you can redistribute it and/or modify |
386 | -# it under the terms of the GNU General Public License version 3 as |
387 | -# published by the Free Software Foundation. |
388 | -# |
389 | -# This program is distributed in the hope that it will be useful, |
390 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
391 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
392 | -# GNU General Public License for more details. |
393 | -# |
394 | -# You should have received a copy of the GNU General Public License |
395 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. |
396 | -# |
397 | -# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com> |
398 | |
399 | === removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py' |
400 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 2013-06-11 20:36:45 +0000 |
401 | +++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 1970-01-01 00:00:00 +0000 |
402 | @@ -1,44 +0,0 @@ |
403 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
404 | -# |
405 | -# Copyright (C) 2013 Canonical Ltd |
406 | -# |
407 | -# This program is free software: you can redistribute it and/or modify |
408 | -# it under the terms of the GNU General Public License version 3 as |
409 | -# published by the Free Software Foundation. |
410 | -# |
411 | -# This program is distributed in the hope that it will be useful, |
412 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
413 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
414 | -# GNU General Public License for more details. |
415 | -# |
416 | -# You should have received a copy of the GNU General Public License |
417 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. |
418 | -# |
419 | -# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com> |
420 | - |
421 | - |
422 | -class MainWindow(object): |
423 | - """An emulator class that makes it easy to interact with the CurrencyConverter.""" |
424 | - |
425 | - def __init__(self, app): |
426 | - self.app = app |
427 | - |
428 | - def get_clear_button(self): |
429 | - """Returns the clear button object""" |
430 | - return self.app.select_single("Button", objectName="clearBtn") |
431 | - |
432 | - def get_from_currency_field(self): |
433 | - """Returns the from currency field""" |
434 | - return self.app.select_single("TextField", objectName="inputFrom") |
435 | - |
436 | - def get_to_currency_field(self): |
437 | - """Returns the to currency field""" |
438 | - return self.app.select_single("TextField", objectName="inputTo") |
439 | - |
440 | - def get_from_currency_button(self): |
441 | - """Returns the select for the from currency field""" |
442 | - return self.app.select_single("Button", objectName="selectorFrom") |
443 | - |
444 | - def get_to_currency_button(self): |
445 | - """Returns the select for the to currency field""" |
446 | - return self.app.select_single("Button", objectName="selectorTo") |
447 | |
448 | === removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py' |
449 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py 2013-06-11 22:58:27 +0000 |
450 | +++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000 |
451 | @@ -1,165 +0,0 @@ |
452 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
453 | -# |
454 | -# Copyright (C) 2013 Canonical Ltd |
455 | -# |
456 | -# This program is free software: you can redistribute it and/or modify |
457 | -# it under the terms of the GNU General Public License version 3 as |
458 | -# published by the Free Software Foundation. |
459 | -# |
460 | -# This program is distributed in the hope that it will be useful, |
461 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
462 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
463 | -# GNU General Public License for more details. |
464 | -# |
465 | -# You should have received a copy of the GNU General Public License |
466 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. |
467 | -# |
468 | -# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com> |
469 | - |
470 | -from testtools.matchers import Equals, NotEquals, Not, Is |
471 | -from autopilot.matchers import Eventually |
472 | - |
473 | -class ubuntusdk(object): |
474 | - """An emulator class that makes it easy to interact with the ubuntu sdk applications.""" |
475 | - |
476 | - def __init__(self, autopilot, app): |
477 | - self.app = app |
478 | - self.autopilot = autopilot |
479 | - |
480 | - def get_qml_view(self): |
481 | - """Get the main QML view""" |
482 | - return self.app.select_single("QQuickView") |
483 | - |
484 | - def get_object(self, typeName, name): |
485 | - """Get a specific object""" |
486 | - return self.app.select_single(typeName, objectName=name) |
487 | - |
488 | - def get_objects(self, typeName, name): |
489 | - """Get more than one object""" |
490 | - return self.app.select_many(typeName, objectName=name) |
491 | - |
492 | - def switch_to_tab(self, tab): |
493 | - """Switch to the specified tab number""" |
494 | - tabs = self.get_tabs() |
495 | - currentTab = tabs.selectedTabIndex |
496 | - |
497 | - #perform operations until tab == currentTab |
498 | - while tab != currentTab: |
499 | - if tab > currentTab: |
500 | - self._previous_tab() |
501 | - if tab < currentTab: |
502 | - self._next_tab() |
503 | - currentTab = tabs.selectedTabIndex |
504 | - |
505 | - def toggle_toolbar(self): |
506 | - """Toggle the toolbar between revealed and hidden""" |
507 | - #check and see if the toolbar is open or not |
508 | - if self.get_toolbar().opened: |
509 | - self.hide_toolbar() |
510 | - else: |
511 | - self.open_toolbar() |
512 | - |
513 | - def get_toolbar(self): |
514 | - """Returns the toolbar in the main events view.""" |
515 | - return self.app.select_single("Toolbar") |
516 | - |
517 | - def get_toolbar_button(self, button): |
518 | - """Returns the toolbar button at position index""" |
519 | - toolbar = self.get_toolbar() |
520 | - item = toolbar.get_children_by_type("QQuickItem")[0] |
521 | - row = item.get_children_by_type("QQuickRow")[0] |
522 | - buttonLoaders = row.get_children_by_type("QQuickLoader") |
523 | - buttonLoader = buttonLoaders[button] |
524 | - return buttonLoader |
525 | - |
526 | - def click_toolbar_button(self, value): |
527 | - """Clicks the toolbar button with value""" |
528 | - #The toolbar button is assumed to be the following format |
529 | - #ToolbarActions { |
530 | - # Action { |
531 | - # objectName: "name" |
532 | - # text: value |
533 | - toolbar = self.get_toolbar() |
534 | - if not toolbar.opened: |
535 | - self.open_toolbar() |
536 | - item = toolbar.get_children_by_type("QQuickItem")[0] |
537 | - row = item.get_children_by_type("QQuickRow")[0] |
538 | - buttonList = row.get_children_by_type("QQuickLoader") |
539 | - for button in buttonList: |
540 | - itemList = lambda: self.get_objects("Action", button) |
541 | - |
542 | - for item in itemList(): |
543 | - if item.get_properties()['text'] == value: |
544 | - self.autopilot.pointing_device.click_object(item) |
545 | - |
546 | - def open_toolbar(self): |
547 | - """Open the toolbar""" |
548 | - qmlView = self.get_qml_view() |
549 | - |
550 | - lineX = qmlView.x + qmlView.width * 0.50 |
551 | - startY = qmlView.y + qmlView.height - 1 |
552 | - stopY = qmlView.y + qmlView.height - 200 |
553 | - |
554 | - self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY) |
555 | - self.autopilot.pointing_device.click() |
556 | - self.autopilot.pointing_device.click() |
557 | - |
558 | - def hide_toolbar(self): |
559 | - """Hide the toolbar""" |
560 | - qmlView = self.get_qml_view() |
561 | - |
562 | - lineX = qmlView.x + qmlView.width * 0.50 |
563 | - startY = qmlView.y + qmlView.height - 200 |
564 | - stopY = qmlView.y + qmlView.height - 1 |
565 | - |
566 | - self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY) |
567 | - self.autopilot.pointing_device.click() |
568 | - self.autopilot.pointing_device.click() |
569 | - |
570 | - def set_popup_value(self, popover, button, value): |
571 | - """Changes the given popover selector to the request value |
572 | - At the moment this only works for values that are currently visible. To |
573 | - access the remaining items, a help method to drag and recheck is needed.""" |
574 | - #The popover is assumed to be the following format |
575 | - # Popover { |
576 | - # Column { |
577 | - # ListView { |
578 | - # delegate: Standard { |
579 | - # objectName: "name" |
580 | - # text: value |
581 | - |
582 | - self.autopilot.pointing_device.click_object(button) |
583 | - #we'll get all matching objects, incase the popover is reused between buttons |
584 | - itemList = lambda: self.get_objects("Standard", popover) |
585 | - |
586 | - for item in itemList(): |
587 | - if item.get_properties()['text'] == value: |
588 | - self.autopilot.pointing_device.click_object(item) |
589 | - |
590 | - def get_tabs(self): |
591 | - """Return all tabs""" |
592 | - return self.get_object("Tabs", "rootTabs") |
593 | - |
594 | - def _previous_tab(self): |
595 | - """Switch to the previous tab""" |
596 | - qmlView = self.get_qml_view() |
597 | - |
598 | - startX = qmlView.x + qmlView.width * 0.20 |
599 | - stopX = qmlView.x + qmlView.width * 0.50 |
600 | - lineY = qmlView.y + qmlView.height * 0.05 |
601 | - |
602 | - self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY) |
603 | - self.autopilot.pointing_device.click() |
604 | - self.autopilot.pointing_device.click() |
605 | - |
606 | - def _next_tab(self): |
607 | - """Switch to the next tab""" |
608 | - qmlView = self.get_qml_view() |
609 | - |
610 | - startX = qmlView.x + qmlView.width * 0.50 |
611 | - stopX = qmlView.x + qmlView.width * 0.20 |
612 | - lineY = qmlView.y + qmlView.height * 0.05 |
613 | - |
614 | - self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY) |
615 | - self.autopilot.pointing_device.click() |
616 | - self.autopilot.pointing_device.click() |
617 | |
618 | === removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py' |
619 | --- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py 2015-01-08 17:45:23 +0000 |
620 | +++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py 1970-01-01 00:00:00 +0000 |
621 | @@ -1,25 +0,0 @@ |
622 | -# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
623 | - |
624 | -"""Tests for the Hello World""" |
625 | - |
626 | -import os |
627 | - |
628 | -from autopilot.matchers import Eventually |
629 | -from testtools.matchers import Equals |
630 | - |
631 | -import CurrencyConverter |
632 | - |
633 | - |
634 | -class MainViewTestCase(CurrencyConverter.ClickAppTestCase): |
635 | - """Generic tests for the Hello World""" |
636 | - |
637 | - def test_initial_label(self): |
638 | - label = self.main_view.select_single(objectName='label') |
639 | - self.assertThat(label.text, Equals('Hello..')) |
640 | - |
641 | - def test_click_button_should_update_label(self): |
642 | - button = self.main_view.select_single(objectName='button') |
643 | - self.pointing_device.click_object(button) |
644 | - label = self.main_view.select_single(objectName='label') |
645 | - self.assertThat(label.text, Eventually(Equals('..world!'))) |
646 | - |
647 | |
648 | === removed file 'getting-started/CurrencyConverter/tests/autopilot/run' |
649 | --- getting-started/CurrencyConverter/tests/autopilot/run 2015-01-08 17:45:23 +0000 |
650 | +++ getting-started/CurrencyConverter/tests/autopilot/run 1970-01-01 00:00:00 +0000 |
651 | @@ -1,12 +0,0 @@ |
652 | -#!/bin/bash |
653 | - |
654 | -if [[ -z `which autopilot` ]]; then |
655 | - echo "Autopilot is not installed. Skip" |
656 | - exit |
657 | -fi |
658 | - |
659 | -SCRIPTPATH=`dirname $0` |
660 | -pushd ${SCRIPTPATH} |
661 | -autopilot run CurrencyConverter |
662 | -popd |
663 | - |
664 | |
665 | === renamed directory 'getting-started/CurrencyConverter/tests/qmltests' => 'getting-started/CurrencyConverter/tests/integration' |
666 | === renamed file 'getting-started/CurrencyConverter/tests/qmltests/tst_CurrencyConverter.qml' => 'getting-started/CurrencyConverter/tests/integration/tst_currencyconverter.qml' |
667 | --- getting-started/CurrencyConverter/tests/qmltests/tst_CurrencyConverter.qml 2014-03-05 13:39:26 +0000 |
668 | +++ getting-started/CurrencyConverter/tests/integration/tst_currencyconverter.qml 2015-03-12 17:38:35 +0000 |
669 | @@ -2,7 +2,7 @@ |
670 | import Ubuntu.Components 0.1 // we need units.gu() here |
671 | import QtTest 1.0 // for TestCase, compare() etc |
672 | import Ubuntu.Test 0.1 // for UbuntuTestCase, findChild() etc |
673 | -import "../../" |
674 | +import "../.." |
675 | |
676 | // Part 2 (read tst_currency.qml first if you haven't) |
677 | |
678 | @@ -10,16 +10,16 @@ |
679 | // This time we wrap the TestCase into an Item because we need to display |
680 | // the CurrencyConverter. |
681 | // Just like before, you can run it with |
682 | -// qmltestrunner -input tst_CurrencyConverter.qml |
683 | +// qmltestrunner -input tst_currencyconverter.qml |
684 | // Additionally you can open it in qmlscene: |
685 | -// qmlscene tst_CurrencyConverter.qml |
686 | +// qmlscene tst_currencyconverter.qml |
687 | |
688 | Item { |
689 | width: units.gu(40) |
690 | height: units.gu(30) |
691 | |
692 | // Create an instance of the QML element we want to test |
693 | - CurrencyConverter { |
694 | + Main { |
695 | id: currencyConverter |
696 | anchors.fill: parent |
697 | } |
698 | @@ -58,13 +58,13 @@ |
699 | keyClick(Qt.Key_5) |
700 | |
701 | // Now the field should contain the value 0.05 because 0.0 is already in there in the beginning |
702 | - tryCompare(inputFrom, "text", "0.05", "Input field \"From:\" does does not contain the value 0.05") |
703 | + tryCompare(inputFrom, "text", "0.05") |
704 | |
705 | var clearBtn = findChild(currencyConverter, "clearBtn") |
706 | mouseClick(clearBtn, clearBtn.width / 2, clearBtn.height / 2) |
707 | |
708 | // Now the field should be set back to "0.0" |
709 | - tryCompare(inputFrom, "text", "0.0", "Input field \"From:\" is not reset to 0.00") |
710 | + tryCompare(inputFrom, "text", "0.0") |
711 | } |
712 | |
713 | |
714 | |
715 | === renamed file 'getting-started/CurrencyConverter/tests/qmltests/tst_convert.qml' => 'getting-started/CurrencyConverter/tests/unit/tst_convert.qml' |
716 | --- getting-started/CurrencyConverter/tests/qmltests/tst_convert.qml 2014-03-05 13:39:26 +0000 |
717 | +++ getting-started/CurrencyConverter/tests/unit/tst_convert.qml 2015-03-12 17:38:35 +0000 |
718 | @@ -16,7 +16,7 @@ |
719 | |
720 | // The element we want to test. As we are not painting |
721 | // anything, don't bother with the size. |
722 | - CurrencyConverter { |
723 | + Main { |
724 | id: currencyConverter |
725 | } |
726 | |
727 | |
728 | === removed file 'getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml' |
729 | --- getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml 2015-01-08 17:45:23 +0000 |
730 | +++ getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml 1970-01-01 00:00:00 +0000 |
731 | @@ -1,50 +0,0 @@ |
732 | -import QtQuick 2.0 |
733 | -import QtTest 1.0 |
734 | -import Ubuntu.Components 1.1 |
735 | -import "../../components" |
736 | - |
737 | -// See more details @ http://qt-project.org/doc/qt-5.0/qtquick/qml-testcase.html |
738 | - |
739 | -// Execute tests with: |
740 | -// qmltestrunner |
741 | - |
742 | -Item { |
743 | - // The objects |
744 | - HelloComponent { |
745 | - id: objectUnderTest |
746 | - } |
747 | - |
748 | - TestCase { |
749 | - name: "HelloComponent" |
750 | - |
751 | - function init() { |
752 | - console.debug(">> init"); |
753 | - compare("",objectUnderTest.text,"text was not empty on init"); |
754 | - console.debug("<< init"); |
755 | - } |
756 | - |
757 | - function cleanup() { |
758 | - console.debug(">> cleanup"); |
759 | - console.debug("<< cleanup"); |
760 | - } |
761 | - |
762 | - function initTestCase() { |
763 | - console.debug(">> initTestCase"); |
764 | - console.debug("<< initTestCase"); |
765 | - } |
766 | - |
767 | - function cleanupTestCase() { |
768 | - console.debug(">> cleanupTestCase"); |
769 | - console.debug("<< cleanupTestCase"); |
770 | - } |
771 | - |
772 | - function test_canReadAndWriteText() { |
773 | - var expected = "Hello World"; |
774 | - |
775 | - objectUnderTest.text = expected; |
776 | - |
777 | - compare(expected,objectUnderTest.text,"expected did not equal result"); |
778 | - } |
779 | - } |
780 | -} |
781 | - |
daniel@ daydream: /tmp/ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er$ sudo apt-get install python3-autopilot autopilot- desktop[ sudo] password for daniel: daydream: /tmp/ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er$ make test /tmp/ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er/tests/ unit/tst_ convert. qml:19: 5: CurrencyConverter is not a type
CurrencyConve rter { little_ endian- lp64 shared (dynamic) release build; by GCC 4.9.2) :tst_convert: :compile( ) ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er/tests/ unit/tst_ convert. qml produced 1 error(s): ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er/tests/ unit/tst_ convert. qml:19, 5: CurrencyConverter is not a type sdk-tutorials/ getting- started/ CurrencyConvert er daniel/ .local/ share' local/share' share/gnome' share/ubuntu' ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er' lib/x86_ 64-linux- gnu/qt5/ bin' lib/x86_ 64-linux- gnu/qt5/ qml'
Reading package lists... Done
Building dependency tree
Reading state information... Done
autopilot-desktop is already the newest version.
python3-autopilot is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
daniel@
qmltestrunner -input tests/unit
file://
^
********* Start testing of qmltestrunner *********
Config: Using QtTest library 5.4.0, Qt 5.4.0 (x86_64-
QWARN : qmltestrunner:
/tmp/
/tmp/
Working directory: /tmp/ubuntu-
View: QQuickView, import paths:
'/home/
'/usr/share'
'/usr/
'/usr/
'/usr/
'/tmp/
'/usr/
'/usr/
Plugin paths:
'.'
FAIL! : qmltestrunner: :tst_convert: :compile( ) CurrencyConverter is not a type sdk-tutorials/ getting- started/ CurrencyConvert er/tests/ unit/tst_ convert. qml(19) ] daydream: /tmp/ubuntu- sdk-tutorials/ getting- started/ CurrencyConvert er$
Loc: [/tmp/ubuntu-
Totals: 0 passed, 1 failed, 0 skipped, 0 blacklisted
********* Finished testing of qmltestrunner *********
Makefile:32: recipe for target 'test' failed
make: *** [test] Error 1
daniel@