Merge lp:~nskaggs/ubuntu-sdk-tutorials/update-currency-tests into lp:ubuntu-sdk-tutorials

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
Reviewer Review Type Date Requested Status
Daniel Holbach (community) Needs Fixing
Review via email: mp+252776@code.launchpad.net

Description of the change

update tests for currency converter

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote :

daniel@daydream:/tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter$ sudo apt-get install python3-autopilot autopilot-desktop[sudo] password for daniel:
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@daydream:/tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter$ make test
qmltestrunner -input tests/unit
file:///tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter/tests/unit/tst_convert.qml:19:5: CurrencyConverter is not a type
         CurrencyConverter {
         ^
********* Start testing of qmltestrunner *********
Config: Using QtTest library 5.4.0, Qt 5.4.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 4.9.2)
QWARN : qmltestrunner::tst_convert::compile()
  /tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter/tests/unit/tst_convert.qml produced 1 error(s):
    /tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter/tests/unit/tst_convert.qml:19,5: CurrencyConverter is not a type
  Working directory: /tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter
  View: QQuickView, import paths:
    '/home/daniel/.local/share'
    '/usr/share'
    '/usr/local/share'
    '/usr/share/gnome'
    '/usr/share/ubuntu'
    '/tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter'
    '/usr/lib/x86_64-linux-gnu/qt5/bin'
    '/usr/lib/x86_64-linux-gnu/qt5/qml'
  Plugin paths:
    '.'

FAIL! : qmltestrunner::tst_convert::compile() CurrencyConverter is not a type
   Loc: [/tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter/tests/unit/tst_convert.qml(19)]
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@daydream:/tmp/ubuntu-sdk-tutorials/getting-started/CurrencyConverter$

review: Needs Fixing
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

make test works now. Merging with dholbach's blessing.

137. By Nicholas Skaggs

merge lp:~nskaggs/ubuntu-sdk-tutorials/update-currency-tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== renamed file 'getting-started/CurrencyConverter/main.qml' => 'getting-started/CurrencyConverter/Main.qml'
--- getting-started/CurrencyConverter/main.qml 2015-01-08 17:45:23 +0000
+++ getting-started/CurrencyConverter/Main.qml 2015-03-12 17:38:35 +0000
@@ -10,8 +10,6 @@
1010
11MainView {11MainView {
12 id: root12 id: root
13 // objectName for functional testing purposes (autopilot-qt5)
14 objectName: "mainView"
1513
16 // Note! applicationName needs to match the "name" field of the click manifest14 // Note! applicationName needs to match the "name" field of the click manifest
17 applicationName: "currencyconverter.yourname"15 applicationName: "currencyconverter.yourname"
1816
=== modified file 'getting-started/CurrencyConverter/Makefile'
--- getting-started/CurrencyConverter/Makefile 2015-01-08 17:45:23 +0000
+++ getting-started/CurrencyConverter/Makefile 2015-03-12 17:38:35 +0000
@@ -3,9 +3,7 @@
3# Notes for autopilot tests:3# Notes for autopilot tests:
4# ---------------------------------------------------------------4# ---------------------------------------------------------------
5# In order to run autopilot tests:5# In order to run autopilot tests:
6# sudo apt-add-repository ppa:autopilot/ppa6# sudo apt-get install python3-autopilot autopilot-desktop
7# sudo apt-get update
8# sudo apt-get install python-autopilot autopilot-qt
9#7#
10# Notes for translations:8# Notes for translations:
11# ---------------------------------------------------------------9# ---------------------------------------------------------------
@@ -30,9 +28,11 @@
3028
31all: po/template.pot29all: po/template.pot
3230
33autopilot:31test:
34 chmod +x tests/autopilot/run32 qmltestrunner -input tests/unit
35 tests/autopilot/run33 qmltestrunner -input tests/integration
34 chmod +x tests/acceptance/run
35 tests/acceptance/run
3636
37check:37check:
38 qmltestrunner -input tests/unit38 qmltestrunner -input tests/unit
3939
=== renamed directory 'getting-started/CurrencyConverter/tests/autopilot' => 'getting-started/CurrencyConverter/tests/acceptance'
=== renamed directory 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter' => 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter'
=== modified file 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter/__init__.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/__init__.py 2013-06-05 16:58:12 +0000
+++ getting-started/CurrencyConverter/tests/acceptance/currencyconverter/__init__.py 2015-03-12 17:38:35 +0000
@@ -1,6 +1,6 @@
1# -#- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -#-1# -#- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -#-
2#2#
3# Copyright (C) 2013 Canonical Ltd3# Copyright (C) 2013-2015 Canonical Ltd
4#4#
5# This program is free software: you can redistribute it and/or modify5# 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 as6# it under the terms of the GNU General Public License version 3 as
@@ -16,4 +16,78 @@
16#16#
17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>17# Authored by: Nicholas Skaggs <nicholas.skaggs@canonical.com>
1818
19"""CurrencyConverter autopilot tests and emulators - top level package."""19import ubuntuuitoolkit
20import logging
21import random
22
23logger = logging.getLogger(__name__)
24
25
26class CurrencyConverter(object):
27
28 """Autopilot helper object for the currencyconverter application."""
29
30 def __init__(self, app_proxy, test_type):
31 self.app = app_proxy
32 self.test_type = test_type
33 self.main_view = self.app.select_single(Main)
34
35 @property
36 def pointing_device(self):
37 return self.app.pointing_device
38
39
40class Main(ubuntuuitoolkit.MainView):
41
42 """Autopilot helper for the MainView."""
43
44 def __init__(self, *args):
45 super(Main, self).__init__(*args)
46 self.visible.wait_for(True)
47 self.wait_for_network()
48
49 def wait_for_network(self):
50 self.select_single("ActivityIndicator").running.wait_for(False)
51
52 def set_random_to_value(self):
53 """Sets a random value in the to currency field"""
54 self.get_to_currency_field()._set_field_to_random_value()
55
56 def set_random_from_value(self):
57 """Sets a random value in the from currency field"""
58 self.get_from_currency_field()._set_field_to_random_value()
59
60 def get_clear_button(self):
61 """Returns the clear button object"""
62 return self.select_single("Button", objectName="clearBtn")
63
64 def use_clear_button(self):
65 """Clicks the clear button"""
66 self.pointing_device.click_object(self.get_clear_button())
67
68 def get_from_currency_field(self):
69 """Returns the from currency field"""
70 return self.select_single(TextField, objectName="inputFrom")
71
72 def get_to_currency_field(self):
73 """Returns the to currency field"""
74 return self.select_single(TextField, objectName="inputTo")
75
76 def get_from_currency_button(self):
77 """Returns the select for the from currency field"""
78 return self.select_single("Button", objectName="selectorFrom")
79
80 def get_to_currency_button(self):
81 """Returns the select for the to currency field"""
82 return self.select_single("Button", objectName="selectorTo")
83
84
85class TextField(ubuntuuitoolkit.TextField):
86 """Autopilot helper for the Textfield."""
87
88 def _set_field_to_random_value(self):
89 value = str(random.random())
90 self.write(value)
91
92 def get_value(self):
93 return float(self.text)
2094
=== modified file 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/__init__.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/tests/__init__.py 2013-06-11 20:36:45 +0000
+++ getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/__init__.py 2015-03-12 17:38:35 +0000
@@ -1,6 +1,6 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Copyright (C) 2013 Canonical Ltd3# Copyright (C) 2013-2015 Canonical Ltd
4#4#
5# This program is free software: you can redistribute it and/or modify5# 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 as6# it under the terms of the GNU General Public License version 3 as
@@ -20,54 +20,48 @@
20"""CurrencyConverter autopilot tests."""20"""CurrencyConverter autopilot tests."""
2121
22import os.path22import os.path
23import os
24
25from autopilot.input import Mouse, Touch, Pointer
26from autopilot.platform import model
27from autopilot.testcase import AutopilotTestCase23from autopilot.testcase import AutopilotTestCase
2824from autopilot import logging as autopilot_logging
29from CurrencyConverter.emulators.main_window import MainWindow25import logging
30from CurrencyConverter.emulators.ubuntusdk import ubuntusdk26import currencyconverter
27import ubuntuuitoolkit
28from ubuntuuitoolkit import base
29
30logger = logging.getLogger(__name__)
31
3132
32class CurrencyConverterTestCase(AutopilotTestCase):33class CurrencyConverterTestCase(AutopilotTestCase):
33
34 """A common test case class that provides several useful methods for34 """A common test case class that provides several useful methods for
35 CurrencyConverter tests.35 CurrencyConverter tests."""
3636
37 """37 local_location = os.path.dirname(os.path.dirname(os.getcwd()))
3838 local_location_qml = os.path.join(local_location, 'Main.qml')
39 if model() == 'Desktop':39
40 scenarios = [('with mouse', dict(input_device_class=Mouse))]40 def get_launcher_and_type(self):
41 else:41 if os.path.exists(self.local_location_qml):
42 scenarios = [('with touch', dict(input_device_class=Touch))]42 launcher = self.launch_test_local
4343 test_type = 'local'
44 local_location = "../../CurrencyConverter.qml"44 else:
45 launcher = self.launch_test_click
46 test_type = 'click'
47 return launcher, test_type
4548
46 def setUp(self):49 def setUp(self):
47 self.pointing_device = Pointer(self.input_device_class.create())
48 super(CurrencyConverterTestCase, self).setUp()50 super(CurrencyConverterTestCase, self).setUp()
49 if os.path.exists(self.local_location):51 self.launcher, self.test_type = self.get_launcher_and_type()
50 self.launch_test_local()52 self.app = currencyconverter.CurrencyConverter(self.launcher(),
51 else:53 self.test_type)
52 self.launch_test_installed()
5354
55 @autopilot_logging.log_action(logger.info)
54 def launch_test_local(self):56 def launch_test_local(self):
55 self.app = self.launch_test_application(57 return self.launch_test_application(
56 "qmlscene",58 base.get_qmlscene_launch_command(),
57 self.local_location,59 self.local_location_qml,
58 app_type='qt')60 app_type='qt',
5961 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
60 def launch_test_installed(self):62
61 self.app = self.launch_test_application(63 @autopilot_logging.log_action(logger.info)
62 "qmlscene",64 def launch_test_click(self):
63 "/usr/share/CurrencyConverter/CurrencyConverter.qml",65 return self.launch_click_package(
64 "--desktop_file_hint=/usr/share/applications/CurrencyConverter.desktop",66 "com.ubuntu.developer.yourname.currencyconverter",
65 app_type='qt')67 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
66
67 @property
68 def main_window(self):
69 return MainWindow(self.app)
70
71 @property
72 def ubuntusdk(self):
73 return ubuntusdk(self, self.app)
7468
=== renamed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py' => 'getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/test_currencyconverter.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/tests/test_CurrencyConverter.py 2013-06-11 20:36:45 +0000
+++ getting-started/CurrencyConverter/tests/acceptance/currencyconverter/tests/test_currencyconverter.py 2015-03-12 17:38:35 +0000
@@ -1,6 +1,6 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#2#
3# Copyright (C) 2013 Canonical Ltd3# Copyright (C) 2013-2015 Canonical Ltd
4#4#
5# This program is free software: you can redistribute it and/or modify5# 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 as6# it under the terms of the GNU General Public License version 3 as
@@ -19,77 +19,32 @@
1919
20""" Tests for CurrencyConverter """20""" Tests for CurrencyConverter """
2121
22from __future__ import absolute_import22from currencyconverter.tests import CurrencyConverterTestCase
2323
24from testtools.matchers import Equals, NotEquals, Not, Is24
25from autopilot.matchers import Eventually25class TestMainWindow(CurrencyConverterTestCase):
2626
27from CurrencyConverter.tests import CurrencyConverterTestCase27 def test_from_currency_convert(self):
2828 """ Setting from currency value should update to currency """
2929
30class TestCurrencyConverter(CurrencyConverterTestCase):30 self.app.main_view.set_random_from_value()
31 """ Tests the CurrencyConverter page features """31 to_value = self.app.main_view.get_to_currency_field().get_value()
3232 self.assertGreater(to_value, 0)
33 def setUp(self):33
34 super(TestCurrencyConverter, self).setUp()34 def test_to_currency_convert(self):
35 self.assertThat(35 """ Setting to currency value should update from currency """
36 self.ubuntusdk.get_qml_view().visible, Eventually(Equals(True)))36
3737 self.app.main_view.set_random_to_value()
38 def tearDown(self):38 from_value = self.app.main_view.get_from_currency_field().get_value()
39 super(TestCurrencyConverter, self).tearDown()39 self.assertGreater(from_value, 0)
4040
41 """ Test if the currency rate is converted """
42 def test_convert_currency(self):
43 fromField = self.main_window.get_from_currency_field()
44 toField = self.main_window.get_to_currency_field()
45 fromCurrencyButton = self.main_window.get_from_currency_button()
46 toCurrencyButton = self.main_window.get_to_currency_button()
47
48 #store current values
49 oldToValue = toField.text
50
51 #input value to convert from
52 self.pointing_device.click_object(fromField)
53 self.keyboard.type('1')
54
55 #store current values
56 oldFromValue = fromField.text
57
58 #verify fromField was updated and toField is still the same
59 self.assertThat(toField.text, Eventually(NotEquals(oldToValue)))
60 self.assertThat(fromField.text, Eventually(Equals(oldFromValue)))
61
62 #store current values
63 oldFromValue = fromField.text
64 oldToValue = toField.text
65
66 #change the from currency
67 self.ubuntusdk.set_popup_value("popoverCurrencySelector", fromCurrencyButton, 'HUF')
68
69 #verify fromField was updated and toField is still the same
70 self.assertThat(fromField.text, Eventually(NotEquals(oldFromValue)))
71 self.assertThat(toField.text, Eventually(Equals(oldToValue)))
72
73 #store current values
74 oldFromValue = fromField.text
75 oldToValue = toField.text
76
77 #change the to currency
78 self.ubuntusdk.set_popup_value("popoverCurrencySelector", toCurrencyButton, 'BGN')
79
80 #verify fromField is the same and toField is updated
81 self.assertThat(fromField.text, Eventually(Equals(oldFromValue)))
82 self.assertThat(toField.text, Eventually(NotEquals(oldToValue)))
83
84 """ Test if the clear button clears the screen """
85 def test_clear_button(self):41 def test_clear_button(self):
86 clearButton = self.main_window.get_clear_button()42 """ Test if the clear button clears the screen """
87 fromField = self.main_window.get_from_currency_field()43
88 toField = self.main_window.get_to_currency_field()44 self.app.main_view.set_random_from_value()
8945 self.app.main_view.use_clear_button()
90 #click the clear button46
91 self.pointing_device.click_object(clearButton)47 self.assertEquals(self.app.main_view.get_from_currency_field().text,
9248 '0.0')
93 #confirm fields have been wiped49 self.assertEquals(self.app.main_view.get_to_currency_field().text,
94 self.assertThat(fromField.text, Eventually(Equals('0.0')))50 '0.0')
95 self.assertThat(toField.text, Eventually(Equals('0.0')))
9651
=== added file 'getting-started/CurrencyConverter/tests/acceptance/run'
--- getting-started/CurrencyConverter/tests/acceptance/run 1970-01-01 00:00:00 +0000
+++ getting-started/CurrencyConverter/tests/acceptance/run 2015-03-12 17:38:35 +0000
@@ -0,0 +1,12 @@
1#!/bin/bash
2
3if [[ -z `which autopilot3` ]]; then
4 echo "Autopilot3 is not installed. Skip"
5 exit
6fi
7
8SCRIPTPATH=`dirname $0`
9pushd ${SCRIPTPATH}
10autopilot3 run -v currencyconverter
11popd
12
013
=== removed directory 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators'
=== removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py 2013-06-05 16:58:12 +0000
+++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,17 +0,0 @@
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>
180
=== removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 2013-06-11 20:36:45 +0000
+++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/main_window.py 1970-01-01 00:00:00 +0000
@@ -1,44 +0,0 @@
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
19
20class MainWindow(object):
21 """An emulator class that makes it easy to interact with the CurrencyConverter."""
22
23 def __init__(self, app):
24 self.app = app
25
26 def get_clear_button(self):
27 """Returns the clear button object"""
28 return self.app.select_single("Button", objectName="clearBtn")
29
30 def get_from_currency_field(self):
31 """Returns the from currency field"""
32 return self.app.select_single("TextField", objectName="inputFrom")
33
34 def get_to_currency_field(self):
35 """Returns the to currency field"""
36 return self.app.select_single("TextField", objectName="inputTo")
37
38 def get_from_currency_button(self):
39 """Returns the select for the from currency field"""
40 return self.app.select_single("Button", objectName="selectorFrom")
41
42 def get_to_currency_button(self):
43 """Returns the select for the to currency field"""
44 return self.app.select_single("Button", objectName="selectorTo")
450
=== removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py 2013-06-11 22:58:27 +0000
+++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/emulators/ubuntusdk.py 1970-01-01 00:00:00 +0000
@@ -1,165 +0,0 @@
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, button):
67 """Returns the toolbar button at position index"""
68 toolbar = self.get_toolbar()
69 item = toolbar.get_children_by_type("QQuickItem")[0]
70 row = item.get_children_by_type("QQuickRow")[0]
71 buttonLoaders = row.get_children_by_type("QQuickLoader")
72 buttonLoader = buttonLoaders[button]
73 return buttonLoader
74
75 def click_toolbar_button(self, value):
76 """Clicks the toolbar button with value"""
77 #The toolbar button is assumed to be the following format
78 #ToolbarActions {
79 # Action {
80 # objectName: "name"
81 # text: value
82 toolbar = self.get_toolbar()
83 if not toolbar.opened:
84 self.open_toolbar()
85 item = toolbar.get_children_by_type("QQuickItem")[0]
86 row = item.get_children_by_type("QQuickRow")[0]
87 buttonList = row.get_children_by_type("QQuickLoader")
88 for button in buttonList:
89 itemList = lambda: self.get_objects("Action", button)
90
91 for item in itemList():
92 if item.get_properties()['text'] == value:
93 self.autopilot.pointing_device.click_object(item)
94
95 def open_toolbar(self):
96 """Open the toolbar"""
97 qmlView = self.get_qml_view()
98
99 lineX = qmlView.x + qmlView.width * 0.50
100 startY = qmlView.y + qmlView.height - 1
101 stopY = qmlView.y + qmlView.height - 200
102
103 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
104 self.autopilot.pointing_device.click()
105 self.autopilot.pointing_device.click()
106
107 def hide_toolbar(self):
108 """Hide the toolbar"""
109 qmlView = self.get_qml_view()
110
111 lineX = qmlView.x + qmlView.width * 0.50
112 startY = qmlView.y + qmlView.height - 200
113 stopY = qmlView.y + qmlView.height - 1
114
115 self.autopilot.pointing_device.drag(lineX, startY, lineX, stopY)
116 self.autopilot.pointing_device.click()
117 self.autopilot.pointing_device.click()
118
119 def set_popup_value(self, popover, button, value):
120 """Changes the given popover selector to the request value
121 At the moment this only works for values that are currently visible. To
122 access the remaining items, a help method to drag and recheck is needed."""
123 #The popover is assumed to be the following format
124 # Popover {
125 # Column {
126 # ListView {
127 # delegate: Standard {
128 # objectName: "name"
129 # text: value
130
131 self.autopilot.pointing_device.click_object(button)
132 #we'll get all matching objects, incase the popover is reused between buttons
133 itemList = lambda: self.get_objects("Standard", popover)
134
135 for item in itemList():
136 if item.get_properties()['text'] == value:
137 self.autopilot.pointing_device.click_object(item)
138
139 def get_tabs(self):
140 """Return all tabs"""
141 return self.get_object("Tabs", "rootTabs")
142
143 def _previous_tab(self):
144 """Switch to the previous tab"""
145 qmlView = self.get_qml_view()
146
147 startX = qmlView.x + qmlView.width * 0.20
148 stopX = qmlView.x + qmlView.width * 0.50
149 lineY = qmlView.y + qmlView.height * 0.05
150
151 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
152 self.autopilot.pointing_device.click()
153 self.autopilot.pointing_device.click()
154
155 def _next_tab(self):
156 """Switch to the next tab"""
157 qmlView = self.get_qml_view()
158
159 startX = qmlView.x + qmlView.width * 0.50
160 stopX = qmlView.x + qmlView.width * 0.20
161 lineY = qmlView.y + qmlView.height * 0.05
162
163 self.autopilot.pointing_device.drag(startX, lineY, stopX, lineY)
164 self.autopilot.pointing_device.click()
165 self.autopilot.pointing_device.click()
1660
=== removed file 'getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py'
--- getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py 2015-01-08 17:45:23 +0000
+++ getting-started/CurrencyConverter/tests/autopilot/CurrencyConverter/test_main.py 1970-01-01 00:00:00 +0000
@@ -1,25 +0,0 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
3"""Tests for the Hello World"""
4
5import os
6
7from autopilot.matchers import Eventually
8from testtools.matchers import Equals
9
10import CurrencyConverter
11
12
13class MainViewTestCase(CurrencyConverter.ClickAppTestCase):
14 """Generic tests for the Hello World"""
15
16 def test_initial_label(self):
17 label = self.main_view.select_single(objectName='label')
18 self.assertThat(label.text, Equals('Hello..'))
19
20 def test_click_button_should_update_label(self):
21 button = self.main_view.select_single(objectName='button')
22 self.pointing_device.click_object(button)
23 label = self.main_view.select_single(objectName='label')
24 self.assertThat(label.text, Eventually(Equals('..world!')))
25
260
=== removed file 'getting-started/CurrencyConverter/tests/autopilot/run'
--- getting-started/CurrencyConverter/tests/autopilot/run 2015-01-08 17:45:23 +0000
+++ getting-started/CurrencyConverter/tests/autopilot/run 1970-01-01 00:00:00 +0000
@@ -1,12 +0,0 @@
1#!/bin/bash
2
3if [[ -z `which autopilot` ]]; then
4 echo "Autopilot is not installed. Skip"
5 exit
6fi
7
8SCRIPTPATH=`dirname $0`
9pushd ${SCRIPTPATH}
10autopilot run CurrencyConverter
11popd
12
130
=== renamed directory 'getting-started/CurrencyConverter/tests/qmltests' => 'getting-started/CurrencyConverter/tests/integration'
=== renamed file 'getting-started/CurrencyConverter/tests/qmltests/tst_CurrencyConverter.qml' => 'getting-started/CurrencyConverter/tests/integration/tst_currencyconverter.qml'
--- getting-started/CurrencyConverter/tests/qmltests/tst_CurrencyConverter.qml 2014-03-05 13:39:26 +0000
+++ getting-started/CurrencyConverter/tests/integration/tst_currencyconverter.qml 2015-03-12 17:38:35 +0000
@@ -2,7 +2,7 @@
2import Ubuntu.Components 0.1 // we need units.gu() here2import Ubuntu.Components 0.1 // we need units.gu() here
3import QtTest 1.0 // for TestCase, compare() etc3import QtTest 1.0 // for TestCase, compare() etc
4import Ubuntu.Test 0.1 // for UbuntuTestCase, findChild() etc4import Ubuntu.Test 0.1 // for UbuntuTestCase, findChild() etc
5import "../../"5import "../.."
66
7// Part 2 (read tst_currency.qml first if you haven't)7// Part 2 (read tst_currency.qml first if you haven't)
88
@@ -10,16 +10,16 @@
10// This time we wrap the TestCase into an Item because we need to display10// This time we wrap the TestCase into an Item because we need to display
11// the CurrencyConverter.11// the CurrencyConverter.
12// Just like before, you can run it with12// Just like before, you can run it with
13// qmltestrunner -input tst_CurrencyConverter.qml13// qmltestrunner -input tst_currencyconverter.qml
14// Additionally you can open it in qmlscene:14// Additionally you can open it in qmlscene:
15// qmlscene tst_CurrencyConverter.qml15// qmlscene tst_currencyconverter.qml
1616
17Item {17Item {
18 width: units.gu(40)18 width: units.gu(40)
19 height: units.gu(30)19 height: units.gu(30)
2020
21 // Create an instance of the QML element we want to test21 // Create an instance of the QML element we want to test
22 CurrencyConverter {22 Main {
23 id: currencyConverter23 id: currencyConverter
24 anchors.fill: parent24 anchors.fill: parent
25 }25 }
@@ -58,13 +58,13 @@
58 keyClick(Qt.Key_5)58 keyClick(Qt.Key_5)
5959
60 // Now the field should contain the value 0.05 because 0.0 is already in there in the beginning60 // Now the field should contain the value 0.05 because 0.0 is already in there in the beginning
61 tryCompare(inputFrom, "text", "0.05", "Input field \"From:\" does does not contain the value 0.05")61 tryCompare(inputFrom, "text", "0.05")
6262
63 var clearBtn = findChild(currencyConverter, "clearBtn")63 var clearBtn = findChild(currencyConverter, "clearBtn")
64 mouseClick(clearBtn, clearBtn.width / 2, clearBtn.height / 2)64 mouseClick(clearBtn, clearBtn.width / 2, clearBtn.height / 2)
65 65
66 // Now the field should be set back to "0.0"66 // Now the field should be set back to "0.0"
67 tryCompare(inputFrom, "text", "0.0", "Input field \"From:\" is not reset to 0.00")67 tryCompare(inputFrom, "text", "0.0")
68 }68 }
6969
7070
7171
=== renamed file 'getting-started/CurrencyConverter/tests/qmltests/tst_convert.qml' => 'getting-started/CurrencyConverter/tests/unit/tst_convert.qml'
--- getting-started/CurrencyConverter/tests/qmltests/tst_convert.qml 2014-03-05 13:39:26 +0000
+++ getting-started/CurrencyConverter/tests/unit/tst_convert.qml 2015-03-12 17:38:35 +0000
@@ -16,7 +16,7 @@
1616
17 // The element we want to test. As we are not painting17 // The element we want to test. As we are not painting
18 // anything, don't bother with the size.18 // anything, don't bother with the size.
19 CurrencyConverter {19 Main {
20 id: currencyConverter20 id: currencyConverter
21 }21 }
2222
2323
=== removed file 'getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml'
--- getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml 2015-01-08 17:45:23 +0000
+++ getting-started/CurrencyConverter/tests/unit/tst_hellocomponent.qml 1970-01-01 00:00:00 +0000
@@ -1,50 +0,0 @@
1import QtQuick 2.0
2import QtTest 1.0
3import Ubuntu.Components 1.1
4import "../../components"
5
6// See more details @ http://qt-project.org/doc/qt-5.0/qtquick/qml-testcase.html
7
8// Execute tests with:
9// qmltestrunner
10
11Item {
12 // The objects
13 HelloComponent {
14 id: objectUnderTest
15 }
16
17 TestCase {
18 name: "HelloComponent"
19
20 function init() {
21 console.debug(">> init");
22 compare("",objectUnderTest.text,"text was not empty on init");
23 console.debug("<< init");
24 }
25
26 function cleanup() {
27 console.debug(">> cleanup");
28 console.debug("<< cleanup");
29 }
30
31 function initTestCase() {
32 console.debug(">> initTestCase");
33 console.debug("<< initTestCase");
34 }
35
36 function cleanupTestCase() {
37 console.debug(">> cleanupTestCase");
38 console.debug("<< cleanupTestCase");
39 }
40
41 function test_canReadAndWriteText() {
42 var expected = "Hello World";
43
44 objectUnderTest.text = expected;
45
46 compare(expected,objectUnderTest.text,"expected did not equal result");
47 }
48 }
49}
50

Subscribers

People subscribed via source and target branches