Best JavaScript code snippet using puppeteer
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)...
settings.py
Source:settings.py
1import pygame2from trosnoth.trosnothgui.settings.display import DisplaySettingsTab3from trosnoth.trosnothgui.settings.keymap import KeymapTab4from trosnoth.trosnothgui.settings.sound import SoundSettingsTab5from trosnoth.trosnothgui.settings.themes import ThemeTab6from trosnoth.gui.framework import framework, elements7from trosnoth.gui.framework.tabContainer import TabContainer, TabSize8from trosnoth.gui.common import (ScaledArea, Location, AttachedPoint)9from trosnoth.utils.event import Event10class SettingsMenu(framework.CompoundElement):11 def __init__(self, app, onClose=None, onRestart=None,12 showThemes=False, showSound=True, showDisplay=True,13 showKeymap=True):14 super(SettingsMenu, self).__init__(app)15 self.onClose = Event()16 if onClose is not None:17 self.onClose.addListener(onClose)18 self.onRestart = Event()19 if onRestart is not None:20 self.onRestart.addListener(onRestart)21 area = ScaledArea(50,140,924, 570)22 bg = pygame.Surface((924, 500))23 bg.fill(app.theme.colours.settingsMenu)24 if app.displaySettings.alphaOverlays:25 bg.set_alpha(192)26 font = app.screenManager.fonts.bigMenuFont27 self.tabContainer = TabContainer(self.app, area, font,28 app.theme.colours.settingsTabBorder)29 bp = elements.SizedPicture(app, bg, Location(AttachedPoint((0,0),30 self.tabContainer._getTabRect)), TabSize(self.tabContainer))31 if showDisplay:32 displayTab = DisplaySettingsTab(app, onClose=self.onClose.execute)33 self.tabContainer.addTab(displayTab)34 if showKeymap:35 keymapTab = KeymapTab(app, onClose=self.onClose.execute)36 self.tabContainer.addTab(keymapTab)37 if showSound:38 soundTab = SoundSettingsTab(app, onClose=self.onClose.execute)39 self.tabContainer.addTab(soundTab)40 if showThemes:41 themeTab = ThemeTab(app, onClose=self.onClose.execute,42 onRestart=self.onRestart.execute)43 self.tabContainer.addTab(themeTab)...
session.py
Source:session.py
...38 readBuff = self.socket.recv(BUFF_SIZE)39 except timeout as e:40 continue41 if not readBuff:42 self.onClose(data)43 return44 data += readBuff45 self.onPacketRecv(packet)...
base_menu.py
Source:base_menu.py
1import dearpygui.dearpygui as dpg2from .base_window import init_content_window, init_menu_window3MENU_STATUS = {4 'menu': True,5 'content': True6}7 8def onclose_menu_window():9 MENU_STATUS['menu'] = False10 dpg.configure_item("menu_menu_window", default_value = False)11 12def onclose_content_window():13 MENU_STATUS['content'] = False14 dpg.configure_item("menu_content_window", default_value = False)15def init_onclose():16 dpg.configure_item("menu_window", on_close=onclose_menu_window)17 dpg.configure_item("content_window", on_close=onclose_content_window)18def menu_menu(sender, app_data):19 if MENU_STATUS['menu'] is False:20 if dpg.does_alias_exist("menu_window"):21 dpg.remove_alias("menu_window")22 init_menu_window()23 dpg.configure_item("menu_window", on_close=onclose_menu_window)24 else:25 dpg.delete_item("menu_window")26 27 MENU_STATUS['menu'] = not MENU_STATUS['menu']28def menu_content(sender, app_data):29 if MENU_STATUS['content'] is False:30 if dpg.does_alias_exist("content_window"):31 dpg.remove_alias("content_window")32 init_content_window()33 dpg.configure_item("content_window", on_close=onclose_content_window)34 else:35 dpg.delete_item("content_window")36 ...
closable.py
Source:closable.py
1from reflect_html import *2from reflect_antd import Alert3onClose = lambda: print("I have been closed.")4def app():5 return [6 Alert(7 message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text",8 type="warning",9 closable=True,10 onClose=onClose,11 ),12 Alert(13 message="Error Text",14 description="Error Description Error Description Error Description Error Description Error Description Error Description",15 type="error",16 closable=True,17 onClose=onClose,18 ),...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await page.close();6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch({headless: false});11 browser.on('targetcreated', async (target) => {12 const page = await target.page();13 console.log(page.url());14 });15 await browser.newPage();16})();17* `emulate(options)` - Emulates given device metrics and user agent. This method is
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await browser.close();6})();7const puppeteer = require('puppeteer');8(async () => {9 const browser = await puppeteer.launch({headless: false});10 const page = await browser.newPage();11 await browser.close();12})();13const puppeteer = require('puppeteer');14(async () => {15 const browser = await puppeteer.launch({headless: false});16 const page = await browser.newPage();17 await browser.close();18})();19const puppeteer = require('puppeteer');20(async () => {21 const browser = await puppeteer.launch({headless: false});22 const page = await browser.newPage();23 await browser.close();24})();25const puppeteer = require('puppeteer');26(async () => {27 const browser = await puppeteer.launch({headless: false});28 const page = await browser.newPage();29 await browser.close();30})();31const puppeteer = require('puppeteer');32(async () => {33 const browser = await puppeteer.launch({headless: false});34 const page = await browser.newPage();35 await browser.close();36})();37const puppeteer = require('puppeteer');38(async () => {39 const browser = await puppeteer.launch({headless: false});40 const page = await browser.newPage();41 await browser.close();42})();43const puppeteer = require('puppeteer
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await browser.close();6})();7const puppeteer = require('puppeteer');8(async () => {9 const browser = await puppeteer.launch({headless: false});10 const page = await browser.newPage();11 await browser.close();12})();13const puppeteer = require('puppeteer');14(async () => {15 const browser = await puppeteer.launch({headless: false});16 const page = await browser.newPage();17 await browser.close();18})();19const puppeteer = require('puppeteer');20(async () => {21 const browser = await puppeteer.launch({headless: false});22 const page = await browser.newPage();23 await browser.close();24})();25const puppeteer = require('puppeteer');26(async () => {27 const browser = await puppeteer.launch({headless: false});28 const page = await browser.newPage();29 await browser.close();30})();31const puppeteer = require('puppeteer');32(async () => {33 const browser = await puppeteer.launch({headless: false});34 const page = await browser.newPage();35 await browser.close();36})();37const puppeteer = require('puppeteer');38(async () => {39 const browser = await puppeteer.launch({headless: false});40 const page = await browser.newPage();41 await browser.close();42})();43const puppeteer = require('puppeteer');44(async () => {
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({4 });5 const page = await browser.newPage();6 await page.screenshot({path: 'google.png'});7 await browser.close();8})();9const puppeteer = require('puppeteer');10(async () => {11 const browser = await puppeteer.launch({12 });13 const page = await browser.newPage();14 await page.screenshot({path: 'google.png'});15 await browser.close();16})();17const puppeteer = require('puppeteer');18(async () => {19 const browser = await puppeteer.launch({20 });21 const page = await browser.newPage();22 await page.screenshot({path: 'google.png'});23 await browser.close();24})();25const puppeteer = require('puppeteer');26(async () => {27 const browser = await puppeteer.launch({28 });29 const page = await browser.newPage();30 await page.screenshot({path: 'google.png'});31 await browser.close();32})();33const puppeteer = require('puppeteer');34(async () => {35 const browser = await puppeteer.launch({36 });37 const page = await browser.newPage();38 await page.screenshot({path: 'google.png'});39 await browser.close();40})();41const puppeteer = require('puppeteer
Using AI Code Generation
1(async () => {2 const browser = await puppeteer.launch({headless: false})3 const page = await browser.newPage()4 await page.waitFor(5000)5 await browser.close()6})()7(async () => {8 const browser = await puppeteer.launch({headless: false})9 const page = await browser.newPage()10 await page.waitFor(5000)11 await browser.close()12})()13(async () => {14 const browser = await puppeteer.launch({headless: false})15 const page = await browser.newPage()16 await page.waitFor(5000)17 await browser.close()18})()19(async () => {20 const browser = await puppeteer.launch({headless: false})21 const page = await browser.newPage()22 await page.waitFor(5000)23 await browser.close()24})()
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 await page.screenshot({path: 'google.png'});6 await browser.close();7})();
Using AI Code Generation
1const browser = await puppeteer.launch();2const page = await browser.newPage();3await page.close();4await browser.close();5const browser = await puppeteer.launch();6const page = await browser.newPage();7await page.close();8await browser.close();9const browser = await puppeteer.launch();10const page = await browser.newPage();11await page.close();12await browser.close();13const browser = await puppeteer.launch();14const page = await browser.newPage();15await page.close();16await browser.close();17const browser = await puppeteer.launch();18const page = await browser.newPage();19await page.close();20await browser.close();21const browser = await puppeteer.launch();22const page = await browser.newPage();23await page.close();24await browser.close();25const browser = await puppeteer.launch();26const page = await browser.newPage();27await page.close();28await browser.close();29const browser = await puppeteer.launch();30const page = await browser.newPage();31await page.close();32await browser.close();33const browser = await puppeteer.launch();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!