forked from asadmansr/android-test-report-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractReport.py
executable file
·51 lines (44 loc) · 1.43 KB
/
extractReport.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
import sys
import xml.etree.ElementTree as ET
def parseXML(xmlfile):
hasSeenFailure = False
message = ""
tree = ET.parse(xmlfile)
root = tree.getroot()
attributes = root.attrib
for k,v in attributes.items():
cs = len(k)
sp = 16-cs
print(k.capitalize() + " "*sp + v)
if ((k == "failures") and (int(v) > 0)) or ((k == "errors") and (int(v) > 0)):
f = open("extractReport_status.log", "w")
f.write("error")
f.close()
for elem in root:
if (elem.tag == "testcase"):
elem_attrib = elem.attrib
try:
failure_message = (elem.find('failure').attrib)['message']
hasSeenFailure = True
message += "\n"
message += printFormatter("testcase", elem_attrib['name']) + "\n"
message += printFormatter("message", failure_message) + "\n"
message += printFormatter("time", elem_attrib['time']) + "\n"
except AttributeError:
pass
if (hasSeenFailure):
print("")
print("Failed Test Cases:")
print("------------------")
print(message)
print("")
def printFormatter(key, msg):
keyLen = len(key)
space = 12-keyLen
return(key.capitalize() + " "*space + msg)
def main():
path = sys.argv[1]
print(path + "\n")
parseXML(path)
if __name__ == "__main__":
main()