Repository navigation
Expand file tree
/
Copy pathcucumberbot.py
More file actions
92 lines (86 loc) · 3.11 KB
/
Copy pathcucumberbot.py
File metadata and controls
92 lines (86 loc) · 3.11 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import ast
from cukejson import CukeJson
from extras import browser_name_from_json, tag_format, publish_path, term, banner,load_config_from_file, send_webhooks, QUIET_MODE
# CucumberBot
# Written by Ewen McCahon
# Copyright (c) Ewen McCahon 2018
TEST_ASSET_PATH = os.environ['ASSET_PATH']
TEST_SUITE_NAME = os.environ['TEST_SUITE_NAME']
PUBLISH_BASE = os.environ['PUBLISH_BASE']
try:
TAGS = os.environ['CUKE_TAGS']
except KeyError:
TAGS = '[]'
NICE_TAGS = ast.literal_eval(TAGS)
try:
BOT_CONFIG = os.environ['BOT_CONFIG']
except KeyError:
BOT_CONFIG = './config.yml'
CONFIG = load_config_from_file(BOT_CONFIG)
term('Report Directory: ' + TEST_ASSET_PATH)
def reports_in_directory(report_directory):
"""
reports_in_directory(report_directory)
Generate a Summary for All JSON Reports in a Directory
"""
dir_listing = os.listdir(report_directory)
json_files = []
for entry in dir_listing:
report_path = os.path.join(report_directory, entry)
if os.path.isfile(report_path):
if '.json' in entry:
term('Processing Report: ' + entry)
cuke_report = CukeJson(report_path, quiet_mode=QUIET_MODE)
json_files.append({
'browser_name': browser_name_from_json(report_path),
'report_url': PUBLISH_BASE + TEST_ASSET_PATH + publish_path(report_path),
'report': cuke_report,
})
return json_files
def generate_report():
"""
generate_report()
Main Function to Generate Reports
Requires Environment Variables Listed in test.sh
"""
cucumber_reports = reports_in_directory(TEST_ASSET_PATH)
if len(cucumber_reports) < 1:
return None
report_container = {
'test_suite_name': TEST_SUITE_NAME,
'results': {},
'links': {},
'tags': tag_format(NICE_TAGS)
}
failed_test = False
errored_test = False
overall_result = 'Passed'
for report_data in cucumber_reports:
report = report_data['report']
if not report.has_errors():
scenarios = report.get_total_scenarios()
passed = report.get_passed_scenarios()
result_string = str(passed) + "/" + str(scenarios) + " Scenarios Passed"
term(report_data['browser_name'] + ': ' + result_string)
report_container['results'][report_data['browser_name']] = result_string
report_container['links'][report_data['browser_name']] = report_data['report_url']
if report.get_build_status() == 'Failed':
failed_test = True
else:
errored_test = True
if errored_test:
overall_result = 'Errored'
elif failed_test:
overall_result = 'Failed'
report_container['result'] = overall_result
term(report_container)
return report_container
if __name__ == '__main__':
banner()
generated_report = generate_report()
if generated_report != None:
send_webhooks(CONFIG['webhooks'].items(), generated_report)
else:
term('No Reports in Directory: ' + str(TEST_ASSET_PATH), 'ERROR')
exit(1)