_dialog.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 TYPE_CHECKING, Dict, Optional
  15. from playwright._impl._connection import ChannelOwner, from_nullable_channel
  16. from playwright._impl._helper import locals_to_params
  17. if TYPE_CHECKING: # pragma: no cover
  18. from playwright._impl._page import Page
  19. class Dialog(ChannelOwner):
  20. def __init__(
  21. self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
  22. ) -> None:
  23. super().__init__(parent, type, guid, initializer)
  24. self._page: Optional["Page"] = from_nullable_channel(initializer.get("page"))
  25. def __repr__(self) -> str:
  26. return f"<Dialog type={self.type} message={self.message} default_value={self.default_value}>"
  27. @property
  28. def type(self) -> str:
  29. return self._initializer["type"]
  30. @property
  31. def message(self) -> str:
  32. return self._initializer["message"]
  33. @property
  34. def default_value(self) -> str:
  35. return self._initializer["defaultValue"]
  36. @property
  37. def page(self) -> Optional["Page"]:
  38. return self._page
  39. async def accept(self, promptText: str = None) -> None:
  40. await self._channel.send("accept", None, locals_to_params(locals()))
  41. async def dismiss(self) -> None:
  42. await self._channel.send(
  43. "dismiss",
  44. None,
  45. )