microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
64.05k stars 3.47k forks source link

[Bug]: expect_download doesn't resume after download #30106

Closed lielurbanico closed 3 months ago

lielurbanico commented 3 months ago

Version

1.40.0

Steps to reproduce

Example steps (replace with your own):

  1. Open a dynamically-generated pdf in a new popup window with playwright (chromium)
  2. Within expect_download, click the download button through page.mouse.click(x, y)
  3. You should see the error come up

Expected behavior

I was expecting my code to resume after the file is downloaded.

Actual behavior

My code freezes as expect_download doesn't resolve after the file is fully downloaded.

Additional context

Example code:

pdf_button = self.page.query_selector(f'[id=my_pdf_id]')

if pdf_button:
    with self.page.expect_popup() as new_page_info:
        pdf_button.click(modifiers=["Alt", ])

    new_page = new_page_info.value
    new_page.set_viewport_size({"width": 480, "height": 720})

    with self.page.expect_download() as download_info:
        sleep(1)
        new_page.mouse.click(x=363, y=15)
        sleep(1)

    download_info.value.save_as(f"{self.dir}/my_pdf.pdf")
    new_page.close()
    sleep(1)

expect_popup works well and indeed, new_page contains the new page that opens up. However, after I use expect_download, it click the download button (I must use coordinates due to other unrelated issues, but with headful view, I can see that the download button is indeed clicked), but the program does not resume.

image

Environment

- Operating System: [Windows 11]
- CPU: [i7-10510U]
- Browser: [Chromium]
- Python Version: [3.9.18]
- Other info:
pavelfeldman commented 3 months ago

Please follow the bug template to file something we can reproduce locally.

kinopop commented 3 months ago

Your problem should be the same as mine, probably because your download method is post, expect_download, which only recognizes get types.