Best Python code snippet using playwright-python
logger.py
Source: logger.py
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:...
ex19-studydrills.py
Source: ex19-studydrills.py
...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:...
可变参数.py
Source: 可变参数.py
...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() # å±é¨åé
...
main.py
Source: main.py
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')...
Playwright error connection refused in docker
playwright-python advanced setup
How to select an input according to a parent sibling label
Error when installing Microsoft Playwright
Trouble waiting for changes to complete that are triggered by Python Playwright `select_option`
Capturing and Storing Request Data Using Playwright for Python
Can Playwright be used to launch a browser instance
Trouble in Clicking on Log in Google Button of Pop Up Menu Playwright Python
Scrapy Playwright get date by clicking button
React locator example
I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application. My application is running locally on http. Chromium and geko drivers force httpS connection for some domain names one of which is "app". So i have to change name for my docker container wich contains frontend application.
Check out the latest blogs from LambdaTest on this topic:
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
When it comes to web automation testing, there are a number of frameworks like Selenium, Cypress, PlayWright, Puppeteer, etc., that make it to the ‘preferred list’ of frameworks. The choice of test automation framework depends on a range of parameters like type, complexity, scale, along with the framework expertise available within the team. However, it’s no surprise that Selenium is still the most preferred framework among developers and QAs.
Playwright is a framework that I’ve always heard great things about but never had a chance to pick up until earlier this year. And since then, it’s become one of my favorite test automation frameworks to use when building a new automation project. It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks I’ve worked with.
The speed at which tests are executed and the “dearth of smartness” in testing are the two major problems developers and testers encounter.
With the rapidly evolving technology due to its ever-increasing demand in today’s world, Digital Security has become a major concern for the Software Industry. There are various ways through which Digital Security can be achieved, Captcha being one of them.Captcha is easy for humans to solve but hard for “bots” and other malicious software to figure out. However, Captcha has always been tricky for the testers to automate, as many of them don’t know how to handle captcha in Selenium or using any other test automation framework.
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.
Get 100 minutes of automation test minutes FREE!!