def concateHTMLandCSS(): path = constant.config['logDir'] htmlFilePath = path + '/result.html' styleFile = path + '/assets/style.css' outputFile = path + '/output.html' soup = bs4.BeautifulSoup(open(htmlFilePath).read(), "lxml") stylesheets = soup.findAll("link", {"rel": "stylesheet"}) for s in stylesheets: t = soup.new_tag('style') c = bs4.element.NavigableString(open(styleFile).read()) t.insert(0, c) t['type'] = 'text/css' s.replaceWith(t) open(outputFile, "w").write(str(soup).replace(''', '')) Logger.logCollectorRequest(outputFile, 'files')
def getScreenshot(self, message): fileName = message + ".png" screenshotLocation = "../screenshots/" relativeFileName = screenshotLocation + fileName currentLocation = os.path.dirname(__file__) destinationFileName = constant.config['logDir'] + '/' + fileName destinationLocation = constant.config['logDir'] + '/assets' try: if not os.path.exists(destinationLocation): os.makedirs(destinationLocation) self.driver.save_screenshot(destinationFileName) Logger.logCollectorRequest(destinationFileName, 'files') # Logger.log("Screenshot saved to directory " + destinationFileName) except: Logger.log(traceback.format_exc())
def pytest_runtest_makereport(item, call): outcome = yield rep = outcome.get_result() if rep.when == 'call' or (rep.when == 'setup' and rep.outcome in ['failed', 'skipped']): classRunning = str(rep).split('::')[1] testCaseName = str(rep).split('::')[-1].split( 'when')[0].rstrip().replace("'", '') status = rep.outcome timeTaken = rep.duration executionInfo = call.excinfo screenshot = '' if status == 'failed': path = constant.config['logDir'] + '/' + str( testCaseName) + '.png' if os.path.exists(path): screenshot = str(testCaseName) + '.png' if executionInfo is None: executionInfo = '' else: executionInfo = str(executionInfo) if constant.config['validataionMessage'] != []: #executionInfo += '\n'.join(set(constant.config['validataionMessage'])) executionInfo = str(executionInfo) resultDict = { classRunning: { testCaseName: { 'status': status, 'time': str(timeTaken), 'validataionMessage': executionInfo, 'screenshot': screenshot, 'comments': '' } } } Logger.logCollectorRequest(resultDict, 'result') setattr(item, "rep_" + rep.when, rep)