~canonical-platform-qa/ubuntu-system-tests/shared-cpo-data

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/telegram/__init__.py

  • Committer: Tarmac
  • Author(s): Omer Akram, Richard Huddie
  • Date: 2016-05-13 09:28:31 UTC
  • mfrom: (375.1.36 test_add_telegram)
  • Revision ID: tarmac-20160513092831-eal6txep611ytp3y
* CPO for telegram app
* test: login to telegram.

Approved by platform-qa-bot, Richard Huddie, sbaldassin.

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 System Tests
 
4
# Copyright (C) 2016 Canonical
 
5
#
 
6
# This program is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation, either version 3 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
from ubuntu_system_tests.helpers import autopilot
 
20
from ubuntu_system_tests.helpers import context
 
21
from ubuntu_system_tests.helpers import processes
 
22
from ubuntu_system_tests.helpers.scopes.apps import (
 
23
    launch_application_from_apps_scope)
 
24
from ubuntu_system_tests.helpers import wait_until
 
25
 
 
26
APP = 'telegram'
 
27
APP_ID = 'com.ubuntu.telegram'
 
28
APP_NAME = 'Telegram'
 
29
APP_WIN_ID = 'com.ubuntu.telegram_telegram'
 
30
 
 
31
 
 
32
def launch_telegram_app():
 
33
    """
 
34
    Launch the telegram app from apps scope and return proxy object.
 
35
 
 
36
    :return: Proxy object for telegram application.
 
37
 
 
38
    """
 
39
    launch_application_from_apps_scope(APP_NAME)
 
40
    if not wait_until(is_telegram_app_running, period=0.5):
 
41
        raise RuntimeError('Telegram process did not start.')
 
42
    context.shared.add_cleanup(processes.stop_process, APP)
 
43
    return get_telegram_app_proxy(pid=get_telegram_process_id())
 
44
 
 
45
 
 
46
def is_telegram_app_running():
 
47
    """ Indicate if the telegram app is currently running """
 
48
    return processes.is_process_running(APP)
 
49
 
 
50
 
 
51
def get_telegram_app_proxy(pid):
 
52
    """
 
53
    Return telegram app proxy object from existing process.
 
54
 
 
55
    :return: Proxy object for telegram application.
 
56
    """
 
57
    from ubuntu_system_tests.helpers.telegram._cpo import MainView  # NOQA
 
58
    proxy = autopilot.get_proxy_object(pid=pid)
 
59
    return autopilot.patched_wait_select_single(
 
60
        root=proxy, class_object=MainView, class_name='MainView')
 
61
 
 
62
 
 
63
def get_telegram_process_id():
 
64
    """
 
65
    Return PID of the telegram process to be used for dbus introspection
 
66
 
 
67
    Telegram app have two PIDs when its started, the latest process is what
 
68
    is usable for dbus introspection, so we return the leftmost PID from the
 
69
    list of PIDs.
 
70
 
 
71
    :return: PID of telegram app
 
72
    """
 
73
    return processes.get_process_ids(APP)[0]