1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
"""Ubuntu Touch App Autopilot tests."""
2
"""Application autopilot helpers."""
7
5
import ubuntuuitoolkit
9
from autopilot import introspection
10
from autopilot.matchers import Eventually
11
from testtools.matchers import Equals
12
from ubuntuuitoolkit import base
15
PACKAGE_ID = '%ProjectName:l%.%ClickDomain:l%'
18
def get_path_to_source_root():
19
return os.path.abspath(
21
os.path.dirname(__file__), '..', '..', '..', '..'))
24
class ApplicationCustomProxyObject(
25
ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
27
"""Autopilot custom proxy object for the app."""
30
def validate_dbus_object(cls, path, state):
31
application_name = PACKAGE_ID
32
name = introspection.get_classname_from_path(path)
33
if str(name) == application_name:
34
if state['applicationName'][1] == application_name:
7
logger = logging.getLogger(__name__)
10
class AppException(ubuntuuitoolkit.ToolkitException):
12
"""Exception raised when there are problems with the Application."""
15
class TouchApp(object):
17
"""Autopilot helper object for the application."""
19
def __init__(self, app_proxy, test_type):
21
self.test_type = test_type
22
self.main_view = self.app.select_single(MainView)
40
return self.select_single(ubuntuuitoolkit.MainView)
43
class ClickAppTestCase(base.UbuntuUIToolkitAppTestCase):
45
"""Common test case that provides several useful methods for the tests."""
47
project_name = '%ProjectName%'
49
def launch_application(self):
50
app_qml_source_location = self._get_app_qml_source_path()
51
if os.path.exists(app_qml_source_location):
52
app = self._launch_application_from_source(
53
app_qml_source_location)
55
app = self._launch_installed_application()
57
self.assertThat(app.main_view.visible, Eventually(Equals(True)))
60
def _get_app_qml_source_path(self):
61
qml_file_name = 'Main.qml'
62
return os.path.join(self._get_path_to_project_source(), qml_file_name)
64
def _get_path_to_project_source(self):
65
return os.path.join(get_path_to_source_root(), self.project_name)
67
def _launch_application_from_source(self, app_qml_source_location):
68
return self.launch_test_application(
69
base.get_qmlscene_launch_command(),
70
app_qml_source_location,
72
emulator_base=ApplicationCustomProxyObject)
74
def _launch_installed_application(self):
75
return self.launch_click_package(
76
PACKAGE_ID, emulator_base=ApplicationCustomProxyObject)
25
def pointing_device(self):
26
return self.app.pointing_device
29
class MainView(ubuntuuitoolkit.MainView):
31
"""A helper that makes it easy to interact with the mainview"""
33
def __init__(self, *args):
34
super(MainView, self).__init__(*args)
35
self.visible.wait_for(True, 30)
38
return self.select_single('Button', objectName="button")
41
return self.select_single('Label', objectName="label")
b'\\ No newline at end of file'