首页 > 解决方案 > 使用 waitForResponse 时剧作家测试失败

问题描述

当我使用命令“page.waitForResponse”时,我的编剧测试从未通过。虽然执行了 API 调用,并且可以在 chrome 的网络选项卡中看到。我将开玩笑超时设置为 30000,但这似乎不是问题。

it("Test", async () => {
  await page.goto("http://localhost:8080/")
 await Promise.all([
  await page.waitForResponse("https://development/my/call", {
    timeout: 1000,
  }),
  page.click("css=body")
])
})

网络

url: https://development/my/call
Status: 200
Type: xhr

错误

Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Error

标签: reactjsplaywright

解决方案


问题可能出在您的问题中未包含的内容中。

通常,您必须在导致调用的操作发生之前开始等待响应。假设操作是在页面某处单击,然后您要键入:

await Promise.all([
    page.waitForResponse("http://localhost:8060/my/call"),
    page.click('.someButton'),
]);

试试这个,它可能会解决你的问题。


推荐阅读