1
1
from abc import ABC , abstractmethod
2
+ import pathlib
2
3
import re
3
- from typing import Any , List , Literal , Optional , Union
4
+ from typing import Any , List , Literal , Optional , Sequence , Union
4
5
from uuid import uuid4
5
6
import os
6
7
from loguru import logger
11
12
FileChooser ,
12
13
Download ,
13
14
Error ,
15
+ FilePayload ,
14
16
)
15
17
from dendrite .sync_api ._api .dto .authenticate_dto import AuthenticateDTO
16
18
from dendrite .sync_api ._api .dto .upload_auth_session_dto import UploadAuthSessionDTO
@@ -333,11 +335,11 @@ def _get_active_page_manager(self) -> PageManager:
333
335
Exception: If there is an issue launching the browser or retrieving the PageManager.
334
336
"""
335
337
if not self ._active_page_manager :
336
- _ , _ , active_page_manager = self ._launch ()
338
+ ( _ , _ , active_page_manager ) = self ._launch ()
337
339
return active_page_manager
338
340
return self ._active_page_manager
339
341
340
- def _get_download (self , pw_page : PlaywrightPage , timeout : float ) -> Download :
342
+ def get_download (self , pw_page : PlaywrightPage , timeout : float ) -> Download :
341
343
"""
342
344
Retrieves the download event from the browser.
343
345
@@ -349,6 +351,32 @@ def _get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
349
351
"""
350
352
return self ._impl .get_download (self , pw_page , timeout )
351
353
354
+ def upload_files (
355
+ self ,
356
+ files : Union [
357
+ str ,
358
+ pathlib .Path ,
359
+ FilePayload ,
360
+ Sequence [Union [str , pathlib .Path ]],
361
+ Sequence [FilePayload ],
362
+ ],
363
+ timeout : float = 30000 ,
364
+ ) -> None :
365
+ """
366
+ Uploads files to the active page using a file chooser.
367
+
368
+ Args:
369
+ files (Union[str, pathlib.Path, FilePayload, Sequence[Union[str, pathlib.Path]], Sequence[FilePayload]]): The file(s) to be uploaded.
370
+ This can be a file path, a `FilePayload` object, or a sequence of file paths or `FilePayload` objects.
371
+ timeout (float, optional): The maximum amount of time (in milliseconds) to wait for the file chooser to be ready. Defaults to 30.
372
+
373
+ Returns:
374
+ None
375
+ """
376
+ page = self .get_active_page ()
377
+ file_chooser = self ._get_filechooser (page .playwright_page , timeout )
378
+ file_chooser .set_files (files )
379
+
352
380
def _get_filechooser (
353
381
self , pw_page : PlaywrightPage , timeout : float = 30000
354
382
) -> FileChooser :
0 commit comments