diff --git a/parseTestResults.py b/parseTestResults.py index 939aa304110c5b3c819fc6c3577e5f6fdce5bf5e..9aefe0be7f9534a125cfc173b739fc640707fa59 100644 --- a/parseTestResults.py +++ b/parseTestResults.py @@ -15,8 +15,8 @@ Usage python parseTestResults.py output.xml where output.xml is the xml file generated by robot - - + + The command outputs to a new xlslx file if it does not exist, or appends to an existing one. """ @@ -38,32 +38,46 @@ class TestOutputParser: def run_parser(self): soup = BeautifulSoup(self.contents, "lxml") + + # Suite information + suite = soup.find("suite") + path = suite["source"] + # TODO This might be an issue later on. In Unix-style paths the separator is a forward slash + parts = path.split("\\") + # Extract info for test entries + self.api = parts[len(parts) - 2] + self.robotFile = parts[len(parts) - 1] + + # Tests tests = soup.find_all("test") for test in tests: - self.testEntries.append(createTestEntry(test)) + self.testEntries.append(self.createTestEntry(test)) # Write tests ew = ExcelWriter() for entry in self.testEntries: ew.writeTestEntry(entry) ew.save() + + def createTestEntry(self, xmlObj): + """ + Takes the xml entry corresponding to the test from the output file, + and returns a TestEntry object with the relevant information extracted. + """ + # retrieve ID and name + idRaw = xmlObj.find("doc", recursive=False).contents + mg = re.search(r"Test ID: ([0-9\.]*)$", idRaw[0].string, re.MULTILINE) + testId = mg.group(1) + name = xmlObj["name"] + #retrieve status and error message (if FAIL) + statusObj = xmlObj.find("status", recursive=False) + cts = statusObj.contents + errorMsg = cts[0] if len(cts) > 0 else "" -def createTestEntry(xmlObj): - # retrieve ID and name - idRaw = xmlObj.find("doc", recursive=False).contents - mg = re.search(r"Test ID: ([0-9\.]*)$", idRaw[0].string, re.MULTILINE) - testId = mg.group(1) - name = xmlObj["name"] - - #retrieve status and error message (if FAIL) - statusObj = xmlObj.find("status", recursive=False) - cts = statusObj.contents - errorMsg = cts[0] if len(cts) > 0 else "" - - result = statusObj["status"] - return TestEntry(testId, name, result, errorMsg) - + result = statusObj["status"] + return TestEntry(testId, name, result, errorMsg, self.api, self.robotFile) + def display_usage(): print(usage_str) diff --git a/testEntry.py b/testEntry.py index 0b4b7f0495180c34bdddeeac02a7d08bc32a9597..6afbaefab6406b92d79fcadf88154d8b96fe0427 100644 --- a/testEntry.py +++ b/testEntry.py @@ -1,14 +1,16 @@ class TestEntry: - def __init__(self, id, name, result, errorMsg=""): + def __init__(self, id, name, result, errorMsg, api, robotFile): self.id = id self.name = name self.result = result self.errorMsg = errorMsg + self.api = api + self.robotFile = robotFile def __str__(self): baseStr = "[{}] {}:{}".format(self.id, self.name, self.result) if self.errorMsg != "": - return "{}: {}".format(baseStr, self.errorMsg) + return "{}: {} ({}/{})".format(baseStr, self.errorMsg, self.api, self.robotFile) else: return baseStr @@ -16,4 +18,4 @@ class TestEntry: return "{}: {}".format(self.name, self.result) def asList(self): - return [self.id, self.name, self.result, self.errorMsg] \ No newline at end of file + return [self.id, self.name, self.result, self.errorMsg, self.api, self.robotFile] \ No newline at end of file diff --git a/writeExcel.py b/writeExcel.py index 39266396d3409d95f1e80904a881bd8d07fda3fc..b4fbd03d60e3271a314e3234047d82bba8eb5143 100644 --- a/writeExcel.py +++ b/writeExcel.py @@ -16,6 +16,13 @@ class ExcelWriter: self.wb = getWorkbook() self.ws = self.wb.active + def getEntryWithId(self, id): + """ + When inserting an entry, it might be a test being re-run. In that case, + the row containing that test needs to be updated, as opposed to appending + the entry to the end of the file. + """ + def getLastRow(self): for cell in self.ws["A"]: if cell.value is None: @@ -25,7 +32,8 @@ class ExcelWriter: def writeTestEntry(self, testEntry): lastRow = self.getLastRow() cellCol = ExcelWriter.PASS_COL if testEntry.result == "PASS" else ExcelWriter.FAIL_COL - for col, cellValue in zip(self.ws.iter_cols(min_row=lastRow, max_col=4, max_row=lastRow), testEntry.asList()): + entryVals = testEntry.asList() + for col, cellValue in zip(self.ws.iter_cols(min_row=lastRow, max_col=len(entryVals), max_row=lastRow), entryVals): for cell in col: cell.value = cellValue cell.fill = PatternFill("solid", fgColor=cellCol)# cellCol @@ -37,10 +45,10 @@ def initWorkbook(wb): """ Writes column headers to ws """ - headers = [("Test ID", 10), ("Test name", 80), ("Result", 6), ("Error Message", 100)] + headers = [("Test ID", 10), ("Test name", 80), ("Result", 6), ("Error Message", 100), ("NFV API", 25), ("Robot Test File", 25)] headerFont = Font(bold=True) ws = wb.active - for col, header in zip(ws.iter_cols(min_row=1, max_col=4, max_row=1), headers): + for col, header in zip(ws.iter_cols(min_row=1, max_col=len(headers), max_row=1), headers): for cell in col: headerName = header[0] colsize = header[1]