-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
78 lines (63 loc) · 2.28 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -- FILE: features/steps/example_steps.py
import os
import logging
from gi.repository import GLib
from behave import then, step
from time import sleep
from dogtail.tree import root, SearchError
from dogtail.rawinput import keyCombo
@step(u'Press "{sequence}"')
def press_button_sequence(context, sequence):
keyCombo(sequence)
sleep(0.5)
def wait_for_app_to_appear(context, app):
# Waiting for a window to appear
for attempt in xrange(0, 10):
try:
context.app.instance = root.application(app.lower())
context.app.instance.child(roleName='frame')
break
except (GLib.GError, SearchError):
sleep(1)
continue
context.execute_steps("Then %s should start" % app)
@step(u'Start {app} via {type:w}')
def start_app_via_command(context, app, type):
for attempt in xrange(0, 10):
try:
if type == 'command':
context.app.startViaCommand()
if type == 'menu':
context.app.startViaMenu()
break
except GLib.GError:
sleep(1)
if attempt == 6:
# Killall the app processes if app didn't show up after 5 seconds
os.system("pkill -f %s 2&> /dev/null" % app.lower())
os.system("python cleanup.py")
context.execute_steps("* Start %s via command" % app)
continue
@step(u'Close app via gnome panel')
def close_app_via_gnome_panel(context):
context.app.closeViaGnomePanel()
@step(u'Make sure that {app} is running')
def ensure_app_running(context, app):
start_app_via_command(context, app, 'command')
wait_for_app_to_appear(context, app)
logging.debug("app = %s", root.application(app.lower()))
@then(u'{app} should start')
def test_app_started(context, app):
# Dogtail seems to cache applications list
# So we should wait for exception here
try:
root.application(app.lower()).child(roleName='frame')
except SearchError:
raise RuntimeError("App '%s' is not running" % app)
@then(u"{app} shouldn't be running anymore")
def then_app_is_dead(context, app):
try:
root.application(app.lower()).child(roleName='frame')
raise RuntimeError("App '%s' is running" % app)
except SearchError:
pass