Browse Source

New activties "Submit". Change TestcaseStatus if broken link happened

bernhardbuhl 4 years ago
parent
commit
666d17c80a

+ 13 - 2
baangt/TestSteps/TestStepMaster.py

@@ -118,6 +118,8 @@ class TestStepMaster:
                 self.apiSession.setHeaders(setHeaderData=lValue)
             elif lActivity == 'SAVE':
                 self.doSaveData(lValue, lValue2)
+            elif lActivity == 'SUBMIT':
+                self.browserSession.submit()
             elif lActivity == "ADDRESS_CREATE":
                 # Create Address with option lValue and lValue2
                 AddressCreate(lValue,lValue2)
@@ -156,11 +158,20 @@ class TestStepMaster:
         Will check all links on the current webpage
 
         Result will be written into "CheckedLinks" in TestDataDict
+
+        If theres a returncode >= 400 in the list, we'll mark the testcase as failed
         """
         if self.testcaseDataDict.get("CheckedLinks"):
-            self.testcaseDataDict["CheckedLinks"] += self.browserSession.checkLinks()
+            self.testcaseDataDict["Result_CheckedLinks"] += self.browserSession.checkLinks()
         else:
-            self.testcaseDataDict["CheckedLinks"] = self.browserSession.checkLinks()
+            self.testcaseDataDict["Result_CheckedLinks"] = self.browserSession.checkLinks()
+
+        for entry in self.testcaseDataDict["Result_CheckedLinks"]:
+            if entry[0] > 400:
+                self.testcaseDataDict[GC.TESTCASESTATUS] = GC.TESTCASESTATUS_ERROR
+                self.testcaseDataDict[GC.TESTCASEERRORLOG] = self.testcaseDataDict.get(GC.TESTCASEERRORLOG,"")\
+                                                             + "URL-Checker error"
+                break
 
     @staticmethod
     def _sanitizeXField(inField):

+ 16 - 3
baangt/base/ExportResults/ExportResults.py

@@ -261,16 +261,24 @@ class ExportResults:
         """
         Fields, that start with "RESULT_" shall always be exported.
 
+        Other fields, that shall always be exported are also added
+
         @return:
         """
+
         try:
             for key in self.dataRecords[0].keys():
-                if "RESULT_" in key:
+                if "RESULT_" in key.upper():
                     if not key in self.fieldListExport:
                         self.fieldListExport.append(key)
+
         except Exception as e:
             logger.critical(f'looks like we have no data in records: {self.dataRecords}, len of dataRecords: {len(self.dataRecords)}')
 
+        # They are added here, because they'll not necessarily appear in the first record of the export data:
+        self.fieldListExport.append(GC.TESTCASEERRORLOG)
+        self.fieldListExport.append(GC.SCREENSHOTS)
+
     def _exportData(self):
         for key, value in self.dataRecords.items():
             for (n, column) in enumerate(self.fieldListExport):
@@ -287,10 +295,15 @@ class ExportResults:
 
     def __writeCell(self, line, cellNumber, testRecordDict, fieldName, strip=False):
         if fieldName in testRecordDict.keys() and testRecordDict[fieldName]:
+            # Remove leading New-Line:
             if '\n' in testRecordDict[fieldName][0:5] or strip:
                 testRecordDict[fieldName] = testRecordDict[fieldName].strip()
-            if isinstance(testRecordDict[fieldName], dict) or isinstance(testRecordDict[fieldName], list):
-                self.worksheet.write(line, cellNumber, testRecordDict[fieldName].strip())
+            # Do different stuff for Dicts and Lists:
+            if isinstance(testRecordDict[fieldName], dict):
+                self.worksheet.write(line, cellNumber, testRecordDict[fieldName])
+            elif isinstance(testRecordDict[fieldName], list):
+                self.worksheet.write(line, cellNumber,
+                                     utils.listToString(testRecordDict[fieldName]))
             else:
                 if fieldName == GC.TESTCASESTATUS:
                     if testRecordDict[GC.TESTCASESTATUS] == GC.TESTCASESTATUS_SUCCESS:

+ 2 - 1
baangt/base/HandleDatabase.py

@@ -120,12 +120,13 @@ class HandleDatabase:
         try:
             # the topmost record of the RangeDict (RangeDict was built by the range(s) from the TestRun
             # - 1 because there's a header line in the Excel-Sheet.
-            lRecord = self.dataDict[(list(self.rangeDict.keys())[0])-1]
+            lRecord = self.dataDict[(list(self.rangeDict.keys())[0])]
         except Exception as e:
             logger.debug(f"Couldn't read record from database: {list(self.rangeDict.keys())[0]}")
             self.rangeDict.pop(list(self.rangeDict.keys())[0])
             return None
 
+        # Remove the topmost entry fro the rangeDict, so that next time we read the next entry in the lines above
         self.rangeDict.pop(list(self.rangeDict.keys())[0])
         return self.updateGlobals(lRecord)
 

+ 7 - 2
baangt/base/TestRun/TestRun.py

@@ -230,9 +230,14 @@ class TestRun:
 
         """
         self.testRunUtils.replaceGlobals(self.globalSettings)
+
+        kwargs = {GC.KWARGS_TESTRUNATTRIBUTES: self.getAllTestRunAttributes(),
+                  GC.KWARGS_TESTRUNINSTANCE: self,
+                  GC.KWARGS_TIMING: self.timing}
+
         self.executeDictSequenceOfClasses(
-            self.testRunUtils.getCompleteTestRunAttributes(self.testRunName)[GC.STRUCTURE_TESTCASESEQUENCE],
-            counterName=GC.STRUCTURE_TESTCASESEQUENCE)
+            kwargs[GC.KWARGS_TESTRUNATTRIBUTES][GC.STRUCTURE_TESTCASESEQUENCE],
+            counterName=GC.STRUCTURE_TESTCASESEQUENCE, **kwargs)
 
     def executeDictSequenceOfClasses(self, dictSequenceOfClasses, counterName, **kwargs):
         """

+ 30 - 0
baangt/base/Utils.py

@@ -88,6 +88,36 @@ class utils:
         return data
 
     @staticmethod
+    def listToString(completeList):
+        """
+        Returns a concatenated string from a list-object
+        :param completeList: any List
+        :return: String
+        """
+        if len(completeList) > 0:
+            returnString = utils.__listChildToString(completeList)
+
+        returnString = returnString.lstrip("\n")
+        return returnString
+
+    @staticmethod
+    def __listChildToString(listEntry):
+        """
+        Recursively going through a dict and transforming each layer into a string.
+        :param listEntry:
+        :return:
+        """
+        returnString = ""
+        for entry in listEntry:
+            if isinstance(entry, list):
+                returnString = f"{returnString}\n{utils.__listChildToString(entry)}"
+            else:
+                returnString = f"{returnString}, {entry}"
+
+        returnString = returnString.lstrip(", ")
+        return returnString
+
+    @staticmethod
     def findFileAndPathFromPath(fileNameAndPath, basePath=None):
         """
         Tries different approaches to locate a file