def create_remote_object(parent: ChannelOwner, type: str, guid: str, initializer: Dict) -> ChannelOwner: if type == "Artifact": return Artifact(parent, type, guid, initializer) if type == "APIRequestContext": return APIRequestContext(parent, type, guid, initializer) if type == "BindingCall": return BindingCall(parent, type, guid, initializer) if type == "Browser": return Browser(cast(BrowserType, parent), type, guid, initializer) if type == "BrowserType": return BrowserType(parent, type, guid, initializer) if type == "BrowserContext": return BrowserContext(parent, type, guid, initializer) if type == "CDPSession": return CDPSession(parent, type, guid, initializer) if type == "ConsoleMessage": return ConsoleMessage(parent, type, guid, initializer) if type == "Dialog": return Dialog(parent, type, guid, initializer) if type == "ElementHandle": return ElementHandle(parent, type, guid, initializer) if type == "Frame": return Frame(parent, type, guid, initializer) if type == "JSHandle": return JSHandle(parent, type, guid, initializer) if type == "LocalUtils": local_utils = LocalUtils(parent, type, guid, initializer) if not local_utils._connection._local_utils: local_utils._connection._local_utils = local_utils return local_utils if type == "Page": return Page(parent, type, guid, initializer) if type == "Playwright": return Playwright(parent, type, guid, initializer) if type == "Request": return Request(parent, type, guid, initializer) if type == "Response": return Response(parent, type, guid, initializer) if type == "Route": return Route(parent, type, guid, initializer) if type == "Stream": return Stream(parent, type, guid, initializer) if type == "Tracing": return Tracing(parent, type, guid, initializer) if type == "WebSocket": return WebSocket(parent, type, guid, initializer) if type == "Worker": return Worker(parent, type, guid, initializer) if type == "WritableStream": return WritableStream(parent, type, guid, initializer) if type == "Selectors": return SelectorsOwner(parent, type, guid, initializer) return DummyObject(parent, type, guid, initializer)
def create_remote_object(parent: ChannelOwner, type: str, guid: str, initializer: Dict) -> Any: if type == "Artifact": return Artifact(parent, type, guid, initializer) if type == "BindingCall": return BindingCall(parent, type, guid, initializer) if type == "Browser": return Browser(cast(BrowserType, parent), type, guid, initializer) if type == "BrowserType": return BrowserType(parent, type, guid, initializer) if type == "BrowserContext": browser_name: str = "" if isinstance(parent, Browser): browser_name = parent._browser_type.name if isinstance(parent, BrowserType): browser_name = parent.name if browser_name == "chromium": return ChromiumBrowserContext(parent, type, guid, initializer) return BrowserContext(parent, type, guid, initializer) if type == "CDPSession": return CDPSession(parent, type, guid, initializer) if type == "ConsoleMessage": return ConsoleMessage(parent, type, guid, initializer) if type == "Dialog": return Dialog(parent, type, guid, initializer) if type == "ElementHandle": return ElementHandle(parent, type, guid, initializer) if type == "Frame": return Frame(parent, type, guid, initializer) if type == "JSHandle": return JSHandle(parent, type, guid, initializer) if type == "Page": return Page(parent, type, guid, initializer) if type == "Playwright": return Playwright(parent, type, guid, initializer) if type == "Request": return Request(parent, type, guid, initializer) if type == "Response": return Response(parent, type, guid, initializer) if type == "Route": return Route(parent, type, guid, initializer) if type == "Stream": return Stream(parent, type, guid, initializer) if type == "WebSocket": return WebSocket(parent, type, guid, initializer) if type == "Worker": return Worker(parent, type, guid, initializer) if type == "Selectors": return Selectors(parent, type, guid, initializer) return DummyObject(parent, type, guid, initializer)
def _on_page(self, page: Page) -> None: page._set_browser_context(self) self._pages.append(page) self.emit(BrowserContext.Events.Page, page)
async def verify_viewport(self, page: Page, width: int, height: int): assert page.viewport_size()["width"] == width assert page.viewport_size()["height"] == height assert await page.evaluate("window.innerWidth") == width assert await page.evaluate("window.innerHeight") == height
def __init__(self, page: Page, is_not: bool = False) -> None: super().__init__(page.locator(":root"), is_not) self._actual_page = page
async def verify_viewport(self, page: Page, width: int, height: int): assert cast(Tuple[int, int], page.viewport_size())[0] == width assert cast(Tuple[int, int], page.viewport_size())[1] == height assert await page.evaluate("window.innerWidth") == width assert await page.evaluate("window.innerHeight") == height
def _on_page(self, page: Page) -> None: print("ON PAGE ARRIVED") page._set_browser_context(self) self._pages.append(page) self.emit(BrowserContext.Events.Page, page)
def _on_page(self, page: Page) -> None: page._set_browser_context(self) self._pages.append(page) self.emit(BrowserContext.Events.Page, page) if page._opener and not page._opener.is_closed(): page._opener.emit(Page.Events.Popup, page)
def test_should_be_able_capture_pdf_without_path(page: Page): buffer = page.pdf() assert buffer
def test_should_be_able_to_save_pdf_file(page: Page, server, tmpdir: Path): output_file = tmpdir / "foo.png" page.pdf(path=str(output_file)) assert os.path.getsize(output_file) > 0