最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Playwright test fails when using waitForResponse - Stack Overflow

programmeradmin3浏览0评论

My playwright test never passes when I use the mand "page.waitForResponse". Although the API call is performed and can be seen in the network tab of chrome. I set the jest timeout to 30000, but this does not seem to be the issue.

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")
])
})

Network

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

Error

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

My playwright test never passes when I use the mand "page.waitForResponse". Although the API call is performed and can be seen in the network tab of chrome. I set the jest timeout to 30000, but this does not seem to be the issue.

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")
])
})

Network

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

Error

Async callback was not invoked within the 30000 ms timeout specified by jest.setTimeout.Error
Share Improve this question edited Jan 20, 2024 at 0:31 ggorlen 58k8 gold badges114 silver badges157 bronze badges asked May 26, 2021 at 10:02 vuvuvuvu 5,34818 gold badges59 silver badges90 bronze badges 1
  • The golden rule for Promise.all(): virtually never should any of the array elements have await in front of them--you want to pass the promises, not their resolved values, into the Promise.all array. You want to await the result of all the promises, one time, which is the await in front of Promise.all(). – ggorlen Commented Jan 20, 2024 at 0:29
Add a ment  | 

1 Answer 1

Reset to default 5

The problem might be in what you don't include in your question.

Typically, you have to start waiting for the response before the action that causes the call happens. Let's say that action is some click somewhere on the page, then you want to type:

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

Try this, it might be what will solve your problem.

发布评论

评论列表(0)

  1. 暂无评论