[gnome-logs/wip/test: 23/33] Add environment.py
- From: Rashi Aswani <aswanirashi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-logs/wip/test: 23/33] Add environment.py
- Date: Wed, 19 Aug 2015 05:50:43 +0000 (UTC)
commit 0fbba33c2ad00918c430660f54da5f022775b79b
Author: Rashi Aswani <aswanirashi19 gmail com>
Date: Tue Jul 21 19:29:23 2015 +0530
Add environment.py
tests/common_steps.py | 2 +-
tests/environment.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 1 deletions(-)
---
diff --git a/tests/common_steps.py b/tests/common_steps.py
index 803fbff..b449bbd 100644
--- a/tests/common_steps.py
+++ b/tests/common_steps.py
@@ -33,7 +33,7 @@ class App(object):
This class does all basic events with the app
"""
def __init__(
- self, appName, shortcut='<Control><Q>', a11yAppName="None",
+ self, appName, shortcut='<Control><Q>', a11yAppName=None,
forceKill=True, parameters='', recordVideo=False):
"""
Initialize object App
diff --git a/tests/environment.py b/tests/environment.py
new file mode 100644
index 0000000..f0f7bdb
--- /dev/null
+++ b/tests/environment.py
@@ -0,0 +1,82 @@
+# -*- coding: UTF-8 -*-
+
+from time import sleep, localtime, strftime
+from dogtail.utils import isA11yEnabled, enableA11y
+if not isA11yEnabled():
+ enableA11y(True)
+
+from common_steps import App, dummy, cleanup
+from dogtail.config import config
+import os
+
+def before_all(context):
+ """Setup logs stuff
+ Being executed once before any test
+ """
+
+ try:
+ # Close running logs instances
+ os.system("./gnome-logs-test --force-shutdown > /dev/null")
+
+ # Skip dogtail actions to print to stdout
+ config.logDebugToStdOut = False
+ config.typingDelay = 0.2
+
+ # Include assertion object
+ context.assertion = dummy()
+
+ # Cleanup existing data before any test
+ cleanup()
+
+ # Store scenario start time for session logs
+ context.log_start_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
+
+ context.app_class = App('./gnome-logs-test')
+
+ except Exception as e:
+ print("Error in before_all: %s" % e.message)
+
+
+def after_step(context, step):
+ try:
+ if step.status == 'failed' and hasattr(context, "embed"):
+ # Embed screenshot if HTML report is used
+ os.system("dbus-send --print-reply --session --type=method_call " +
+ "--dest='org.gnome.Shell.Screenshot' " +
+ "'/org/gnome/Shell/Screenshot' " +
+ "org.gnome.Shell.Screenshot.Screenshot " +
+ "boolean:true boolean:false string:/tmp/screenshot.png")
+ context.embed('image/png', open("/tmp/screenshot.png", 'r').read())
+ except Exception as e:
+ print("Error in after_step: %s" % str(e))
+
+
+def after_scenario(context, scenario):
+ """Teardown for each scenario
+ Kill logs (in order to make this reliable we send sigkill)
+ """
+
+ try:
+ # Attach journalctl logs
+ if hasattr(context, "embed"):
+ os.system("journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'>
/tmp/journal-session.log" % context.log_start_time)
+ data = open("/tmp/journal-session.log", 'r').read()
+ if data:
+ context.embed('text/plain', data)
+
+ context.app_class.kill()
+
+ stdout = non_block_read(context.app_class.process.stdout)
+ stderr = non_block_read(context.app_class.process.stderr)
+
+ if stdout:
+ context.embed('text/plain', stdout)
+
+ if stderr:
+ context.embed('text/plain', stderr)
+
+ # Make some pause after scenario
+ sleep(1)
+ except Exception as e:
+ # Stupid behave simply crashes in case exception has occurred
+ print("Error in after_scenario: %s" % e.message)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]