~renatofilho/address-book-app/fix-1200397

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2013-07-09 19:46:49 UTC
  • mfrom: (4.1.3 autopilot)
  • Revision ID: tarmac-20130709194649-569bvf3vdf2gi1fa
Initial structure for autopilot.

Approved by Omer Akram, PS Jenkins bot.

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
# Copyright 2013 Canonical
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU General Public License version 3, as published
 
6
# by the Free Software Foundation.
 
7
 
 
8
"""address-book-app autopilot tests."""
 
9
 
 
10
from os import remove
 
11
import os.path
 
12
import os
 
13
 
 
14
from autopilot.input import Mouse, Touch, Pointer
 
15
from autopilot.platform import model
 
16
from autopilot.testcase import AutopilotTestCase
 
17
from autopilot.matchers import Eventually
 
18
from testtools.matchers import Equals
 
19
 
 
20
from address_book_app.emulators.main_window import MainWindow
 
21
 
 
22
 
 
23
class AddressBookAppTestCase(AutopilotTestCase):
 
24
    """A common test case class that provides several useful methods for
 
25
    address-book-app tests.
 
26
 
 
27
    """
 
28
    DEFAULT_DEV_LOCATION = "../../src/app/address-book-app"
 
29
 
 
30
    if model() == 'Desktop':
 
31
        scenarios = [
 
32
            ('with mouse', dict(input_device_class=Mouse))]
 
33
    else:
 
34
        scenarios = [
 
35
            ('with touch', dict(input_device_class=Touch))]
 
36
 
 
37
    def setUp(self):
 
38
        self.pointing_device = Pointer(self.input_device_class.create())
 
39
        super(AddressBookAppTestCase, self).setUp()
 
40
 
 
41
        if 'AUTOPILOT_APP' in os.environ:
 
42
            self.app_bin = os.environ['AUTOPILOT_APP']
 
43
        else:
 
44
            self.app_bin  = AddressBookAppTestCase.DEFAULT_DEV_LOCATION
 
45
 
 
46
        print "Running from: %s" % (self.app_bin)
 
47
            
 
48
        if not os.path.exists(self.app_bin):
 
49
            self.launch_test_installed()
 
50
        else:
 
51
            self.launch_test_local()
 
52
 
 
53
        main_view = self.main_window.get_qml_view()
 
54
        self.assertThat(main_view.visible, Eventually(Equals(True)))         
 
55
 
 
56
    def launch_test_local(self):            
 
57
        self.app = self.launch_test_application(self.app_bin, app_type='qt')
 
58
 
 
59
    def launch_test_installed(self):
 
60
        self.app = self.launch_test_application("address-book-app",
 
61
            "--desktop_file_hint=/usr/share/applications/address-book-app.desktop",
 
62
            app_type='qt')
 
63
 
 
64
    @property
 
65
    def main_window(self):
 
66
        return MainWindow(self.app)