1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4
# Copyright (C) 2016 Canonical
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.
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.
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/>.
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
27
APP_ID = 'com.ubuntu.telegram'
29
APP_WIN_ID = 'com.ubuntu.telegram_telegram'
32
def launch_telegram_app():
34
Launch the telegram app from apps scope and return proxy object.
36
:return: Proxy object for telegram application.
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())
46
def is_telegram_app_running():
47
""" Indicate if the telegram app is currently running """
48
return processes.is_process_running(APP)
51
def get_telegram_app_proxy(pid):
53
Return telegram app proxy object from existing process.
55
:return: Proxy object for telegram application.
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')
63
def get_telegram_process_id():
65
Return PID of the telegram process to be used for dbus introspection
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
71
:return: PID of telegram app
73
return processes.get_process_ids(APP)[0]