Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
    def __init__(self, parent: ChannelOwner, type: str, guid: str,
                 initializer: Dict) -> None:
        super().__init__(parent, type, guid, initializer)
        self.request = APIRequest(self)
        self.chromium = from_channel(initializer["chromium"])
        self.chromium._playwright = self
        self.firefox = from_channel(initializer["firefox"])
        self.firefox._playwright = self
        self.webkit = from_channel(initializer["webkit"])
        self.webkit._playwright = self

        self.selectors = Selectors(self._loop)
        selectors_owner: SelectorsOwner = from_channel(
            initializer["selectors"])
        self.selectors._add_channel(selectors_owner)

        self._connection.on(
            "close", lambda: self.selectors._remove_channel(selectors_owner))
        self.devices = {}
        self.devices = {
            device["name"]: parse_device_descriptor(device["descriptor"])
            for device in initializer["deviceDescriptors"]
        }
        self._utils: LocalUtils = from_channel(initializer["utils"])
Ejemplo n.º 3
0
class Playwright(ChannelOwner):
    devices: Dict
    selectors: Selectors
    chromium: BrowserType
    firefox: BrowserType
    webkit: BrowserType
    request: APIRequest

    def __init__(self, parent: ChannelOwner, type: str, guid: str,
                 initializer: Dict) -> None:
        super().__init__(parent, type, guid, initializer)
        self.request = APIRequest(self)
        self.chromium = from_channel(initializer["chromium"])
        self.chromium._playwright = self
        self.firefox = from_channel(initializer["firefox"])
        self.firefox._playwright = self
        self.webkit = from_channel(initializer["webkit"])
        self.webkit._playwright = self

        self.selectors = Selectors(self._loop)
        selectors_owner: SelectorsOwner = from_channel(
            initializer["selectors"])
        self.selectors._add_channel(selectors_owner)

        self._connection.on(
            "close", lambda: self.selectors._remove_channel(selectors_owner))
        self.devices = {}
        self.devices = {
            device["name"]: parse_device_descriptor(device["descriptor"])
            for device in initializer["deviceDescriptors"]
        }
        self._utils: LocalUtils = from_channel(initializer["utils"])

    def __getitem__(self, value: str) -> "BrowserType":
        if value == "chromium":
            return self.chromium
        elif value == "firefox":
            return self.firefox
        elif value == "webkit":
            return self.webkit
        raise ValueError("Invalid browser " + value)

    def _set_selectors(self, selectors: SelectorsOwner) -> None:
        selectors_owner = from_channel(self._initializer["selectors"])
        self.selectors._remove_channel(selectors_owner)
        self.selectors = selectors
        self.selectors._add_channel(selectors_owner)

    def stop(self) -> None:
        pass