How to use print_args method in Playwright Python

Best Python code snippet using playwright-python

logger.py

Source:logger.py Github

copy

Full Screen

1import json2from typing import Any, Optional, Union3from yutto.utils.console.colorful import Color, Style, colored_string4from yutto.utils.console.formatter import get_string_width5from yutto.utils.console.status_bar import StatusBar6_logger_debug: bool = False7def set_logger_debug():8 global _logger_debug9 _logger_debug = True10class Badge:11 def __init__(12 self,13 text: str = "CUSTOM",14 fore: Optional[Color] = None,15 back: Optional[Color] = None,16 style: Optional[list[Style]] = None,17 ):18 self.text: str = text19 self.fore: Optional[Color] = fore20 self.back: Optional[Color] = back21 self.style: Optional[list[Style]] = style22 def __str__(self):23 return colored_string(" {} ".format(self.text), fore=self.fore, back=self.back, style=self.style)24 def __repr__(self):25 return str(self)26 def __len__(self):27 return get_string_width(str(self))28 def __add__(self, other: str) -> str:29 return str(self) + other30WARNING_BADGE = Badge("WARN", fore="yellow")31ERROR_BADGE = Badge("ERROR", fore="red", style=["bold"])32INFO_BADGE = Badge("INFO", fore="bright_blue")33DEPRECATED_BADGE = Badge("DEPRECATED", fore="black", back="yellow")34DEBUG_BADGE = Badge("DEBUG", fore="green")35class Logger:36 status = StatusBar37 @classmethod38 def enable_statusbar(cls):39 # StatusBar 为整个 log 模块中唯一有刷新能力的部分,如果禁用(不启用)可以保证 log 的可读性40 cls.status.enable()41 cls.status.set_snippers(42 [43 "( ´・ω・)",44 "( ´・ω)",45 "(  ´・)",46 "(   ´)",47 "( )",48 "(`  )",49 "(・` )",50 "(ω・` )",51 "(・ω・` )",52 "(´・ω・`)",53 ]54 )55 @classmethod56 def custom(cls, string: Any, badge: Badge, *print_args: Any, **print_kwargs: Any):57 prefix = badge + " "58 cls.status.clear()59 print(prefix + str(string), *print_args, **print_kwargs)60 cls.status.next_tick()61 @classmethod62 def warning(cls, string: Any, *print_args: Any, **print_kwargs: Any):63 Logger.custom(string, WARNING_BADGE, *print_args, **print_kwargs)64 @classmethod65 def error(cls, string: Any, *print_args: Any, **print_kwargs: Any):66 Logger.custom(string, ERROR_BADGE, *print_args, **print_kwargs)67 @classmethod68 def info(cls, string: Any, *print_args: Any, **print_kwargs: Any):69 Logger.custom(string, INFO_BADGE, *print_args, **print_kwargs)70 @classmethod71 def deprecated_warning(cls, string: Any, *print_args: Any, **print_kwargs: Any):72 Logger.custom(string, DEPRECATED_BADGE, *print_args, **print_kwargs)73 @classmethod74 def debug(cls, string: Any, *print_args: Any, **print_kwargs: Any):75 if not _logger_debug:76 return77 Logger.custom(string, DEBUG_BADGE, *print_args, **print_kwargs)78 @classmethod79 def custom_multiline(cls, string: Any, badge: Badge, *print_args: Any, **print_kwargs: Any):80 prefix = badge + " "81 lines = string.split("\n")82 multiline_string = prefix + "\n".join(83 [((" " * get_string_width(prefix)) if i != 0 else "") + line for i, line in enumerate(lines)]84 )85 print(multiline_string, *print_args, **print_kwargs)86 @classmethod87 def warning_multiline(cls, string: Any, *print_args: Any, **print_kwargs: Any):88 Logger.custom_multiline(string, WARNING_BADGE, *print_args, **print_kwargs)89 @classmethod90 def error_multiline(cls, string: Any, *print_args: Any, **print_kwargs: Any):91 Logger.custom_multiline(string, ERROR_BADGE, *print_args, **print_kwargs)92 @classmethod93 def info_multiline(cls, string: Any, *print_args: Any, **print_kwargs: Any):94 Logger.custom_multiline(string, INFO_BADGE, *print_args, **print_kwargs)95 @classmethod96 def deprecated_warning_multiline(cls, string: Any, *print_args: Any, **print_kwargs: Any):97 Logger.custom_multiline(string, DEPRECATED_BADGE, *print_args, **print_kwargs)98 @classmethod99 def debug_multiline(cls, string: Any, *print_args: Any, **print_kwargs: Any):100 if not _logger_debug:101 return102 Logger.custom_multiline(string, INFO_BADGE, *print_args, **print_kwargs)103 @classmethod104 def print(cls, string: Any, *print_args: Any, **print_kwargs: Any):105 cls.status.clear()106 print(string, *print_args, **print_kwargs)107 @classmethod108 def json(cls, obj: Union[list[Any], dict[str, Any]], *print_args: Any, **print_kwargs: Any):109 Logger.print(json.dumps(obj, indent=2), *print_args, **print_kwargs)110 @classmethod111 def new_line(cls):112 cls.print("")113 @classmethod114 def is_debug(cls) -> bool:...

Full Screen

Full Screen

ex19-studydrills.py

Source:ex19-studydrills.py Github

copy

Full Screen

...70print("And we can combine the two, variables and math:")71# Call the function, with two expression that consists of variables72# and math as the actual parameters73cheese_and_crackers(amount_of_cheese + 100, amount_of_cheese + 1000)74def print_args(*argv):75 size = len(argv)76 print(size)77 print("Hello! Welcome to use %r!" % argv[0])78 if size > 1:79 for i in range(1, size):80 print("The param %d is %r" % (i, argv[i]))81 return 082 return -183# 1. use numbers as actual parameters84print_args(10, 20, 30)85# 2. use string and numbers as actual parameters86print_args("print_args", 10, 20)87# 3. use strings as actual parameters88print_args("print_args", "Joseph", "Pan")89# 4. use variables as actual parameters90first_name = "Joseph"91last_name = "Pan"92print_args("print_args", first_name, last_name)93# 5. contain math expressions94print_args("print_args", 5*4, 2.0/5)95# 6. more complicated calculations96print_args("print_args", '.'*10, '>'*3)97# 7. more parameters98print_args("print_args", 10, 20, 30, 40, 50)99# 8. tuples as parameters100nums1 = (10, 20, 30)101nums2 = (40, 50, 60)102print_args("print_args", nums1, nums2)103# 9. more complicated types104nums3 = [70, 80, 90]105set1 = {"apple", "banana", "orange"}106dict1 = {'id': '0001', 'name': first_name+" "+last_name}107str1 = "Wow, so complicated!"108print_args("print args", nums1, nums2, nums3, set1, dict1, str1)109# 10. function as parameter and with return values110if print_args(cheese_and_crackers, print_args) != -1:...

Full Screen

Full Screen

可变参数.py

Source:可变参数.py Github

copy

Full Screen

...29# print_score(name='cb',**sum_score) # 正确30print_score('cb',**sum_score) # 不提供关键字参数也可31# print_score('cb',**sum_score,a=1) # 会输出cb的a成绩为1,这说明a=1与**sum_score合并了,并覆盖了第1个字典元素32#%%33def print_args(a,b,*c,**d):34 print(a,b,c,d)35# print_args(1,2) # 1 2 () {}36# print_args(1,2,3) # 1 2 (3,) {} 不使用关键字参数,按顺序给定37# print_args(1,2,3,4,5) # 1 2 (3, 4, 5) {} 如果传入的不是关键字参数,解包时在满足必须参数后全部给*c参数38# print_args(1,2,3,4,5,c=6,d=7) # 1 2 (3, 4, 5) {'c': 6, 'd': 7} 关键字参数都给**d参数39# print_args(x=1,y=2) # 提示确实必须参数 a,b40# print_args(a=1,b=2) # 1 2 () {} # 使用关键字参数,按顺序给定41# print_args(a=1,b=2,3) # 提示位置参数只允许关键字参数42# print_args(a=1,b=2,c=3) # 然而c=3不作为元组参数,还是作为字典参数43# print_args(a=1,b=2,c=(3,4,5)) # 1 2 () {'c': (3, 4, 5)} 这里c=(3,4,5)仍然作为字典参数不作为元组参数44# print_args(1,2,*[3,4]) # 1 2 (3, 4) {} 不使用关键字参数 列表可以拆包45# print_args(a=1,b=2,*[3,4]) # 提示a有多个值46print_args(1,2,*[3,4]) # 故*变量名 能够传递的前提是前边不能有关键字参数4748# 全局参数和局部参数49name = 'cb'50list = [1,2,3]51def loc_args():52 name = 153 print(name)54def global_args():55 #name = name + '1997' # 全局变量不允许直接修改56 global name57 name = name + '1997' # 不可变对象事先声明后可以修改全局变量58 print(name)59 list.append(4) # 对于可变对象可以不声明直接修改60loc_args() # 局部变量 ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import pyb, sensor, image, time, math2enable_lens_corr = False # turn on for straighter lines...3sensor.reset()4sensor.set_pixformat(sensor.RGB565) # grayscale is faster5sensor.set_framesize(sensor.QQVGA)6sensor.skip_frames(time = 2000)7sensor.set_auto_gain(False) # must turn this off to prevent image washout...8sensor.set_auto_whitebal(False) # must turn this off to prevent image washout...9clock = time.clock()10f_x = (2.8 / 3.984) * 160 # find_apriltags defaults to this if not set11f_y = (2.8 / 2.952) * 120 # find_apriltags defaults to this if not set12c_x = 160 * 0.5 # find_apriltags defaults to this if not set (the image.w * 0.5)13c_y = 120 * 0.5 # find_apriltags defaults to this if not set (the image.h * 0.5)14def degrees(radians):15 return (180 * radians) / math.pi16# All lines also have `x1()`, `y1()`, `x2()`, and `y2()` methods to get their end-points17# and a `line()` method to get all the above as one 4 value tuple for `draw_line()`.18uart = pyb.UART(3,9600,timeout_char=1000)19uart.init(9600,bits=8,parity = None, stop=1, timeout_char=1000)20while(True):21 clock.tick()22 # for 2.8mm lens...23 # `merge_distance` controls the merging of nearby lines. At 0 (the default), no24 # merging is done. At 1, any line 1 pixel away from another is merged... and so25 # on as you increase this value. You may wish to merge lines as line segment26 # detection produces a lot of line segment results.27 # `max_theta_diff` controls the maximum amount of rotation difference between28 # any two lines about to be merged. The default setting allows for 15 degrees. 10,15,29 img = sensor.snapshot()30 if enable_lens_corr: img.lens_corr(1.8)31 for l in img.find_line_segments(merge_distance = 20, max_theta_diff = 15):32 #if l[1] < 20 and l[3] < 40 and ((int(l[6])<60 or int(l[6])>120)) and l[0]< 120 and l[0]>40:33 if l.x1() > 40 and l.x1() < 120 and l.y1() < 3 and l.magnitude() > 5 and l.length() > 5 and ((int(l[6])<60 or int(l[6])>120)):34 if l[0]<60 and l[6]<90:35 print_args = ('r')36 elif l[6]>90 and l[0] >60:37 print_args = ('l')38 else:39 print_args = ('s')40 uart.write(("%c" % print_args).encode())41 time.sleep_ms(500)42 img.draw_line(l.line(), color = (255, 0, 0))43 #print(("%c" % print_args).encode())44 #uart.write(("%c" % print_args).encode())45 img = sensor.snapshot()46 for tag in img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y): # defaults to TAG36H1147 img.draw_rectangle(tag.rect(), color = (255, 0, 0))48 img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))49 # The conversion is nearly 6.2cm to 1 -> translation50 print_args = (tag.x_translation(), tag.y_translation(), tag.z_translation(), \51 degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation()))52 if tag.x_translation()>1:53 print_args = ('l')54 uart.write(("%c" % print_args).encode())55 #print(("%c" % print_args).encode())56 time.sleep_ms(500)57 if tag.x_translation()<-1:58 print_args = ('r')59 uart.write(("%c" % print_args).encode())60 #print(("%c" % print_args).encode())61 time.sleep_ms(500)62 #print(("%c" % print_args).encode())63 print(tag.z_translation())64 if tag.z_translation() > -6:65 print_args = ('c')66 uart.write(("%c" % print_args).encode())67 #print(("%c" % print_args).encode())68 time.sleep_ms(9000)69 '''else:70 print_args = ('a')71 uart.write(("%c" % print_args).encode())72 print(("%c" % print_args).encode())73 time.sleep_ms(500)'''74 #print(("%c" % print_args).encode())75 # Translation units are unknown. Rotation units are in degrees.76 #uart.write(("Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args).encode())77 #uart.write(("FPS %f\r\n" % clock.fps()).encode())78 #print_args = ('n')...

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