【问题标题】:Python - Playwright timeoutPython - 剧作家超时
【发布时间】:2022-12-22 23:07:49
【问题描述】:

我正在使用 Playwright 上传文件并下载结果。当输入文件很大,并且处理时间很长时,我会从剧作家那里得到超时; “下载”按钮出现需要很长时间。

    raise exception
playwright._impl._api_types.TimeoutError: Timeout 30000.0ms exceeded while waiting for event "download"
=========================== logs ===========================
waiting for event "download"
============================================================

我怎样才能让剧作家在那个特定事件上等待更长时间?

with page.expect_download() as download_info:
    page.locator("text=Download").click()
    #todo: wait longer?
download = download_info.value
# expect(page).to_have_url("http://localhost:8080/swagger/#/NER/post_ner")
path = download.path()
suggested_filename = file_out
download.save_as(suggested_filename)

【问题讨论】:

    标签: python playwright webautomation playwright-python


    【解决方案1】:

    如果你知道 click 需要一段时间,你可以设置超时:

    page.locator("text=Download").click(timeout=60000)
    

    【讨论】:

    • 另外,请记住超时以毫秒为单位。
    • 我试过这个:age.locator("text=Download").click(timeout=120000),但它被忽略了。我收到相同的错误消息:playwright._impl._api_types.TimeoutError:等待事件“下载”时超出超时 30000.0ms 这有效:page.set_default_timeout(timeout=120000)
    【解决方案2】:

    如果您不担心超时时间过长,也可以将超时设置为 0。虽然这可能会导致它可能需要几个小时……或者如果它卡在加载中就永远不会结束。超时值不是 0 可能是最佳实践。

    page.locator("text=Download").click(timeout=0)

    【讨论】:

    • 我试过了,也被忽略了。感谢您的回复。
    【解决方案3】:

    您必须在 playwright.config.ts 中设置超时

    https://playwright.dev/docs/test-configuration

    const config: PlaywrightTestConfig = {
        testDir: './tests',
        /* Maximum time one test can run for. */
        timeout: 40 * 1000
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 2021-12-28
      • 2022-12-10
      • 1970-01-01
      • 1970-01-01
      • 2022-06-21
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      相关资源
      最近更新 更多