2
This module provides the main entry point for the execution automated
6
import os, re, sys, logging
8
from logging import StreamHandler, FileHandler, Formatter
9
from itertools import chain
13
from .runner import TestSuiteRunner
14
from .parser import parse_options
15
from .utils import safe_make_directory, safe_run_command
16
from .discovery import discover_applications
19
def process_application(app_data, target_directory):
21
Process all test suites in an application
23
logging.debug("Processing application '%s' (%s)"
24
% (app_data.name, app_data.path))
25
application_target = app_data.get_target_directory(target_directory)
26
safe_make_directory(application_target)
28
for suite_data in app_data.suites():
29
process_suite(suite_data, application_target)
32
def process_suite(suite_data, application_target):
34
Run the suite test cases, make sure that the logs are stored
35
in the correct directory and generate html report from them
37
runner = TestSuiteRunner(suite_data)
38
results = runner.run()
40
log_file = suite_data.get_log_filename(application_target)
41
with open(log_file, 'w') as f:
43
convert_log_file(log_file)
46
def convert_log_file(log_file):
48
Transform xml log format into html report
50
if os.path.exists(globals.SCREENSHOTS_SHARE):
51
screenshot_dir = os.path.join(os.path.dirname(log_file),
54
if not os.path.exists(screenshot_dir):
55
safe_make_directory(screenshot_dir)
57
if len(os.listdir(globals.SCREENSHOTS_SHARE)) > 0:
58
command = "mv " + globals.SCREENSHOTS_SHARE + "/* " + screenshot_dir
59
safe_run_command(command)
61
log_file_tmp = log_file + ".tmp"
62
o = open(log_file_tmp, "w")
63
data = open(log_file).read()
64
o.write(re.sub(globals.SCREENSHOTS_SHARE, "screenshots", data))
69
os.rename(log_file_tmp, log_file)
71
xsl_file = os.path.join(globals.MAGO_SHARE, "report.xsl")
72
if not os.path.exists(xsl_file):
73
logging.error("XSL file `%s' does not exist." % xsl_file)
76
html_file = log_file.replace(".log", ".html")
78
command = "xsltproc -o %s %s %s" \
79
% (html_file, xsl_file, log_file)
80
safe_run_command(command)
83
def configure_logging(log_level_str, log_filename):
85
Configure log handlers
87
log_level = logging.getLevelName(log_level_str.upper())
89
log_handlers.append(StreamHandler())
91
log_handlers.append(FileHandler(log_filename))
93
format = ("%(asctime)s %(levelname)-8s %(message)s")
95
for handler in log_handlers:
96
handler.setFormatter(Formatter(format))
97
logging.getLogger().addHandler(handler)
99
logging.getLogger().setLevel(log_level)
100
elif not logging.getLogger().handlers:
101
logging.disable(logging.CRITICAL)
104
def main(args=sys.argv):
106
Execute automated tests
108
# For the moment, all applications should be running in English
111
# Get shared directory based on the directory in which binary is located
112
options = parse_options(args)
113
configure_logging(options.log_level, options.log)
115
logging.debug('MAGO_SHARE: %s' % globals.MAGO_SHARE)
116
logging.debug('MAGO_PATH: %s' % ':'.join(globals.MAGO_PATH))
117
logging.debug('SCREENSHOTS_SHARE: %s' % globals.SCREENSHOTS_SHARE)
119
apps = discover_applications(globals.MAGO_PATH,
120
options.applications,
127
logging.warning("No test applications found")
131
process_application(app, options.target)
134
print "Application: %s - %s" % (app.name, app.path)
135
for suite in app.suites():
136
print "- Suite: %s - %s" % (suite.name, suite.filename)
137
for case in suite.cases():
138
print " - Case: %s" % case.name
143
if __name__ == "__main__":