~ubuntu-clock-dev/ubuntu-clock-app/reboot-packaging

« back to all changes in this revision

Viewing changes to app/tests/autopilot/ubuntu-clock-app/__init__.py

Setup autopilot infrastructure and added alarm test

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
 
3
 
"""Ubuntu Touch App autopilot tests."""
4
 
 
5
 
from os import remove
6
 
import os.path
7
 
from tempfile import mktemp
8
 
import subprocess
9
 
 
10
 
from autopilot.input import Mouse, Touch, Pointer
11
 
from autopilot.matchers import Eventually
12
 
from autopilot.platform import model
13
 
from testtools.matchers import Is, Not, Equals
14
 
from autopilot.testcase import AutopilotTestCase
15
 
 
16
 
def get_module_include_path():
17
 
    return os.path.abspath(
18
 
        os.path.join(
19
 
            os.path.dirname(__file__),
20
 
            '..',
21
 
            '..',
22
 
            '..',
23
 
            '..',
24
 
            'backend',
25
 
            'modules')
26
 
        )
27
 
 
28
 
 
29
 
class UbuntuTouchAppTestCase(AutopilotTestCase):
30
 
    """A common test case class that provides several useful methods for the tests."""
31
 
 
32
 
    if model() == 'Desktop':
33
 
        scenarios = [
34
 
        ('with mouse', dict(input_device_class=Mouse))
35
 
        ]
36
 
    else:
37
 
        scenarios = [
38
 
        ('with touch', dict(input_device_class=Touch))
39
 
        ]
40
 
 
41
 
    @property
42
 
    def main_window(self):
43
 
        return MainWindow(self.app)
44
 
 
45
 
 
46
 
    def setUp(self):
47
 
        self.pointing_device = Pointer(self.input_device_class.create())
48
 
        super(UbuntuTouchAppTestCase, self).setUp()
49
 
        self.launch_test_qml()
50
 
 
51
 
 
52
 
    def launch_test_qml(self):
53
 
        # If the test class has defined a 'test_qml' class attribute then we
54
 
        # write it to disk and launch it inside the QML Scene. If not, then we
55
 
        # silently do nothing (presumably the test has something else planned).
56
 
        arch = subprocess.check_output(["dpkg-architecture",
57
 
        "-qDEB_HOST_MULTIARCH"]).strip()
58
 
        if hasattr(self, 'test_qml') and isinstance(self.test_qml, basestring):
59
 
            qml_path = mktemp(suffix='.qml')
60
 
            open(qml_path, 'w').write(self.test_qml)
61
 
            self.addCleanup(remove, qml_path)
62
 
 
63
 
            self.app = self.launch_test_application(
64
 
                "/usr/lib/" + arch + "/qt5/bin/qmlscene",
65
 
                "-I", get_module_include_path(),
66
 
                qml_path,
67
 
                app_type='qt')
68
 
 
69
 
        if hasattr(self, 'test_qml_file') and isinstance(self.test_qml_file, basestring):
70
 
            qml_path = self.test_qml_file
71
 
            self.app = self.launch_test_application(
72
 
                "/usr/lib/" + arch + "/qt5/bin/qmlscene",
73
 
                "-I", get_module_include_path(),
74
 
                qml_path,
75
 
                app_type='qt')
76
 
 
77
 
        self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))
78
 
 
79
 
 
80
 
    def get_qml_view(self):
81
 
        """Get the main QML view"""
82
 
 
83
 
        return self.app.select_single("QQuickView")
84
 
 
85
 
    def get_mainview(self):
86
 
        """Get the QML MainView"""
87
 
 
88
 
        mainView = self.app.select_single("MainView")
89
 
        self.assertThat(mainView, Not(Is(None)))
90
 
        return mainView
91
 
 
92
 
 
93
 
    def get_object(self,objectName):
94
 
        """Get a object based on the objectName"""
95
 
 
96
 
        obj = self.app.select_single(objectName=objectName)
97
 
        self.assertThat(obj, Not(Is(None)))
98
 
        return obj
99
 
 
100
 
 
101
 
    def mouse_click(self,objectName):
102
 
        """Move mouse on top of the object and click on it"""
103
 
 
104
 
        obj = self.get_object(objectName)
105
 
        self.pointing_device.move_to_object(obj)
106
 
        self.pointing_device.click()
107
 
 
108
 
 
109
 
    def mouse_press(self,objectName):
110
 
        """Move mouse on top of the object and press mouse button (without releasing it)"""
111
 
 
112
 
        obj = self.get_object(objectName)
113
 
        self.pointing_device.move_to_object(obj)
114
 
        self.pointing_device.press()
115
 
 
116
 
 
117
 
    def mouse_release(self):
118
 
        """Release mouse button"""
119
 
 
120
 
        self.pointing_device.release()     
121
 
 
122
 
 
123
 
    def type_string(self, string):
124
 
        """Type a string with keyboard"""
125
 
 
126
 
        self.keyboard.type(string)
127
 
 
128
 
 
129
 
    def type_key(self, key):
130
 
        """Type a single key with keyboard"""
131
 
 
132
 
        self.keyboard.key(key)