|
15 | 15 | import sys |
16 | 16 | import typing |
17 | 17 |
|
18 | | -from playwright.sync_base import SyncBase, mapping |
| 18 | +from playwright.sync_base import EventContextManager, SyncBase, mapping |
19 | 19 |
|
20 | 20 | if sys.version_info >= (3, 8): # pragma: no cover |
21 | 21 | from typing import Literal |
|
31 | 31 | from playwright.dialog import Dialog as DialogAsync |
32 | 32 | from playwright.download import Download as DownloadAsync |
33 | 33 | from playwright.element_handle import ElementHandle as ElementHandleAsync |
| 34 | +from playwright.file_chooser import FileChooser as FileChooserAsync |
34 | 35 | from playwright.frame import Frame as FrameAsync |
35 | 36 | from playwright.helper import ( |
36 | 37 | ConsoleMessageLocation, |
@@ -770,6 +771,67 @@ def snapshot( |
770 | 771 | mapping.register(AccessibilityAsync, Accessibility) |
771 | 772 |
|
772 | 773 |
|
| 774 | +class FileChooser(SyncBase): |
| 775 | + def __init__(self, obj: FileChooserAsync): |
| 776 | + super().__init__(obj) |
| 777 | + |
| 778 | + def as_async(self) -> FileChooserAsync: |
| 779 | + return self._async_obj |
| 780 | + |
| 781 | + @classmethod |
| 782 | + def _from_async(cls, obj: FileChooserAsync) -> "FileChooser": |
| 783 | + if not obj._sync_owner: |
| 784 | + obj._sync_owner = cls(obj) |
| 785 | + return obj._sync_owner |
| 786 | + |
| 787 | + @classmethod |
| 788 | + def _from_async_nullable( |
| 789 | + cls, obj: FileChooserAsync = None |
| 790 | + ) -> typing.Optional["FileChooser"]: |
| 791 | + return FileChooser._from_async(obj) if obj else None |
| 792 | + |
| 793 | + @classmethod |
| 794 | + def _from_async_list( |
| 795 | + cls, items: typing.List[FileChooserAsync] |
| 796 | + ) -> typing.List["FileChooser"]: |
| 797 | + return list(map(lambda a: FileChooser._from_async(a), items)) |
| 798 | + |
| 799 | + @classmethod |
| 800 | + def _from_async_dict( |
| 801 | + cls, map: typing.Dict[str, FileChooserAsync] |
| 802 | + ) -> typing.Dict[str, "FileChooser"]: |
| 803 | + return {name: FileChooser._from_async(value) for name, value in map.items()} |
| 804 | + |
| 805 | + @property |
| 806 | + def page(self) -> "Page": |
| 807 | + return Page._from_async(self._async_obj.page) |
| 808 | + |
| 809 | + @property |
| 810 | + def element(self) -> "ElementHandle": |
| 811 | + return ElementHandle._from_async(self._async_obj.element) |
| 812 | + |
| 813 | + @property |
| 814 | + def isMultiple(self) -> bool: |
| 815 | + return self._async_obj.isMultiple |
| 816 | + |
| 817 | + def setFiles( |
| 818 | + self, |
| 819 | + files: typing.Union[ |
| 820 | + str, FilePayload, typing.List[str], typing.List[FilePayload] |
| 821 | + ], |
| 822 | + timeout: int = None, |
| 823 | + noWaitAfter: bool = None, |
| 824 | + ) -> NoneType: |
| 825 | + return self._sync( |
| 826 | + self._async_obj.setFiles( |
| 827 | + files=files, timeout=timeout, noWaitAfter=noWaitAfter |
| 828 | + ) |
| 829 | + ) |
| 830 | + |
| 831 | + |
| 832 | +mapping.register(FileChooserAsync, FileChooser) |
| 833 | + |
| 834 | + |
773 | 835 | class Frame(SyncBase): |
774 | 836 | def __init__(self, obj: FrameAsync): |
775 | 837 | super().__init__(obj) |
@@ -2119,6 +2181,62 @@ def pdf( |
2119 | 2181 | ) |
2120 | 2182 | ) |
2121 | 2183 |
|
| 2184 | + def expect_console_message( |
| 2185 | + self, |
| 2186 | + predicate: typing.Union[typing.Callable[["ConsoleMessage"], bool]] = None, |
| 2187 | + timeout: int = None, |
| 2188 | + ) -> EventContextManager["ConsoleMessage"]: |
| 2189 | + return EventContextManager(self, "console", predicate, timeout) |
| 2190 | + |
| 2191 | + def expect_dialog( |
| 2192 | + self, |
| 2193 | + predicate: typing.Union[typing.Callable[["Dialog"], bool]] = None, |
| 2194 | + timeout: int = None, |
| 2195 | + ) -> EventContextManager["Dialog"]: |
| 2196 | + return EventContextManager(self, "dialog", predicate, timeout) |
| 2197 | + |
| 2198 | + def expect_download( |
| 2199 | + self, |
| 2200 | + predicate: typing.Union[typing.Callable[["Download"], bool]] = None, |
| 2201 | + timeout: int = None, |
| 2202 | + ) -> EventContextManager["Download"]: |
| 2203 | + return EventContextManager(self, "download", predicate, timeout) |
| 2204 | + |
| 2205 | + def expect_file_chooser( |
| 2206 | + self, |
| 2207 | + predicate: typing.Union[typing.Callable[["FileChooser"], bool]] = None, |
| 2208 | + timeout: int = None, |
| 2209 | + ) -> EventContextManager["FileChooser"]: |
| 2210 | + return EventContextManager(self, "filechooser", predicate, timeout) |
| 2211 | + |
| 2212 | + def expect_request( |
| 2213 | + self, |
| 2214 | + predicate: typing.Union[typing.Callable[["Request"], bool]] = None, |
| 2215 | + timeout: int = None, |
| 2216 | + ) -> EventContextManager["Request"]: |
| 2217 | + return EventContextManager(self, "request", predicate, timeout) |
| 2218 | + |
| 2219 | + def expect_response( |
| 2220 | + self, |
| 2221 | + predicate: typing.Union[typing.Callable[["Response"], bool]] = None, |
| 2222 | + timeout: int = None, |
| 2223 | + ) -> EventContextManager["Response"]: |
| 2224 | + return EventContextManager(self, "response", predicate, timeout) |
| 2225 | + |
| 2226 | + def expect_popup( |
| 2227 | + self, |
| 2228 | + predicate: typing.Union[typing.Callable[["Page"], bool]] = None, |
| 2229 | + timeout: int = None, |
| 2230 | + ) -> EventContextManager["Page"]: |
| 2231 | + return EventContextManager(self, "popup", predicate, timeout) |
| 2232 | + |
| 2233 | + def expect_worker( |
| 2234 | + self, |
| 2235 | + predicate: typing.Union[typing.Callable[["Worker"], bool]] = None, |
| 2236 | + timeout: int = None, |
| 2237 | + ) -> EventContextManager["Worker"]: |
| 2238 | + return EventContextManager(self, "worker", predicate, timeout) |
| 2239 | + |
2122 | 2240 |
|
2123 | 2241 | mapping.register(PageAsync, Page) |
2124 | 2242 |
|
@@ -2244,6 +2362,13 @@ def waitForEvent( |
2244 | 2362 | def close(self) -> NoneType: |
2245 | 2363 | return self._sync(self._async_obj.close()) |
2246 | 2364 |
|
| 2365 | + def expect_page( |
| 2366 | + self, |
| 2367 | + predicate: typing.Union[typing.Callable[["Page"], bool]] = None, |
| 2368 | + timeout: int = None, |
| 2369 | + ) -> EventContextManager["Page"]: |
| 2370 | + return EventContextManager(self, "page", predicate, timeout) |
| 2371 | + |
2247 | 2372 |
|
2248 | 2373 | mapping.register(BrowserContextAsync, BrowserContext) |
2249 | 2374 |
|
|
0 commit comments