How to use indent_paragraph method in Playwright Python

Best Python code snippet using playwright-python

documentation_provider.py

Source:documentation_provider.py Github

copy

Full Screen

...156 code_type = self.serialize_python_type(value)157 print(f"{indent}{to_snake_case(original_name)} : {code_type}")158 if doc_value.get("comment"):159 print(160 f"{indent} {self.indent_paragraph(self.render_links(doc_value['comment']), f'{indent} ')}"161 )162 self.compare_types(code_type, doc_value, f"{fqname}({name}=)", "in")163 if (164 signature165 and "return" in signature166 and str(signature["return"]) != "<class 'NoneType'>"167 ):168 value = signature["return"]169 doc_value = method170 self.compare_types(value, doc_value, f"{fqname}(return=)", "out")171 print("")172 print(" Returns")173 print(" -------")174 print(f" {self.serialize_python_type(value)}")175 print(f'{indent}"""')176 for name in args:177 if args[name].get("deprecated"):178 continue179 self.errors.add(180 f"Parameter not implemented: {class_name}.{method_name}({name}=)"181 )182 def indent_paragraph(self, p: str, indent: str) -> str:183 lines = p.split("\n")184 result = [lines[0]]185 for line in lines[1:]:186 result.append(indent + line)187 return "\n".join(result)188 def beautify_method_comment(self, comment: str, indent: str) -> str:189 comment = comment.replace("\\", "\\\\")190 comment = comment.replace('"', '\\"')191 lines = comment.split("\n")192 result = []193 skip_example = False194 last_was_blank = True195 for line in lines:196 if not line.strip():197 last_was_blank = True198 continue199 match = re.match(r"\s*```(.+)", line)200 if match:201 lang = match[1]202 if lang in ["html", "yml", "sh", "py", "python"]:203 skip_example = False204 elif lang == "python " + ("async" if self.is_async else "sync"):205 skip_example = False206 line = "```py"207 else:208 skip_example = True209 if not skip_example:210 if last_was_blank:211 last_was_blank = False212 result.append("")213 result.append(self.render_links(line))214 if skip_example and line.strip() == "```":215 skip_example = False216 return self.indent_paragraph("\n".join(result), indent)217 def render_links(self, comment: str) -> str:218 for [old, new] in self.links.items():219 comment = comment.replace(old, new)220 return comment221 def make_optional(self, text: str) -> str:222 if text.startswith("Union["):223 if text.endswith("NoneType]"):224 return text225 return text[:-1] + ", NoneType]"226 return f"Union[{text}, NoneType]"227 def compare_types(228 self, value: Any, doc_value: Any, fqname: str, direction: str229 ) -> None:230 if "(arg=)" in fqname or "(pageFunction=)" in fqname:...

Full Screen

Full Screen

miscs.py

Source:miscs.py Github

copy

Full Screen

...6from django.core.cache import cache7from django.http import JsonResponse, HttpResponse8from django.views.decorators.cache import cache_page9from hanziconv import HanziConv10def indent_paragraph(para):11 return para.replace('<br />', '</p><p>').replace('<p>', '<p>\u3000\u3000')12@cache_page(timeout=60 * 60 * 24)13def dazuoshou(request):14 feed = {15 'version': 'https://jsonfeed.org/version/1',16 'title': '大作手通知',17 'description': '大作手网站通知RSS',18 'home_page_url': 'http://www.dazuoshou.com.cn',19 'items': []20 }21 ann_link = 'http://www.dazuoshou.com.cn/ann/'22 lists = BeautifulSoup(requests.get(ann_link).content, 'html.parser').find_all('li', class_='clearfix')23 for x in lists:24 a = x.find('a')25 url = ann_link + a['href']26 if cache.get(url):27 feed['items'].append(cache.get(url))28 else:29 date = x.find('span').text30 title = date + ' ' + a.text31 b = BeautifulSoup(requests.get(url).content, 'html.parser')32 description = str(b.find('div', class_='content'))33 item = {34 'id': url,35 'url': url,36 'title': title,37 'content_html': description38 }39 cache.set(url, item)40 feed['items'].append(item)41 return JsonResponse(feed)42def fangeqiang(request):43 # feedjson标准 https://jsonfeed.org/version/144 feed = {45 'version': 'https://jsonfeed.org/version/1',46 'title': '翻个墙SSR更新通知',47 'description': '翻个墙SSR更新通知',48 'home_page_url': 'https://fangeqiang.com/408.html',49 'items': []50 }51 b = BeautifulSoup(requests.get(feed['home_page_url']).content, 'html.parser')52 controls = b.find_all('div', class_='xControl')53 if controls:54 for c in controls:55 if 'ssr' in c.a.text.lower():56 pt = c.find_next('pre', class_='prettyprint')57 urls = [x for x in pt.text.split() if 'ssr://' in x]58 description = '<a href="{ssrurl}">{ssrurl}</a><br/><br/><img src="{imgurl}"/>'.format(ssrurl=urls[0], imgurl=urls[1])59 title = c.a.text.strip()60 feed['items'].append({61 'id': title,62 'title': title,63 'content_html': description64 })65 return JsonResponse(feed)66# 墙外楼去广告67@cache_page(timeout=60 * 60 * 3)68def letscorp(request):69 letscorp_feed_url = 'http://feeds.feedburner.com/letscorp/aDmw?format=xml'70 b = BeautifulSoup(requests.get(letscorp_feed_url).content, 'xml')71 feed = {72 'version': 'https://jsonfeed.org/version/1',73 'title': b.rss.channel.title.text,74 'description': b.rss.channel.description.text,75 'home_page_url': b.rss.channel.link.text,76 'items': []77 }78 for item in b.find_all('item'):79 post_url = item.guid.text80 post_title = item.title.text81 post_date = rfc3339.rfc3339(parser.parse(item.pubDate.text))82 dit = {83 'id': post_url,84 'title': HanziConv.toSimplified(post_title),85 'url': post_url,86 'date_published': post_date87 }88 if not cache.get(post_url):89 content = item.find('content:encoded').text90 # 去广告91 ad1 = content.find('<span>镜像链接:</span>')92 if ad1 != -1:93 content = content[:ad1]94 bs = BeautifulSoup(content, 'html.parser')95 # 所有在href属性包含在ads_href_list的超链接会被删掉96 ads_href_list = ['amazon.com/gp',97 'chrome.google.com/webstore']98 all_ads_link = bs.find_all(lambda tag: tag.name == 'a' and (tag.has_attr('href') and any(x in tag.get('href') for x in ads_href_list)))99 if all_ads_link:100 for link in all_ads_link:101 link.decompose()102 # 删除分享图片103 feedflare = bs.find('div', class_='feedflare')104 if feedflare:105 feedflare.decompose()106 # 删除广告图片107 ads_keywords = ['letscorp/aDmw']108 ads_images = bs.find_all(lambda tag: tag.name == 'img' and (tag.has_attr('src') and any(x in tag.get('src') for x in ads_keywords)))109 if ads_images:110 for image in ads_images:111 image.decompose()112 # 删除相关日志113 rpt = bs.find('h2', class_='related_post_title')114 if rpt:115 rpt.decompose()116 rp = bs.find('ul', class_='related_post')117 if rp:118 rp.decompose()119 content = str(bs)120 # 换行变分段121 content = content.replace('<br />', '</p><p>')122 # 段落缩进123 content = re.sub(r'<p>(\n)?\u3000*', '<p>\u3000\u3000', content)124 # 繁体转简体125 content = HanziConv.toSimplified(content)126 dit['content_html'] = content127 feed['items'].append(dit)128 cache.set(post_url, content)129 else:130 dit['content_html'] = cache.get(post_url)131 feed['items'].append(dit)132 return JsonResponse(feed)133# 联合早报,用了feedx.net的订阅源134@cache_page(timeout=60 * 60 * 12)135def zaobaotoday(request):136 zaobao_feed_url = 'https://feedx.net/rss/zaobaotoday.xml'137 b = BeautifulSoup(requests.get(zaobao_feed_url).content, 'xml')138 item_list = []139 for item in b.find_all('item'):140 # 去重141 if item.title.text not in item_list:142 item_list.append(item.title.text)143 # 段落缩进144 dt = indent_paragraph(item.description.text)145 # 去掉广告及推荐146 pos = dt.find('<div class="tagcloud">')147 if pos != -1:148 dt = dt[:pos]149 pos = dt.find('获取更多RSS:')150 if pos != -1:151 dt = dt[:pos]152 dt = dt.replace('<hr>','')153 item.description.string.replace_with(dt)154 else:155 item.extract()156 return HttpResponse(str(b), content_type='application/xml')157# 自由亚洲国内新闻158def rfa_mandarin(request):159 feed_url = 'https://www.rfa.org/mandarin/yataibaodao/rss2.xml'160 b = BeautifulSoup(requests.get(feed_url).content, 'html.parser')161 response_str = indent_paragraph(str(b))...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful