def pytest_runtest_makereport(__multicall__, item, call): report = __multicall__.execute() if report.when == 'call': report.session_id = getattr(item, 'session_id', None) if hasattr( TestSetup, 'selenium' ) and TestSetup.selenium and not 'skip_selenium' in item.keywords: if report.skipped and 'xfail' in report.keywords or report.failed and 'xfail' not in report.keywords: url = TestSetup.selenium_client.url url and item.debug['urls'].append(url) screenshot = TestSetup.selenium_client.screenshot screenshot and item.debug['screenshots'].append(screenshot) html = TestSetup.selenium_client.html html and item.debug['html'].append(html) log = TestSetup.selenium_client.log log and item.debug['logs'].append(log) report.sections.append( ('pytest-mozwebqa', _debug_summary(item.debug))) network_traffic = TestSetup.selenium_client.network_traffic network_traffic and item.debug['network_traffic'].append( network_traffic) report.debug = item.debug if hasattr(item, 'sauce_labs_credentials') and report.session_id: result = { 'passed': report.passed or (report.failed and 'xfail' in report.keywords) } import sauce_labs sauce_labs.Job(report.session_id).send_result( result, item.sauce_labs_credentials) return report
def _appendrow(self, result, report): import pytest_mozwebqa (testclass, testmethod) = pytest_mozwebqa.split_class_and_test_names(report.nodeid) time = getattr(report, 'duration', 0.0) links = {} if hasattr(report, 'debug') and any(report.debug.values()): (relative_path, full_path) = self._debug_paths(testclass, testmethod) if report.debug['screenshots']: filename = 'screenshot.png' f = open(os.path.join(full_path, filename), 'wb') f.write(base64.decodestring(report.debug['screenshots'][-1])) links.update({'Screenshot': os.path.join(relative_path, filename)}) if report.debug['html']: filename = 'html.txt' f = open(os.path.join(full_path, filename), 'wb') f.write(report.debug['html'][-1]) links.update({'HTML': os.path.join(relative_path, filename)}) # Log may contain passwords, etc so we only capture it for tests marked as public if report.debug['logs'] and 'public' in report.keywords: filename = 'log.txt' f = open(os.path.join(full_path, filename), 'wb') f.write(report.debug['logs'][-1]) links.update({'Log': os.path.join(relative_path, filename)}) if report.debug['network_traffic']: filename = 'networktraffic.json' f = open(os.path.join(full_path, filename), 'wb') f.write(report.debug['network_traffic'][-1]) links.update({'Network Traffic': os.path.join(relative_path, filename)}) if report.debug['urls']: links.update({'Failing URL': report.debug['urls'][-1]}) if self.config.option.sauce_labs_credentials_file and hasattr(report, 'session_id'): self.sauce_labs_job = sauce_labs.Job(report.session_id) if hasattr(self, 'sauce_labs_job'): links['Sauce Labs Job'] = self.sauce_labs_job.url links_html = [] for name, path in links.iteritems(): links_html.append(html.a(name, href=path)) links_html.append(' ') additional_html = [] if not 'Passed' in result: if hasattr(self, 'sauce_labs_job'): additional_html.append(self.sauce_labs_job.video_html) if 'Screenshot' in links: additional_html.append( html.div( html.a(html.img(src=links['Screenshot']), href=links['Screenshot']), class_='screenshot')) if report.longrepr: log = html.div(class_='log') for line in str(report.longrepr).splitlines(): separator = line.startswith('_ ' * 10) if separator: log.append(line[:80]) else: exception = line.startswith("E ") if exception: log.append(html.span(raw(cgi.escape(line)), class_='error')) else: log.append(raw(cgi.escape(line))) log.append(html.br()) additional_html.append(log) self.test_logs.append(html.tr([ html.td(result, class_='col-result'), html.td(testclass, class_='col-class'), html.td(testmethod, class_='col-name'), html.td(round(time), class_='col-duration'), html.td(links_html, class_='col-links'), html.td(additional_html, class_='debug')], class_=result.lower() + ' results-table-row'))