Best Python code snippet using playwright-python
dialogs.py
Source: dialogs.py
1from PyQt5.QtWidgets import QPushButton, QDialog, QWidget, QLabel, QGridLayout, QLineEdit, QApplication2import sys3class MyDialog(QDialog):4 def __init__(self, parent, caption, **kwargs):5 super(MyDialog, self).__init__(parent)6 self.caption = caption7 self.kwargs = kwargs8 self.entries = {}9 self.result = {}10 self.initUI()11 def initUI(self):12 layout = QGridLayout()13 self.setLayout(layout)14 self.setModal(True)15 layout.setColumnStretch(1, 4)16 layout.setColumnStretch(2, 4)17 row = 018 for n,v in self.kwargs.items():19 label = QLabel('%s:'%n)20 layout.addWidget(label, row, 0)21 edt = QLineEdit(self)22 edt.setText(v)23 layout.addWidget(edt, row, 1)24 self.entries[n] = edt25 row += 126 ok = QPushButton('OK')27 ok.clicked.connect(self.onOkBtn)28 layout.addWidget(ok, row, 0)29 cancel = QPushButton('Cancel')30 cancel.clicked.connect(self.onCancelBtn)31 layout.addWidget(cancel, row, 1)32 self.result = {}33 def onOkBtn(self):34 for n,edt in self.entries.items():35 self.result[n] = edt.text()36 self.close()37 def onCancelBtn(self):38 self.result = {}39 self.close()40 def run(self):41 self.exec_()42 return self.result43def makeEdit(parent, layout, caption, value, row, editedHandler=None):44 label = QLabel(caption)45 layout.addWidget(label, row, 0)46 result = QLineEdit(parent)47 result.setText(str(value))48 layout.addWidget(result, row, 1)49 if editedHandler:50 result.textEdited.connect(editedHandler)51 return result52def makeButton(parent, layout, caption, clicked, row, col):53 result = QPushButton(caption)54 result.clicked.connect(clicked)55 layout.addWidget(result, row, col)56 return result57def makeOkCancelButtons(parent, layout, clicked1, clicked2, row):58 return makeButton(parent, layout, '&Ok', clicked1, row, 0),\59 makeButton(parent, layout, '&Cancel', clicked2, row, 1)60class BrightnessConstrastFrame(QWidget):61 def __init__(self, parent, brightness, contrast, onclose, onbrightness, oncontrast):62 super(BrightnessConstrastFrame, self).__init__(parent)63 layout = QGridLayout()64 # layout.setColumnStretch(1, 4)65 # layout.setColumnStretch(2, 4)66 self.brightnessEdt = makeEdit(self, layout, 'Brightness:', brightness, 0, onbrightness)67 self.contrastEdt = makeEdit(self, layout, 'Contrast:', contrast, 1, oncontrast)68 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 2)69 self.setLayout(layout)70 self.onclose = onclose71 def onOkBtn(self):72 self.close()73 QApplication.processEvents()74 self.onclose((float(self.brightnessEdt.text()), float(self.contrastEdt.text())))75 def onCancelBtn(self):76 self.close()77 QApplication.processEvents()78 self.onclose(None)79class ConstrastFrame(QWidget):80 def __init__(self, parent, contrast, onclose):81 super(ConstrastFrame, self).__init__(parent)82 layout = QGridLayout()83 # layout.setColumnStretch(1, 4)84 # layout.setColumnStretch(2, 4)85 self.contrastEdt = makeEdit(self, layout, 'Contrast:', contrast, 1)86 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 2)87 self.setLayout(layout)88 self.onclose = onclose89 def onOkBtn(self):90 self.close()91 QApplication.processEvents()92 self.onclose(float(self.contrastEdt.text()))93 def onCancelBtn(self):94 self.close()95 QApplication.processEvents()96 self.onclose(None)97class NumValFrame(QWidget):98 def __init__(self, parent, name, value, onclose):99 super(NumValFrame, self).__init__(parent)100 layout = QGridLayout()101 # layout.setColumnStretch(1, 4)102 # layout.setColumnStretch(2, 4)103 self.edt = makeEdit(self, layout, name, value, 1)104 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 2)105 self.setLayout(layout)106 self.onclose = onclose107 def onOkBtn(self):108 self.close()109 QApplication.processEvents()110 self.onclose(float(self.edt.text()))111 def onCancelBtn(self):112 self.close()113 QApplication.processEvents()114 self.onclose(None)115class OrtonFrame(QWidget):116 #d = EntriesDialog(win.master, "Orthon effect", (("Main image brightness:","1.1"),117 # ("Blured image brightness:","1.3"), ("Blured image zoom:","1.01"), ("Blend alpha:","0.3"),))118 def __init__(self, parent, brightness, brightness2, zoom, alpha, onclose):119 #super(OrtonFrame, self).__init__(parent)120 super().__init__(parent)121 layout = QGridLayout()122 # layout.setColumnStretch(1, 4)123 # layout.setColumnStretch(2, 4)124 self.brightnessEdt = makeEdit(self, layout, 'Main image brightness:', brightness, 0)125 self.brightness2Edt = makeEdit(self, layout, 'Blured image brightness:', brightness2, 1)126 self.zoomEdt = makeEdit(self, layout, 'Blured image zoom:', zoom, 2)127 self.alphaEdt = makeEdit(self, layout, 'Blend alpha:', alpha, 3)128 makeOkCancelButtons(self, layout, self.onOkBtn, self.onCancelBtn, 4)129 self.setLayout(layout)130 self.onclose = onclose131 def onOkBtn(self):132 self.close()133 QApplication.processEvents()134 self.onclose((135 float(self.brightnessEdt.text()),136 float(self.brightness2Edt.text()),137 float(self.zoomEdt.text()),138 float(self.alphaEdt.text())139 ))140 def onCancelBtn(self):141 self.close()142 QApplication.processEvents()143 self.onclose(None)144if __name__ == '__main__':145 from fbs_runtime.application_context.PyQt5 import ApplicationContext146 appctxt = ApplicationContext()147 appctxt.app.setStyle('Fusion')148 #w = MyDialog(None, one='1',two='2')149 w = MyDialog(None, 'test', **{'one':'1','two':'2'})150 w.show() # real app should call w.run() which returns result dictionary151 exit_code = appctxt.app.exec_()152 for n,v in w.result.items():153 print(n,v)...
Examples_test.py
Source: Examples_test.py
...42 class FileWatchDog():43 def onOpen(self, fileName, openMode):44 print(f"File {fileName} opened with {openMode} mode")4546 def onClose(self, fileName):47 print(f"File {fileName} closed")484950 def onOpenStandaloneMethod(fileName, openMode):51 print(f"StandaloneMethod: File {fileName} opened with {openMode} mode")5253 watchDog = FileWatchDog()5455 notifier = Notifier(["onCreate", "onOpen", "onModify", "onClose", "onDelete"])5657 notifier.subscribe("onOpen", watchDog.onOpen)58 notifier.subscribe("onOpen", onOpenStandaloneMethod)59 notifier.subscribe("onClose", watchDog.onClose)6061 print("\nAfter subscription:")62 notifier.raise_event("onOpen", openMode="w+", fileName="test_file.txt")63 notifier.raise_event("onClose", fileName="test_file.txt")6465 notifier.remove_subscribers_by_event_name("onOpen")6667 print("\nAfter removal of onOpen subscribers:")68 notifier.raise_event("onOpen", openMode="w+", fileName="test_file.txt")69 notifier.raise_event("onClose", fileName="test_file.txt")7071 notifier.remove_subscribers_by_event_name("onClose")7273 print("\nAfter removal of onClose subscribers:")74 notifier.raise_event("onOpen", openMode="w+", fileName="test_file.txt")75 notifier.raise_event("onClose", fileName="test_file.txt")76777879 def test_remove_all_subscribers(self):80 from EventNotifier import Notifier81 class FileWatchDog():82 def onOpen(self, fileName, openMode):83 print(f"File {fileName} opened with {openMode} mode")8485 def onClose(self, fileName):86 print(f"File {fileName} closed")878889 def onOpenStandaloneMethod(fileName, openMode):90 print(f"StandaloneMethod: File {fileName} opened with {openMode} mode")9192 watchDog = FileWatchDog()9394 notifier = Notifier(["onCreate", "onOpen", "onModify", "onClose", "onDelete"])9596 notifier.subscribe("onOpen", watchDog.onOpen)97 notifier.subscribe("onOpen", onOpenStandaloneMethod)98 notifier.subscribe("onClose", watchDog.onClose)99
...
org_apache_sling_scripting_core_impl_scripting_resource_resolver_provider_properties.py
Source: org_apache_sling_scripting_core_impl_scripting_resource_resolver_provider_properties.py
1# coding: utf-82from __future__ import absolute_import3from datetime import date, datetime # noqa: F4014from typing import List, Dict # noqa: F4015from openapi_server.models.base_model_ import Model6from openapi_server.models.config_node_property_boolean import ConfigNodePropertyBoolean # noqa: F401,E5017from openapi_server import util8class OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties(Model):9 """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).10 Do not edit the class manually.11 """12 def __init__(self, log_stacktrace_onclose: ConfigNodePropertyBoolean=None): # noqa: E50113 """OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties - a model defined in OpenAPI14 :param log_stacktrace_onclose: The log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties. # noqa: E50115 :type log_stacktrace_onclose: ConfigNodePropertyBoolean16 """17 self.openapi_types = {18 'log_stacktrace_onclose': ConfigNodePropertyBoolean19 }20 self.attribute_map = {21 'log_stacktrace_onclose': 'log.stacktrace.onclose'22 }23 self._log_stacktrace_onclose = log_stacktrace_onclose24 @classmethod25 def from_dict(cls, dikt) -> 'OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties':26 """Returns the dict as a model27 :param dikt: A dict.28 :type: dict29 :return: The orgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties. # noqa: E50130 :rtype: OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties31 """32 return util.deserialize_model(dikt, cls)33 @property34 def log_stacktrace_onclose(self) -> ConfigNodePropertyBoolean:35 """Gets the log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.36 :return: The log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.37 :rtype: ConfigNodePropertyBoolean38 """39 return self._log_stacktrace_onclose40 @log_stacktrace_onclose.setter41 def log_stacktrace_onclose(self, log_stacktrace_onclose: ConfigNodePropertyBoolean):42 """Sets the log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.43 :param log_stacktrace_onclose: The log_stacktrace_onclose of this OrgApacheSlingScriptingCoreImplScriptingResourceResolverProviderProperties.44 :type log_stacktrace_onclose: ConfigNodePropertyBoolean45 """...
websocket_client_threaded.py
Source: websocket_client_threaded.py
1import threading, Queue2from amitu import websocket_client3class _Writer(threading.Thread):4 def __init__(self, ws):5 super(_Writer, self).__init__()6 self.daemon = True7 self.ws = ws8 self.queue = Queue.Queue()9 def send(self, data):10 self.queue.put(data)11 def run(self):12 while True:13 self.ws._send(self.queue.get(block=True))14class WebSocket(websocket_client.WebSocket):15 """16 Threaded WebSocket class17 Use this class to use a threaded websocket. It reads data from server18 on the current thread, and sends data on a separate daemon thread.19 >>> def onmessage(message): print "onmessage", message20 ...21 >>> def onopen(): print "onopen"22 ...23 >>> def onclose(): print "onclose"24 ...25 >>> ws = WebSocket("ws://server.com:8080/path")26 >>> ws.onopen(onopen)27 >>> ws.onclose(onclose)28 >>> ws.onmessage(onmessage)29 >>> ws.run() # blocks30 """31 def __init__(self, *args, **kw):32 websocket_client.WebSocket.__init__(self, *args, **kw)33 self.writer = _Writer(self)34 self.onopen_handlers = []35 self.onclose_handlers = []36 self.onmessage_handlers = []37 def run(self):38 self.writer.start()39 websocket_client.WebSocket.run(self)40 def send(self, data):41 self.writer.send(data)42 def _fire_onopen(self):43 for cb in self.onopen_handlers: cb()44 def _fire_onmessage(self, data):45 for cb in self.onmessage_handlers: cb(data)46 def _fire_onclose(self):47 for cb in self.onclose_handlers: cb()48 def onopen(self, cb): self.onopen_handlers.append(cb)49 def onmessage(self, cb): self.onmessage_handlers.append(cb)50 def onclose(self, cb): self.onclose_handlers.append(cb)51class WebSocketThreaded(WebSocket, threading.Thread):52 """53 WebSocketThreaded54 This is a thread that runs in the background, reading and writing both55 in two different threads.56 >>> def onmessage(message): print "onmessage", message57 ...58 >>> def onopen(): print "onopen"59 ...60 >>> def onclose(): print "onclose"61 ...62 >>> ws = WebSocketThreaded("ws://server.com:8080/path")63 >>> ws.onopen(onopen)64 >>> ws.onclose(onclose)65 >>> ws.onmessage(onmessage)66 >>> ws.start()67 >>> ws.wait()68 """69 def __init__(self, *args, **kw):70 WebSocket.__init__(self, *args, **kw)...
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!!