Best Python code snippet using playwright-python
_network.py
Source: _network.py
...238 lambda params: self._on_frame_sent(params["opcode"], params["data"]),239 )240 self._channel.on(241 "frameReceived",242 lambda params: self._on_frame_received(params["opcode"], params["data"]),243 )244 self._channel.on(245 "error", lambda params: self.emit(WebSocket.Events.Error, params["error"])246 )247 self._channel.on("close", lambda params: self._on_close())248 @property249 def url(self) -> str:250 return self._initializer["url"]251 def expect_event(252 self,253 event: str,254 predicate: Callable = None,255 timeout: float = None,256 ) -> EventContextManagerImpl:257 if timeout is None:258 timeout = cast(Any, self._parent)._timeout_settings.timeout()259 wait_helper = WaitHelper(self._loop)260 wait_helper.reject_on_timeout(261 timeout, f'Timeout while waiting for event "{event}"'262 )263 if event != WebSocket.Events.Close:264 wait_helper.reject_on_event(265 self, WebSocket.Events.Close, Error("Socket closed")266 )267 if event != WebSocket.Events.Error:268 wait_helper.reject_on_event(269 self, WebSocket.Events.Error, Error("Socket error")270 )271 wait_helper.reject_on_event(self._parent, "close", Error("Page closed"))272 wait_helper.wait_for_event(self, event, predicate)273 return EventContextManagerImpl(wait_helper.result())274 async def wait_for_event(275 self, event: str, predicate: Callable = None, timeout: float = None276 ) -> Any:277 async with self.expect_event(event, predicate, timeout) as event_info:278 pass279 return await event_info280 def _on_frame_sent(self, opcode: int, data: str) -> None:281 if opcode == 2:282 self.emit(WebSocket.Events.FrameSent, base64.b64decode(data))283 else:284 self.emit(WebSocket.Events.FrameSent, data)285 def _on_frame_received(self, opcode: int, data: str) -> None:286 if opcode == 2:287 self.emit(WebSocket.Events.FrameReceived, base64.b64decode(data))288 else:289 self.emit(WebSocket.Events.FrameReceived, data)290 def is_closed(self) -> bool:291 return self._is_closed292 def _on_close(self) -> None:293 self._is_closed = True294 self.emit(WebSocket.Events.Close)295def serialize_headers(headers: Dict[str, str]) -> List[Header]:296 return [{"name": name, "value": value} for name, values in headers.items() for value in ([str(value) for value in values] if type(values) in [list,set,tuple] else [str(values)])]297def parse_headers(headers: List[Header]) -> Dict[str, str]:...
connection.py
Source: connection.py
...155 raise_error_from_server(frame.reply_code, frame.reply_text)156 async def _handle_server_heartbeat(self, frame: HeartbeatFrame):157 print("Server Heartbeat Received")158 self.missed_heartbeats = 0159 async def _on_frame_received(self, frame: Frame):160 try:161 await self.router.route_frame(frame)162 except KeyError:163 print("Frame {} has no router. Skipping it.".format(frame))164 async def _heartbeat_loop(self):165 print("Initiating Heartbeat Loop")166 while self._running:167 await asyncio.sleep(self.heartbeat // 2)168 seconds_without_send = (169 datetime.utcnow() - self.last_send_dt170 ).total_seconds()171 if seconds_without_send > self.heartbeat:172 heartbeat = Frame.from_frame(HeartbeatFrame(), channel=0)173 await self._send_to_server(heartbeat)174 async def _run(self):175 """176 Read Frames until the connection closes.177 :return:178 """179 self._running = True180 while self._running:181 try:182 header = await asyncio.wait_for(183 self.conn.recv(7), timeout=self.heartbeat184 )185 except asyncio.TimeoutError:186 print("Read Timed-out increasing missed heartbeats count")187 self.missed_heartbeats += 1188 if self.missed_heartbeats > 4:189 await self.close()190 raise ConnectionAbortedError(191 "Server missed heartbeats. Closing connection"192 )193 continue194 if header.startswith(b"AMQP"):195 # Some Protocol Version Error.196 header += await self.conn.recv(1)197 supported_version = struct.unpack(">BBB", header[-3:])198 raise ProtocolError(199 f"Target server does not support {VERSION} version. "200 f"Supported Version is: {supported_version}"201 )202 frame, remaining = await self.parse_frame(header)203 assert remaining == b'', 'Remaining of {} is not empty: {}'.format(204 frame, remaining205 )206 # remaining should always be empty207 await self._on_frame_received(frame)208 async def parse_frame(self, header) -> Tuple[Frame, bytes]:209 frame_header, remaining = FrameHeader.from_bytes(header)210 payload = await self.conn.recv(frame_header.size + 1)211 if not payload.endswith(FRAME_END):212 raise FrameEndError(213 "Expected Frame-End not found after reading the whole "214 "frame data."215 )216 payload = payload.rstrip(FRAME_END)217 return Frame.from_bytes(header + payload)218 async def close(self):219 self._running = False220async def _get_connection(221 host: str, port: int, ssl=None, loop=None...
client.py
Source: client.py
...57 @property58 def on_frame_received(self) -> EventListener[OnFrameReceivedCallback]:59 """Event triggered when a frame is received by the client."""60 return self._on_frame_received_event61 def _on_frame_received(self, frame_index: int, frame: FrameData) -> None:62 changes = frame.array_keys | frame.value_keys63 super()._on_frame_received(frame_index, frame)64 self._on_frame_received_event.invoke(changes=changes)65 @classmethod66 @contextmanager67 def connect_to_session(cls, session: Session, /) -> Generator[Client, None, None]:68 """69 Connect to a session.70 :param session: Session that is running.71 :yields: Client connected to the given session.72 """73 with cls.connect_to_server(address="localhost", port=session.port) as client:74 yield client75 @classmethod76 @contextmanager77 def connect_to_server(...
yolov4_dices_detection_controller.py
...40 self._streamer.moveToThread(self._thread)41 self._streamer.frames.connect(self._on_frame_received)42 self._thread.started.connect(self._streamer.run)43 self._thread.start()44 def _on_frame_received(self, frame: np.ndarray):45 dices = self._detector.detect(frame)46 for dice in dices:47 box = dice.box48 left, top = box.left, box.top49 right, bottom = box.left + box.width, box.top + box.height50 color = (0, 0, 255)51 frame = cv2.rectangle(frame, (left, top), (right, bottom), color)52 class_label_x = left + box.width // 253 class_label_y = top + 1054 class_label = _classes[dice.class_id]55 frame = _place_class_label(frame, class_label_x, class_label_y, class_label)56 self.images.emit(rgb_image_to_qt(frame))57 def clear_resources(self):58 self._thread.stop()
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!!