def selenium(mozwebqa, request): """A fixture giving the user more control over the mozwebqa selenium client Used as a context manager, and takes a fixture (or fixture name) and optional base_url as arguments, allowing navigation to any page on any appliance. Example usage: with selenium('cnf_about_pg') as pg: pg.do_stuff() To connect to another appliance, pass in a new base_url: with selenium('cnf_about_pg', 'https://10.11.12.13') as pg: pg.do_stuff() """ # Start to bootstrap the selenium client like mozwebqa does, # Doesn't currently support sauce labs, but could be made to do so if needed test_id = '.'.join(split_class_and_test_names(request.node.nodeid)) mozwebqa.selenium_client = Client(test_id, request.session.config.option) def cm_wrapper(fixture, base_url=None): return SeleniumContextManager(mozwebqa, fixture, base_url) return cm_wrapper
def selenium(mozwebqa, request): """A fixture giving the user more control over the mozwebqa selenium client""" # Start to bootstrap the selenium client like mozwebqa does, # Doesn't currently support sauce labs, but could be made to do so if needed test_id = '.'.join(split_class_and_test_names(request.node.nodeid)) mozwebqa.selenium_client = Client(test_id, request.session.config.option) def cm_wrapper(url, page_or_fixture): return SeleniumContextManager(mozwebqa, url, page_or_fixture) return cm_wrapper
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'))
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'): links['Sauce Labs Job'] = 'http://saucelabs.com/jobs/%s' % report.session_id links_html = [] for name, path in links.iteritems(): links_html.append(html.a(name, href=path)) links_html.append(' ') self.test_logs.append( html.tr(html.td(result, class_=result.lower()), html.td(testclass), html.td(testmethod), html.td(round(time)), html.td(*links_html), class_=result.lower())) if not 'Passed' in result: additional_html = [] if self.config.option.sauce_labs_credentials_file and hasattr(report, 'session_id'): flash_vars = 'config={\ "clip":{\ "url":"http%%3A//saucelabs.com/jobs/%(session_id)s/video.flv",\ "provider":"streamer",\ "autoPlay":false,\ "autoBuffering":true},\ "plugins":{\ "streamer":{\ "url":"http://saucelabs.com/flowplayer/flowplayer.pseudostreaming-3.2.5.swf"},\ "controls":{\ "mute":false,\ "volume":false,\ "backgroundColor":"rgba(0, 0, 0, 0.7)"}},\ "playerId":"player%(session_id)s",\ "playlist":[{\ "url":"http%%3A//saucelabs.com/jobs/%(session_id)s/video.flv",\ "provider":"streamer",\ "autoPlay":false,\ "autoBuffering":true}]}' % {'session_id': report.session_id} additional_html.append( html.div( html.object( html.param(value='true', name='allowfullscreen'), html.param(value='always', name='allowscriptaccess'), html.param(value='high', name='quality'), html.param(value='true', name='cachebusting'), html.param(value='#000000', name='bgcolor'), html.param(value=flash_vars.replace(' ', ''), name='flashvars'), width='100%', height='100%', type='application/x-shockwave-flash', data='http://saucelabs.com/flowplayer/flowplayer-3.2.5.swf?0.2566397726976729', name='player_api', id='player_api'), id='player%s' % report.session_id, class_='video')) 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(*additional_html, colspan='5')))