1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
"""Ubuntu Touch App autopilot tests."""
7
from tempfile import mktemp
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
16
def get_module_include_path():
17
return os.path.abspath(
19
os.path.dirname(__file__),
29
class UbuntuTouchAppTestCase(AutopilotTestCase):
30
"""A common test case class that provides several useful methods for the tests."""
32
if model() == 'Desktop':
34
('with mouse', dict(input_device_class=Mouse))
38
('with touch', dict(input_device_class=Touch))
42
def main_window(self):
43
return MainWindow(self.app)
47
self.pointing_device = Pointer(self.input_device_class.create())
48
super(UbuntuTouchAppTestCase, self).setUp()
49
self.launch_test_qml()
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)
63
self.app = self.launch_test_application(
64
"/usr/lib/" + arch + "/qt5/bin/qmlscene",
65
"-I", get_module_include_path(),
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(),
77
self.assertThat(self.get_qml_view().visible, Eventually(Equals(True)))
80
def get_qml_view(self):
81
"""Get the main QML view"""
83
return self.app.select_single("QQuickView")
85
def get_mainview(self):
86
"""Get the QML MainView"""
88
mainView = self.app.select_single("MainView")
89
self.assertThat(mainView, Not(Is(None)))
93
def get_object(self,objectName):
94
"""Get a object based on the objectName"""
96
obj = self.app.select_single(objectName=objectName)
97
self.assertThat(obj, Not(Is(None)))
101
def mouse_click(self,objectName):
102
"""Move mouse on top of the object and click on it"""
104
obj = self.get_object(objectName)
105
self.pointing_device.move_to_object(obj)
106
self.pointing_device.click()
109
def mouse_press(self,objectName):
110
"""Move mouse on top of the object and press mouse button (without releasing it)"""
112
obj = self.get_object(objectName)
113
self.pointing_device.move_to_object(obj)
114
self.pointing_device.press()
117
def mouse_release(self):
118
"""Release mouse button"""
120
self.pointing_device.release()
123
def type_string(self, string):
124
"""Type a string with keyboard"""
126
self.keyboard.type(string)
129
def type_key(self, key):
130
"""Type a single key with keyboard"""
132
self.keyboard.key(key)