_playwright.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) Microsoft Corporation.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Dict
  15. from playwright._impl._browser_type import BrowserType
  16. from playwright._impl._connection import ChannelOwner, from_channel
  17. from playwright._impl._fetch import APIRequest
  18. from playwright._impl._selectors import Selectors
  19. class Playwright(ChannelOwner):
  20. devices: Dict
  21. selectors: Selectors
  22. chromium: BrowserType
  23. firefox: BrowserType
  24. webkit: BrowserType
  25. request: APIRequest
  26. def __init__(
  27. self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
  28. ) -> None:
  29. super().__init__(parent, type, guid, initializer)
  30. self.request = APIRequest(self)
  31. self.chromium = from_channel(initializer["chromium"])
  32. self.chromium._playwright = self
  33. self.firefox = from_channel(initializer["firefox"])
  34. self.firefox._playwright = self
  35. self.webkit = from_channel(initializer["webkit"])
  36. self.webkit._playwright = self
  37. self.selectors = Selectors(self._loop, self._dispatcher_fiber)
  38. self.devices = self._connection.local_utils.devices
  39. def __getitem__(self, value: str) -> "BrowserType":
  40. if value == "chromium":
  41. return self.chromium
  42. elif value == "firefox":
  43. return self.firefox
  44. elif value == "webkit":
  45. return self.webkit
  46. raise ValueError("Invalid browser " + value)
  47. def _set_selectors(self, selectors: Selectors) -> None:
  48. self.selectors = selectors
  49. async def stop(self) -> None:
  50. pass