Best Python code snippet using playwright-python
redirections.py
Source:redirections.py
...136 for_each = for_each_link_redirection_uri137 else:138 raise ValueError("Unknown redirection URI type: \"{}\""139 .format(uri_type))140 def callback_wrapper(uris, info):141 try:142 callback(uris, info=info)143 except: # noqa144 print "info: " + str(info)145 print "uris: " + str(uris)146 raise147 # -------------------------------------------------------------------------148 # cross-site redirections149 # -------------------------------------------------------------------------150 # usual cross-site redirection151 for_each(152 callback_wrapper,153 base_info={"is_same_host": False, "is_relative_dest": False},154 origin_pre_path="http://www.maindomain.test/",...
gisquick_ws.py
Source:gisquick_ws.py
...48 """49 def start(self, url, username, password, client_info, callback, success_callback):50 self._load_lib()51 @ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_char_p)52 def callback_wrapper(msg):53 msg = json.loads(msg)54 try:55 ret_value = callback(msg) or ""56 resp = {57 "type": msg["type"],58 "status": 200,59 "data": ret_value60 }61 except Exception as e:62 resp = {63 "type": msg["type"],64 "status": e.code if isinstance(e, WsError) else 500,65 "data": str(e)66 }67 if e.__cause__:68 t = TracebackException.from_exception(e.__cause__)69 resp["traceback"] = "".join(t.format())70 return json.dumps(resp).encode("utf-8")71 @ctypes.CFUNCTYPE(ctypes.c_void_p)72 def success_callback_wrapper():73 success_callback()74 try:75 return self._lib.Start(76 go_string(url),77 go_string(username),78 go_string(password),79 go_string(client_info),80 callback_wrapper,81 success_callback_wrapper82 )83 finally:84 self._unload_lib()85 def stop(self):86 if self._lib:87 self._lib.Stop()88 def send(self, name, data=None):89 msg = {90 "type": name91 }92 if data is not None:93 msg["data"] = data94 self._lib.SendMessage(go_string(json.dumps(msg)))95gisquick_ws = GisquickWs()96"""97Alternative version with separate process. Doesn't work properly on Windows,98somehow it starts a new qgis app... However for development on Linux it could be99more convinient, cause you do not need to restart qgis when rebuilding native lib.100"""101"""102import multiprocessing 103def go(url, username, password, parent_conn, child_conn):104 lib = ctypes.cdll.LoadLibrary(lib_path)105 @ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_char_p)106 def callback_wrapper(msg):107 try:108 # print("received MSG", msg.decode())109 child_conn.send(msg.decode())110 reply = child_conn.recv()111 return reply.encode("utf-8")112 except Exception as e:113 traceback.print_exc()114 # traceback.print_stack()115 # raise116 return lib.Start(go_string(url), go_string(username), go_string(password), callback_wrapper)117class GisquickWs2():118 p1 = None119 def start(self, url, username, password, callback):120 print("Start")...
webgui.py
Source:webgui.py
...32 def inject_javascript(browser, script):33 browser.execute_script(script)34 @staticmethod35 def connect_title_changed(browser, callback):36 def callback_wrapper(widget, frame, title): callback(title)37 browser.connect('title-changed', callback_wrapper)38 @staticmethod39 def open_uri(browser, uri):40 browser.open(uri)41class GtkMozEmbedMethods(object):42 @staticmethod43 def create_browser():44 return gtkmozembed.MozEmbed()45 @staticmethod46 def inject_javascript(browser, script):47 uri = 'javascript:%s' % urllib.quote(script + '\n;void(0);')48 browser.load_url(uri)49 @staticmethod50 def connect_title_changed(browser, callback):51 # XXX: probably you should cross your fingers and hope browser52 # isn't sending title messages too quickly...?53 def callback_wrapper(*args): callback(browser.get_title())54 browser.connect('title', callback_wrapper)55 @staticmethod56 def open_uri(browser, uri):57 browser.load_url(uri)58if use is UseWebKit:59 implementation = WebKitMethods60if use is UseGtkMozEmbed:61 implementation = GtkMozEmbedMethods62def asynchronous_gtk_message(fun):63 def worker((function, args, kwargs)):64 apply(function, args, kwargs)65 def fun2(*args, **kwargs):66 gobject.idle_add(worker, (fun, args, kwargs))67 return fun2...
event.py
Source:event.py
...27 if timeout is not None and self.stream() == orig_value:28 # Value did not change, must have timed out29 return30 def add_callback(self, callback):31 def callback_wrapper(x):32 if x:33 callback()34 self._callback_mapping[callback] = callback_wrapper35 self._stream.add_callback(callback_wrapper)36 def remove_callback(self, callback):37 if callback in self._callback_mapping:38 callback_wrapper = self._callback_mapping[callback]39 del self._callback_mapping[callback]40 self._stream.remove_callback(callback_wrapper)41 @property42 def stream(self):43 """ The underlying stream for the event """44 return self._stream45 def remove(self):...
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!!