Skip to content

Commit 111a1a0

Browse files
authored
Den 447 Fix download for browser (#87)
1 parent 82c2567 commit 111a1a0

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

dendrite/async_api/_core/dendrite_browser.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ async def _get_active_page_manager(self) -> PageManager:
376376

377377
return self._active_page_manager
378378

379-
async def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
379+
async def get_download(self, timeout: float) -> Download:
380380
"""
381381
Retrieves the download event from the browser.
382382
@@ -386,7 +386,21 @@ async def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Downloa
386386
Raises:
387387
Exception: If there is an issue retrieving the download event.
388388
"""
389-
return await self._impl.get_download(self, pw_page, timeout)
389+
active_page = await self.get_active_page()
390+
pw_page = active_page.playwright_page
391+
return await self._get_download(pw_page, timeout)
392+
393+
async def _get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
394+
"""
395+
Retrieves the download event from the browser.
396+
397+
Returns:
398+
Download: The download event.
399+
400+
Raises:
401+
Exception: If there is an issue retrieving the download event.
402+
"""
403+
return await self._download_handler.get_data(pw_page, timeout=timeout)
390404

391405
async def upload_files(
392406
self,

dendrite/async_api/_core/dendrite_element.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ async def click(
183183
start_time = time.time()
184184
await page.playwright_page.wait_for_load_state("load", timeout=2000)
185185
wait_duration = time.time() - start_time
186-
print(f"Waited {wait_duration:.2f} seconds for load state")
186+
# print(f"Waited {wait_duration:.2f} seconds for load state")
187187
except Exception as e:
188-
print(f"Page navigated but failed to wait for load state: {e}")
188+
pass
189+
# print(f"Page navigated but failed to wait for load state: {e}")
189190

190191
return InteractionResponse(status="success", message="")
191192

dendrite/async_api/_core/dendrite_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async def get_download(self, timeout: float = 30000) -> Download:
153153
Returns:
154154
The downloaded file data.
155155
"""
156-
return await self.dendrite_browser.get_download(self.playwright_page, timeout)
156+
return await self.dendrite_browser._get_download(self.playwright_page, timeout)
157157

158158
def _get_context(self, element: Any) -> Union[PlaywrightPage, FrameLocator]:
159159
"""

dendrite/sync_api/_core/dendrite_browser.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _get_active_page_manager(self) -> PageManager:
339339
return active_page_manager
340340
return self._active_page_manager
341341

342-
def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
342+
def get_download(self, timeout: float) -> Download:
343343
"""
344344
Retrieves the download event from the browser.
345345
@@ -349,7 +349,21 @@ def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
349349
Raises:
350350
Exception: If there is an issue retrieving the download event.
351351
"""
352-
return self._impl.get_download(self, pw_page, timeout)
352+
active_page = self.get_active_page()
353+
pw_page = active_page.playwright_page
354+
return self._get_download(pw_page, timeout)
355+
356+
def _get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
357+
"""
358+
Retrieves the download event from the browser.
359+
360+
Returns:
361+
Download: The download event.
362+
363+
Raises:
364+
Exception: If there is an issue retrieving the download event.
365+
"""
366+
return self._download_handler.get_data(pw_page, timeout=timeout)
353367

354368
def upload_files(
355369
self,

dendrite/sync_api/_core/dendrite_element.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ def click(
153153
start_time = time.time()
154154
page.playwright_page.wait_for_load_state("load", timeout=2000)
155155
wait_duration = time.time() - start_time
156-
print(f"Waited {wait_duration:.2f} seconds for load state")
157156
except Exception as e:
158-
print(f"Page navigated but failed to wait for load state: {e}")
157+
pass
159158
return InteractionResponse(status="success", message="")
160159

161160
@perform_action("fill")

dendrite/sync_api/_core/dendrite_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_download(self, timeout: float = 30000) -> Download:
123123
Returns:
124124
The downloaded file data.
125125
"""
126-
return self.dendrite_browser.get_download(self.playwright_page, timeout)
126+
return self.dendrite_browser._get_download(self.playwright_page, timeout)
127127

128128
def _get_context(self, element: Any) -> Union[PlaywrightPage, FrameLocator]:
129129
"""

0 commit comments

Comments
 (0)