Best Python code snippet using pytest-mozwebqa_python
saucelabs.py
Source:saucelabs.py
...60 desired_capabilities=capabilities)61 def url(self, session):62 return 'http://saucelabs.com/jobs/%s' % session63 def additional_html(self, session):64 return [self._video_html(session)]65 def update_status(self, session, passed):66 status = {'passed': passed}67 requests.put('http://saucelabs.com//rest/v1/%s/jobs/%s' % (self.username, session),68 data=json.dumps(status), auth=(self.username, self.api_key))69 def _video_html(self, session):70 flash_vars = 'config={\71 "clip":{\72 "url":"https://assets.saucelabs.com/jobs/%(session)s/video.flv",\73 "provider":"streamer",\74 "autoPlay":false,\75 "autoBuffering":true},\76 "play": {\77 "opacity":1,\78 "label":null,\79 "replayLabel":null},\80 "plugins":{\81 "streamer":{\82 "url":"https://cdn1.saucelabs.com/sauce_skin_deprecated/lib/flowplayer/flowplayer.pseudostreaming-3.2.13.swf",\83 "queryString":"%%3Fstart%%3D%%24%%7Bstart%%7D"},\...
testingbot.py
Source:testingbot.py
...38 auth_url = get_auth_url(39 "https://testingbot.com/tests/{}.mp4".format(session_id), provider, session_id40 )41 pytest_html = item.config.pluginmanager.getplugin("html")42 extra.append(pytest_html.extras.html(_video_html(auth_url, session_id)))43@pytest.mark.optionalhook44def pytest_selenium_runtest_makereport(item, report, summary, extra):45 provider = TestingBot()46 if not provider.uses_driver(item.config.getoption("driver")):47 return48 passed = report.passed or (report.failed and hasattr(report, "wasxfail"))49 session_id = item._driver.session_id50 # Add the job URL to the summary51 job_url = provider.JOB.format(session=session_id)52 summary.append("{0} Job: {1}".format(provider.name, job_url))53 pytest_html = item.config.pluginmanager.getplugin("html")54 # Add the job URL to the HTML report55 extra.append(pytest_html.extras.url(job_url, "{0} Job".format(provider.name)))56 try:57 # Update the job result58 api_url = provider.API.format(session=session_id)59 job_info = requests.get(api_url, auth=provider.auth, timeout=10).json()60 if report.when == "setup" or job_info.get("success") is not False:61 # Only update the result if it's not already marked as failed62 data = {"test[success]": "1" if passed else "0"}63 requests.put(api_url, data=data, auth=provider.auth, timeout=10)64 except Exception as e:65 summary.append(66 "WARNING: Failed to update {0} job status: {1}".format(provider.name, e)67 )68def driver_kwargs(request, test, capabilities, host, port, **kwargs):69 provider = TestingBot(host, port)70 capabilities.setdefault("name", test)71 capabilities.setdefault("client_key", provider.key)72 capabilities.setdefault("client_secret", provider.secret)73 markers = [x.name for x in request.node.iter_markers()]74 groups = capabilities.get("groups", []) + markers75 if groups:76 capabilities["groups"] = groups77 kwargs = {78 "command_executor": provider.executor,79 "desired_capabilities": capabilities,80 }81 return kwargs82def _video_html(video_url, session):83 return str(84 html.div(85 html.video(86 html.source(src=video_url, type="video/mp4"),87 width="100%",88 height="100%",89 controls="controls",90 ),91 id="mediaplayer{session}".format(session=session),92 style="border:1px solid #e6e6e6; float:right; height:240px;"93 "margin-left:5px; overflow:hidden; width:320px",94 )95 )96def get_auth_url(url, provider, session_id):...
crossbrowsertesting.py
Source:crossbrowsertesting.py
...38 .get("videos")39 )40 if videos and len(videos) > 0:41 pytest_html = item.config.pluginmanager.getplugin("html")42 extra.append(pytest_html.extras.html(_video_html(videos[0])))43@pytest.mark.optionalhook44def pytest_selenium_runtest_makereport(item, report, summary, extra):45 provider = CrossBrowserTesting()46 if not provider.uses_driver(item.config.getoption("driver")):47 return48 passed = report.passed or (report.failed and hasattr(report, "wasxfail"))49 # Add the test URL to the summary50 info = requests.get(51 provider.API.format(session=item._driver.session_id),52 auth=provider.auth,53 timeout=10,54 ).json()55 url = info.get("show_result_public_url")56 summary.append("{0}: {1}".format(provider.name, url))57 pytest_html = item.config.pluginmanager.getplugin("html")58 # Add the job URL to the HTML report59 extra.append(pytest_html.extras.url(url, provider.name))60 try:61 # Update the test result62 if report.when == "setup" or info.get("test_score") != "fail":63 # Only update the result if it's not already marked as failed64 score = "pass" if passed else "fail"65 data = {"action": "set_score", "score": score}66 r = requests.put(67 provider.API.format(session=info.get("selenium_test_id")),68 data=data,69 auth=provider.auth,70 timeout=10,71 )72 r.raise_for_status()73 except Exception as e:74 summary.append(75 "WARNING: Failed to update {0} job status: {1}".format(provider.name, e)76 )77def driver_kwargs(request, test, capabilities, **kwargs):78 provider = CrossBrowserTesting()79 capabilities.setdefault("name", test)80 capabilities.setdefault("username", provider.username)81 capabilities.setdefault("password", provider.key)82 kwargs = {83 "command_executor": provider.executor,84 "desired_capabilities": capabilities,85 }86 return kwargs87def _video_html(video):88 html.__tagspec__.update(dict([(x, 1) for x in ("video", "source")]))89 video_attrs = {90 "controls": "",91 "poster": video.get("image"),92 "play-pause-on-click": "",93 "style": "border:1px solid #e6e6e6; float:right; height:240px; "94 "margin-left:5px; overflow:hidden; width:320px",95 }96 source_attrs = {"src": video.get("video"), "type": "video/mp4"}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!