~abreu-alexandre/qtcreator-plugin-ubuntu/fix-html5-app-launch-1504

« back to all changes in this revision

Viewing changes to share/qtcreator/templates/wizards/ubuntu/simple-app-qmlproject/tests/autopilot/displayName/__init__.py

  • Committer: CI Train Bot
  • Author(s): nskaggs, Nicholas Skaggs
  • Date: 2015-06-16 14:47:50 UTC
  • mfrom: (391.1.14 update-qml-autopilot)
  • Revision ID: ci-train-bot@canonical.com-20150616144750-yh4z1evebap3sty2
Update qml based templates to best practicies
Approved by: Zoltan Balogh, PS Jenkins bot, Max Brustkern

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
 
 
3
 
"""Ubuntu Touch App Autopilot tests."""
4
 
 
5
 
import os
6
 
 
 
2
"""Application autopilot helpers."""
 
3
 
 
4
import logging
7
5
import ubuntuuitoolkit
8
6
 
9
 
from autopilot import introspection
10
 
from autopilot.matchers import Eventually
11
 
from testtools.matchers import Equals
12
 
from ubuntuuitoolkit import base
13
 
 
14
 
 
15
 
PACKAGE_ID = '%ProjectName:l%.%ClickDomain:l%'
16
 
 
17
 
 
18
 
def get_path_to_source_root():
19
 
    return os.path.abspath(
20
 
        os.path.join(
21
 
            os.path.dirname(__file__), '..', '..', '..', '..'))
22
 
 
23
 
 
24
 
class ApplicationCustomProxyObject(
25
 
        ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
26
 
 
27
 
    """Autopilot custom proxy object for the app."""
28
 
 
29
 
    @classmethod
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:
35
 
                return True
36
 
        return False
 
7
logger = logging.getLogger(__name__)
 
8
 
 
9
 
 
10
class AppException(ubuntuuitoolkit.ToolkitException):
 
11
 
 
12
    """Exception raised when there are problems with the Application."""
 
13
 
 
14
 
 
15
class TouchApp(object):
 
16
 
 
17
    """Autopilot helper object for the application."""
 
18
 
 
19
    def __init__(self, app_proxy, test_type):
 
20
        self.app = app_proxy
 
21
        self.test_type = test_type
 
22
        self.main_view = self.app.select_single(MainView)
37
23
 
38
24
    @property
39
 
    def main_view(self):
40
 
        return self.select_single(ubuntuuitoolkit.MainView)
41
 
 
42
 
 
43
 
class ClickAppTestCase(base.UbuntuUIToolkitAppTestCase):
44
 
 
45
 
    """Common test case that provides several useful methods for the tests."""
46
 
 
47
 
    project_name = '%ProjectName%'
48
 
 
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)
54
 
        else:
55
 
            app = self._launch_installed_application()
56
 
 
57
 
        self.assertThat(app.main_view.visible, Eventually(Equals(True)))
58
 
        return app
59
 
 
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)
63
 
 
64
 
    def _get_path_to_project_source(self):
65
 
        return os.path.join(get_path_to_source_root(), self.project_name)
66
 
 
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,
71
 
            app_type='qt',
72
 
            emulator_base=ApplicationCustomProxyObject)
73
 
 
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
 
27
 
 
28
 
 
29
class MainView(ubuntuuitoolkit.MainView):
 
30
 
 
31
    """A helper that makes it easy to interact with the mainview"""
 
32
 
 
33
    def __init__(self, *args):
 
34
        super(MainView, self).__init__(*args)
 
35
        self.visible.wait_for(True, 30)
 
36
 
 
37
    def get_button(self):
 
38
        return self.select_single('Button', objectName="button")
 
39
 
 
40
    def get_label(self):
 
41
        return self.select_single('Label', objectName="label")
 
 
b'\\ No newline at end of file'