1 # -*- coding: UTF-8 -*-
3 from time
import sleep
, localtime
, strftime
4 from dogtail
.utils
import isA11yEnabled
, enableA11y
5 if not isA11yEnabled():
8 from common_steps
import App
, dummy
, cleanup
, non_block_read
9 from dogtail
.config
import config
13 def before_all(context
):
14 """Setup evolution stuff
15 Being executed once before any test
19 # Close running evo instances
20 os
.system("evolution --force-shutdown > /dev/null")
22 # Skip dogtail actions to print to stdout
23 config
.logDebugToStdOut
= False
24 config
.typingDelay
= 0.2
26 # Include assertion object
27 context
.assertion
= dummy()
29 # Cleanup existing data before any test
32 # Store scenario start time for session logs
33 context
.log_start_time
= strftime("%Y-%m-%d %H:%M:%S", localtime())
35 context
.app_class
= App('evolution')
37 except Exception as e
:
38 print("Error in before_all: %s" % e
.message
)
41 def after_step(context
, step
):
43 if step
.status
== 'failed' and hasattr(context
, "embed"):
44 # Embed screenshot if HTML report is used
45 os
.system("dbus-send --print-reply --session --type=method_call " +
46 "--dest='org.gnome.Shell.Screenshot' " +
47 "'/org/gnome/Shell/Screenshot' " +
48 "org.gnome.Shell.Screenshot.Screenshot " +
49 "boolean:true boolean:false string:/tmp/screenshot.png")
50 context
.embed('image/png', open("/tmp/screenshot.png", 'r').read())
51 except Exception as e
:
52 print("Error in after_step: %s" % str(e
))
55 def after_scenario(context
, scenario
):
56 """Teardown for each scenario
57 Kill evolution (in order to make this reliable we send sigkill)
60 # Attach journalctl logs
61 if hasattr(context
, "embed"):
62 os
.system("journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> /tmp/journal-session.log" % context
.log_start_time
)
63 data
= open("/tmp/journal-session.log", 'r').read()
65 context
.embed('text/plain', data
)
67 context
.app_class
.kill()
69 stdout
= non_block_read(context
.app_class
.process
.stdout
)
70 stderr
= non_block_read(context
.app_class
.process
.stderr
)
73 context
.embed('text/plain', stdout
)
76 context
.embed('text/plain', stderr
)
78 # Make some pause after scenario
80 except Exception as e
:
81 # Stupid behave simply crashes in case exception has occurred
82 print("Error in after_scenario: %s" % e
.message
)