-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversionUtilityWithMultipleSuites.py
124 lines (92 loc) · 4.7 KB
/
conversionUtilityWithMultipleSuites.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import sys
import json;
class DataFetcher_ConverterUtility:
def __init__(self, filePath):
self.filePath = filePath;
jsonFile = open(self.filePath)
self.jsonData = json.load(jsonFile)
def sanitize(self, input):
input = input.replace("&", "&").replace("\"", """)
input = input.replace("<", "<").replace(">", ">")
return input
def getTotalTestCasesInSuite(self,suiteIndex):
return len(self.jsonData[suiteIndex]['results'])
def getTotalTestSuite(self):
return len(self.jsonData)
def getTestSuiteInfo(self, testSuiteIndex):
testSuiteDatDictionary = {};
jsonResultData = self.jsonData[testSuiteIndex]['results'];
generationTime = self.jsonData[testSuiteIndex]['generated_at'];
testSuiteDatDictionary["generated_at"] = generationTime;
totalTestCasesInSuite = self.getTotalTestCasesInSuite(testSuiteIndex)
testSuiteDatDictionary["testCounts"] = totalTestCasesInSuite;
return testSuiteDatDictionary;
def getTestCasesInfo(self, suiteIndex, testCaseIndex):
testCaseDatDictionary = {};
jsonResultData = self.jsonData[suiteIndex]['results'][testCaseIndex];
nodeData = jsonResultData['node'];
executionTime = jsonResultData['execution_time'];
# if jsonResultData['fail'] is None:
# testCaseFailureStatus = True;
# else:
# testCaseFailureStatus = False;
if jsonResultData['fail']:
testCaseFailureStatus = True;
else:
testCaseFailureStatus = False;
if jsonResultData['error'] != None:
# testCaseErrorMessage = self.sanitize(jsonResultData['error']);
testCaseErrorMessage = jsonResultData['error'];
else:
testCaseErrorMessage = " ";
testCaseClassName = nodeData['package_name'];
testCaseName = nodeData['name'];
testCaseDatDictionary["executionTime"] = executionTime;
testCaseDatDictionary['testCaseFailureStatus'] = testCaseFailureStatus;
testCaseDatDictionary['testCaseErrorMessage'] = testCaseErrorMessage;
testCaseDatDictionary['testCaseClassName'] = testCaseClassName;
testCaseDatDictionary['testCaseName'] = testCaseName;
testCaseDatDictionary['testCaseFailureStatus'] = testCaseFailureStatus;
testCaseDatDictionary['testCaseFailureType'] = 'WARNING';
return testCaseDatDictionary;
def generateXMlFile(self):
xmlHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
testSuitesStartTag = "<testsuites"
testSuitesEndTag = "</testsuites>"
testSuiteTag = ""
testSuiteStartTag = "\n" + "<testsuite"
testSuiteEndTag = "</testsuite>"
testCaseTag = ""
testCaseStart = "\n" + "<testcase"
testCaseEnd = "</testcase>"
failureTagStart = "\n" + "<failure"
failureTagEnd = "</failure>"
testSuitesStartTag += ">"
for testSuiteCounter in range(0, self.getTotalTestSuite()):
testSuiteInfo = self.getTestSuiteInfo(testSuiteCounter);
testSuiteTag += testSuiteStartTag;
testSuiteTag += " tests=" + "\"" + str(testSuiteInfo['testCounts']) + "\"";
testSuiteTag += " generated_at=" + "\"" + str(testSuiteInfo['generated_at']) + "\"";
totalTestCasesInSuite = self.getTotalTestCasesInSuite(testSuiteCounter);
for testcaseCounter in range(0, totalTestCasesInSuite):
testCaseInfo = self.getTestCasesInfo(testSuiteCounter, testcaseCounter);
testCaseTag += testCaseStart
testCaseTag += " name=" + "\"" + testCaseInfo['testCaseName'] + "\"";
testCaseTag += " class=" + "\"" + testCaseInfo['testCaseClassName'] + "\"";
testCaseTag += " time=" + "\"" + str(testCaseInfo['executionTime']) + "\"" + ">";
if testCaseInfo['testCaseFailureStatus']:
testCaseTag += failureTagStart;
testCaseTag += " message=" + "\"" + testCaseInfo['testCaseErrorMessage'] + "\"";
testCaseTag += " type=" + "\"" + testCaseInfo['testCaseFailureType'] + "\"";
testCaseTag += ">" + failureTagEnd + "\n";
testCaseTag += testCaseEnd + "\n";
testSuiteTag += ">" + testCaseTag;
testSuiteTag += ">" + testSuiteEndTag + "\n";
testSuitesStartTag += testSuiteTag;
testSuitesStartTag += testSuitesEndTag + "\n";
return xmlHeader + testSuitesStartTag;
object = DataFetcher_ConverterUtility(".//run_results.json");
data = object.generateXMlFile()
xmlFile = open(".//output.xml", 'w');
xmlFile.write(data)
xmlFile.close();