Best Python code snippet using playwright-python
00_Multi_server_starter.py
Source: 00_Multi_server_starter.py
1# -*- coding: utf-8 -*-2"""3Created on Mon Aug 6 12:51:03 20184@author: viho5/******************************************************************************6* Copyright 2019 Fraunhofer Institute for Building Physics IBP. All Rights Reserved.7*8* Licensed under the Apache License, Version 2.0 (the "License");9* you may not use this file except in compliance with the License.10* You may obtain a copy of the License at11*12* http://www.apache.org/licenses/LICENSE-2.013*14* Unless required by applicable law or agreed to in writing, software15* distributed under the License is distributed on an "AS IS" BASIS,16* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.17* See the License for the specific language governing permissions and18* limitations under the License.19*****************************************************************************/20"""21import asyncio22import sys23from REST_ADS_AIO import app_ads24from task1 import app_task125from task2 import app_task226#from XKNX_Rest_AIOHTTP import app_xknx27from REST2FMI_AIO import app_fmi28from rest_fmi_ahu import app_ahu29from rest_fmi_ctrl import app_ctrl30def start():31 try:32 loop = asyncio.get_event_loop()33 34 35 ### ### ### ### ### ### ### ###36 # Application "ADS" on port 808037 # app1 = app_ads38 # handler1 = app1.make_handler()39 # coroutine1 = loop.create_server(handler1, '127.0.0.1', 8080)40 # server1 = loop.run_until_complete(coroutine1)41 # address1, port1 = server1.sockets[0].getsockname()42 # print('ADS_APP started on http://{}:{}'.format(address1, port1))43 44 ### ### ### ### ### ### ### ###45 #Application "TASK1" on port 808146 app2 = app_ctrl47 handler2 = app2.make_handler()48 coroutine2 = loop.create_server(handler2, '127.0.0.1', 8080)49 server2 = loop.run_until_complete(coroutine2)50 address2, port2 = server2.sockets[0].getsockname()51 print('CTRL_APP started on http://{}:{}'.format(address2, port2))52 ### ### ### ### ### ### ### ###53 # Application "XKNX" on port 8082 54 # app3 = app_xknx55 # handler3 = app3.make_handler()56 # coroutine3 = loop.create_server(handler3, '127.0.0.1', 8082)57 # server3 = loop.run_until_complete(coroutine3)58 # address3, port3 = server3.sockets[0].getsockname()59 # print('XKNX_APP started on http://{}:{}'.format(address3, port3))60 61 ### ### ### ### ### ### ### ###62 # Application "FMI" on port 8083 63 # app4 = app_fmi64 # handler4 = app4.make_handler()65 # coroutine4 = loop.create_server(handler4, '127.0.0.1', 8083)66 # server4 = loop.run_until_complete(coroutine4)67 # address4, port4 = server4.sockets[0].getsockname()68 # print('FMI_APP started on http://{}:{}'.format(address4, port4))69 70 ### ### ### ### ### ### ### ###71 #Application "TASK2" on port 808172 app4 = app_ahu73 handler4 = app4.make_handler()74 coroutine4 = loop.create_server(handler4, '127.0.0.1', 8083)75 server4 = loop.run_until_complete(coroutine4)76 address4, port4 = server4.sockets[0].getsockname()77 print('AHU_APP started on http://{}:{}'.format(address4, port4))78 79 try:80 loop.run_forever()81 except KeyboardInterrupt:82 pass83 finally:84 ### ### ### ### ### ### ### ###85 # Close all apps86 # server1.close()87 # loop.run_until_complete(app1.shutdown())88 # loop.run_until_complete(handler1.shutdown(60.0))89 # loop.run_until_complete(handler1.finish_connections(1.0))90 # loop.run_until_complete(app1.cleanup())91 server2.close()92 loop.run_until_complete(app2.shutdown())93 loop.run_until_complete(handler2.shutdown(60.0))94 loop.run_until_complete(handler2.finish_connections(1.0))95 loop.run_until_complete(app2.cleanup())96 97 # server3.close()98 # loop.run_until_complete(app3.shutdown())99 # loop.run_until_complete(handler3.shutdown(60.0))100 # loop.run_until_complete(handler3.finish_connections(1.0))101 # loop.run_until_complete(app3.cleanup())102 103 server4.close()104 loop.run_until_complete(app4.shutdown())105 loop.run_until_complete(handler4.shutdown(60.0))106 loop.run_until_complete(handler4.finish_connections(1.0))107 loop.run_until_complete(app4.cleanup())108 109 loop.close()110 except Exception as e:111 sys.stderr.write('Error: ' + format(str(e)) + "\n")112 sys.exit(1)113if __name__ == '__main__':114 start()...
__init__.py
Source: __init__.py
1"""2pythonæ¥å¿æ¨¡å logging3éè¦çå个é¨åï¼4ä¸ã è®°å½å¨ logger5 éè¿è®°å½å¨çå½æ°ï¼å®ç°æ¥å¿ä¿¡æ¯çè®°å½,å¦ï¼6 logger.info('----')7 logger.debug('---')8 logger.warning('--')9 logger.error(msg)10 logger.critical(msg)11äºã å¤çå¨ Handler12 å°è®°å½å¨çè®°å½æ¥å¿ä¿¡æ¯è¿è¡ç¹å®çå¤çï¼13 é»è®¤æ
åµä½¿ç¨æå°å°æ§å¶å°çStreamHandlerå¤çå¨14 å¤çå¨Handler对象éè¦æ·»å å°è®°å½å¨loggerä¸ç, å¦ï¼15 logger.addHandler(xxxHandler)16 常ç¨çå¤çå¨ï¼17 æµå¤çå¨StreamHandler18 æ件å¤çå¨ FileHandler19 ç½ç»è¯·æ±å¤çå¨ HTTPHandler : ä¸ä¼ æ¥å¿ä¿¡æ¯å°æ¥å¿æå¡å¨(Flask/Flume)20 é®ç®±å¤çå¨ SMTPHandler21ä¸ã æ¥å¿æ ¼å¼åFormatter22 æå®æ¥å¿ä¿¡æ¯çæ ¼å¼ï¼å¦åªè®°å½æ¥å¿ä¿¡æ¯çæ¶é´åæ¶æ¯ï¼åæ ¼å¼ä¸º:23 %(asctime)s : %(message)s24 asctimeåmessageé½æ¯æ ¼å¼åæ¥å¿çåéä¿¡æ¯ã25åã æ¥å¿è¿æ»¤å¨Filter26 è¿æ»¤ä¸äºæ ç¨çæ¥å¿ä¿¡æ¯ã27"""28import logging29from logging.handlers import TimedRotatingFileHandler, HTTPHandler, SMTPHandler30# å建æ¥å¿è®°å½å¨31# ä»»å¡3ï¼ ååºdjangoåflask项ç®ä¸çæ¥å¿è®°å½å¨çå称32# django.db.backends33# django.class.AdminEmailHandler34logger = logging.getLogger(name='django.request')35logger.setLevel(logging.WARN)36# å建æ¥å¿å¤çå¨(StreamHandler, FileHandler)37handler1 = logging.StreamHandler()38handler1.setLevel(logging.INFO)39handler2 = logging.FileHandler('django.log')40handler2.setLevel(logging.ERROR)41handler3 = SMTPHandler('smtp.qq.com',42 fromaddr='610039018@qq.com',43 toaddrs='diyuhuan@1000phone.com',44 subject='æ¥å¿é®ç®±éç¥')45# é
ç½®é®ä»¶éªè¯ç¨æ·åå£ä»¤ï¼æææç ï¼46handler3.username = '610039018@qq.com'47handler3.password = 'xrjtaatcuylqbbba' # QQé®ç®±å件æ¶éªè¯çâææç â48handler3.setLevel(logging.FATAL)49# å建ä¸ä¼ æ¥å¿è¯·æ±çå¤çå¨HTTPHandler50# ä¸ä¼ æ¥å¿çæ¥å£ï¼ http://10.35.162.97:5000/log/51# æ¥å£çæ¹æ³ï¼ post52# ååºçæ°æ®æ¯json53handler4 = HTTPHandler(host='10.35.162.97:5000',54 url='/log/', method='POST')55handler4.setLevel(logging.INFO)56# åå»ºæ ¼å¼å对象 , 并添å å°å¤çå¨57formatter = logging.Formatter('[ <%(asctime)s> %(name)s %(levelname)s ] %(message)s')58handler1.setFormatter(formatter)59handler2.setFormatter(formatter)60handler3.setFormatter(formatter)61handler4.setFormatter(formatter) # æ æçï¼é»è®¤æ
åµä¸å°ææçæ¥å¿ä¿¡æ¯ä¸ä¼ å°æå¡å¨62# å°å¤çå¨æ·»å å°æ¥å¿è®°å½å¨63logger.addHandler(handler1)64logger.addHandler(handler2)65# logger.addHandler(handler3)66logger.addHandler(handler4)67# ä»»å¡4ï¼ ä½¿ç¨SMTPHandlerå°è®°å½çæ¥å¿ä¿¡æ¯åéå°é®ç®±ä¸68if __name__ == '__main__':69 logger.info('hi, disen')70 logger.debug('hi, 190')71 logger.warning('hi, 110')72 logger.error('hi, 120')...
test_log.py
Source: test_log.py
1#!/usr/bin/python32# coding: utf-83import logging4from logging.handlers import TimedRotatingFileHandler, HTTPHandler, SMTPHandler5from logging import StreamHandler, FileHandler6# from common.handler_ import ESHandler7# è·åæ¥å¿è®°å½å¨8logger = logging.getLogger('user_action')9logger.setLevel(logging.INFO) # å¯ä»¥æ¶éINFOå以ä¸çº§å«çææä¿¡æ¯10# çææ¥å¿çæ ¼å¼å对象, å®ä¹æ¶éåªäºä¿¡æ¯11fmt_str = "[ %(asctime)s %(name)s %(levelname)s ] %(message)s"12formatter = logging.Formatter(fmt_str, '%Y-%m-%d %H:%M:%S')13# å建æ¥å¿å¤çå¨(StreamHandler, FileHandler, HTTPHandler, SMTPHandler)14handler1 = StreamHandler()15handler1.setLevel(logging.INFO)16handler1.setFormatter(formatter)17handler2 = FileHandler('access.log', encoding='utf-8')18handler2.setLevel(logging.INFO)19handler2.setFormatter(formatter)20handler3 = FileHandler('error.log', encoding='utf-8')21handler3.setLevel(logging.ERROR)22handler3.setFormatter(formatter)23# handler4 = ESHandler()24# handler4.setLevel(logging.INFO)25# handler4.setFormatter(formatter)26logger.addHandler(handler1) # å°æ¥å¿å¤çå¨æ·»å å°è®°å½å¨ä¸27logger.addHandler(handler2)28logger.addHandler(handler3)29# logger.addHandler(handler4)30def test_all_msg():31 logger.debug('ææ¯bug, 请æ¥æ¶!')32 logger.info('ææ¯è®¿é®è®°å½ï¼è¯·æ¥æ¶ï¼')33 logger.warning('主人ï¼ä¸»äººï¼è¦åæ¥äºï¼è¯·å°½å¿«ææ¥!')34 logger.error('主人ï¼å¿«æ¥ï¼ è¿éæ个é误ï¼')35 logger.critical('ç´§æ¥æ
åµï¼è¿éåºç°äºå¾ä¸¥éçé误ï¼')...
file_handling.py
Source: file_handling.py
1#File Handling - Create, Accessing and modifying the File2#Opening file3#If we dont specify the mode.Python will take read mode 'r' by defauly4f_handler = open("test.txt")5# #Modes6# # r -read7# # w - write8# # a - append9# # r+ - read and write10#To get the name of the file you are accessing11print(f_handler.name)12#To get the Mode you used to open the file13print(f_handler.mode)14#To read the contents of the file15filetext = f_handler.read()16print(filetext)17#To close the file you opened using open() method18f_handler.close()19#Opening a file using Context Manager20with open("test.txt") as f_handler2:21 filetext2 = f_handler2.read()22print(filetext2)23#Using a to append the text to the existing file content24with open("test.txt", "a") as f_handler3:25 f_handler3.write("Hello world")26with open("test.txt", "r") as f_handler4:27 f = f_handler4.read()28 print(f)29with open("test.txt", "r") as f_handler4:30 #To extract each line in to an element in the list31 f = f_handler4.readlines()32 print(f)33 #Extracting the file contents through file handler using loop34 for i in f_handler4:35 print(i, end="")36 #To extract the part of the file content37 f = f_handler4.read(150)38 print(f)39#Using w mode to override the contents of the file40with open("test2.txt", "w") as f_handler5:41 #writing into the file42 f_handler5.write("Hi All")43 #Placing the curser a particalar place using seek() method44 f_handler5.seek(4)45 f_handler5.write("Good Morning")46#Using context manager to copy the contents from one file to another file.47with open("test.txt", "r") as rf:48 with open("test_copy.txt", "w") as rwf:49 for line in rf:50 rwf.write(line)51#Using context manager to copy the image file. 52with open("teddy.jpg", "rb") as rf:53 with open("teddy2.jpg", "wb") as rwf:54 for line in rf:...
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!!