Skip to content

Commit

Permalink
Den 447 Fix download for browser (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffecup25 authored Nov 7, 2024
1 parent 82c2567 commit 111a1a0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
18 changes: 16 additions & 2 deletions dendrite/async_api/_core/dendrite_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ async def _get_active_page_manager(self) -> PageManager:

return self._active_page_manager

async def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
async def get_download(self, timeout: float) -> Download:
"""
Retrieves the download event from the browser.
Expand All @@ -386,7 +386,21 @@ async def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Downloa
Raises:
Exception: If there is an issue retrieving the download event.
"""
return await self._impl.get_download(self, pw_page, timeout)
active_page = await self.get_active_page()
pw_page = active_page.playwright_page
return await self._get_download(pw_page, timeout)

async def _get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
"""
Retrieves the download event from the browser.
Returns:
Download: The download event.
Raises:
Exception: If there is an issue retrieving the download event.
"""
return await self._download_handler.get_data(pw_page, timeout=timeout)

async def upload_files(
self,
Expand Down
5 changes: 3 additions & 2 deletions dendrite/async_api/_core/dendrite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ async def click(
start_time = time.time()
await page.playwright_page.wait_for_load_state("load", timeout=2000)
wait_duration = time.time() - start_time
print(f"Waited {wait_duration:.2f} seconds for load state")
# print(f"Waited {wait_duration:.2f} seconds for load state")
except Exception as e:
print(f"Page navigated but failed to wait for load state: {e}")
pass
# print(f"Page navigated but failed to wait for load state: {e}")

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

Expand Down
2 changes: 1 addition & 1 deletion dendrite/async_api/_core/dendrite_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async def get_download(self, timeout: float = 30000) -> Download:
Returns:
The downloaded file data.
"""
return await self.dendrite_browser.get_download(self.playwright_page, timeout)
return await self.dendrite_browser._get_download(self.playwright_page, timeout)

def _get_context(self, element: Any) -> Union[PlaywrightPage, FrameLocator]:
"""
Expand Down
18 changes: 16 additions & 2 deletions dendrite/sync_api/_core/dendrite_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _get_active_page_manager(self) -> PageManager:
return active_page_manager
return self._active_page_manager

def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
def get_download(self, timeout: float) -> Download:
"""
Retrieves the download event from the browser.
Expand All @@ -349,7 +349,21 @@ def get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
Raises:
Exception: If there is an issue retrieving the download event.
"""
return self._impl.get_download(self, pw_page, timeout)
active_page = self.get_active_page()
pw_page = active_page.playwright_page
return self._get_download(pw_page, timeout)

def _get_download(self, pw_page: PlaywrightPage, timeout: float) -> Download:
"""
Retrieves the download event from the browser.
Returns:
Download: The download event.
Raises:
Exception: If there is an issue retrieving the download event.
"""
return self._download_handler.get_data(pw_page, timeout=timeout)

def upload_files(
self,
Expand Down
3 changes: 1 addition & 2 deletions dendrite/sync_api/_core/dendrite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ def click(
start_time = time.time()
page.playwright_page.wait_for_load_state("load", timeout=2000)
wait_duration = time.time() - start_time
print(f"Waited {wait_duration:.2f} seconds for load state")
except Exception as e:
print(f"Page navigated but failed to wait for load state: {e}")
pass
return InteractionResponse(status="success", message="")

@perform_action("fill")
Expand Down
2 changes: 1 addition & 1 deletion dendrite/sync_api/_core/dendrite_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_download(self, timeout: float = 30000) -> Download:
Returns:
The downloaded file data.
"""
return self.dendrite_browser.get_download(self.playwright_page, timeout)
return self.dendrite_browser._get_download(self.playwright_page, timeout)

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

0 comments on commit 111a1a0

Please sign in to comment.