~ahayzen/+junk/screen_size

« back to all changes in this revision

Viewing changes to tests/autopilot/screen_size/__init__.py

  • Committer: Andrew Hayzen
  • Date: 2014-06-05 13:26:12 UTC
  • Revision ID: ahayzen@gmail.com-20140605132612-9tjkg5hkjkkgtuam
* Screen size app

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
import os
 
6
import subprocess
 
7
 
 
8
from autopilot import input, platform
 
9
from autopilot.matchers import Eventually
 
10
from testtools.matchers import Equals
 
11
from ubuntuuitoolkit import base, emulators
 
12
 
 
13
 
 
14
def _get_module_include_path():
 
15
    return os.path.join(get_path_to_source_root(), 'modules')
 
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 ClickAppTestCase(base.UbuntuUIToolkitAppTestCase):
 
25
    """Common test case that provides several useful methods for the tests."""
 
26
 
 
27
    package_id = ''  # TODO
 
28
    app_name = 'screen_size'
 
29
 
 
30
    def setUp(self):
 
31
        super(ClickAppTestCase, self).setUp()
 
32
        self.pointing_device = input.Pointer(self.input_device_class.create())
 
33
        self.launch_application()
 
34
 
 
35
        self.assertThat(self.main_view.visible, Eventually(Equals(True)))
 
36
 
 
37
    def launch_application(self):
 
38
        if platform.model() == 'Desktop':
 
39
            self._launch_application_from_desktop()
 
40
        else:
 
41
            self._launch_application_from_phablet()
 
42
 
 
43
    def _launch_application_from_desktop(self):
 
44
        app_qml_source_location = self._get_app_qml_source_path()
 
45
        if os.path.exists(app_qml_source_location):
 
46
            self.app = self.launch_test_application(
 
47
                base.get_qmlscene_launch_command(),
 
48
                '-I' + _get_module_include_path(),
 
49
                app_qml_source_location,
 
50
                app_type='qt',
 
51
                emulator_base=emulators.UbuntuUIToolkitEmulatorBase)
 
52
        else:
 
53
            raise NotImplementedError(
 
54
                "On desktop we can't install click packages yet, so we can "
 
55
                "only run from source.")
 
56
 
 
57
    def _get_app_qml_source_path(self):
 
58
        qml_file_name = '{0}.qml'.format(self.app_name)
 
59
        return os.path.join(self._get_path_to_app_source(), qml_file_name)
 
60
 
 
61
    def _get_path_to_app_source(self):
 
62
        return os.path.join(get_path_to_source_root(), self.app_name)
 
63
 
 
64
    def _launch_application_from_phablet(self):
 
65
        # On phablet, we only run the tests against the installed click
 
66
        # package.
 
67
        self.app = self.launch_click_package(self.pacakge_id, self.app_name)
 
68
 
 
69
    @property
 
70
    def main_view(self):
 
71
        return self.app.select_single(emulators.MainView)