Best Python code snippet using playwright-python
_wait_helper.py
Source:_wait_helper.py
...39 "event": event,40 }41 },42 )43 def _wait_for_event_info_after(self, wait_id: str, error: Exception = None) -> None:44 try:45 info = {46 "waitId": wait_id,47 "phase": "after",48 }49 if error:50 info["error"] = str(error)51 self._channel.send_no_reply(52 "waitForEventInfo",53 {54 "info": info,55 },56 )57 except Exception:58 pass59 def reject_on_event(60 self,61 emitter: EventEmitter,62 event: str,63 error: Error,64 predicate: Callable = None,65 ) -> None:66 def listener(event_data: Any = None) -> None:67 if not predicate or predicate(event_data):68 self._reject(error)69 emitter.on(event, listener)70 self._registered_listeners.append((emitter, event, listener))71 def reject_on_timeout(self, timeout: float, message: str) -> None:72 if timeout == 0:73 return74 async def reject() -> None:75 await asyncio.sleep(timeout / 1000)76 self._reject(TimeoutError(message))77 self._pending_tasks.append(self._loop.create_task(reject()))78 def _cleanup(self) -> None:79 for task in self._pending_tasks:80 if not task.done():81 task.cancel()82 for listener in self._registered_listeners:83 listener[0].remove_listener(listener[1], listener[2])84 def _fulfill(self, result: Any) -> None:85 self._cleanup()86 if not self._result.done():87 self._result.set_result(result)88 self._wait_for_event_info_after(self._wait_id)89 def _reject(self, exception: Exception) -> None:90 self._cleanup()91 if exception:92 base_class = TimeoutError if isinstance(exception, TimeoutError) else Error93 exception = base_class(str(exception) + format_log_recording(self._logs))94 if not self._result.done():95 self._result.set_exception(exception)96 self._wait_for_event_info_after(self._wait_id, exception)97 def wait_for_event(98 self,99 emitter: EventEmitter,100 event: str,101 predicate: Callable = None,102 ) -> None:103 def listener(event_data: Any = None) -> None:104 if not predicate or predicate(event_data):105 self._fulfill(event_data)106 emitter.on(event, listener)107 self._registered_listeners.append((emitter, event, listener))108 def result(self) -> asyncio.Future:109 return self._result110 def log(self, message: str) -> None:...
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!!