You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I never knew if it was waiting for the correct response, so I added code to ensure that it was receiving the correct response. This was not included anywhere in the documentation nor was it in the community. I'm hoping this will save some other people a lot of time.
I included the code on the page that needs updating, but my addition is one comment, and the code
response.request().method() === 'GET | POST | PUT | etc.' &&
which is in the waitForResponse() function.
Enjoy!
// Start waiting for response before clicking. Note no await.
const responsePromise = page.waitForResponse('https://example.com/resource');
await page.getByText('trigger response').click();
const response = await responsePromise;
// Alternative way with a predicate. Note no await.
// Specify the expected request method: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH, or custom method
const responsePromise = page.waitForResponse(response =>
response.request().method() === 'GET | POST | PUT | etc.' && response.url() === 'https://example.com' && response.status() === 200
);
await page.getByText('trigger response').click();
const response = await responsePromise;
The text was updated successfully, but these errors were encountered:
yury-s
added a commit
to yury-s/playwright
that referenced
this issue
May 10, 2024
Page(s)
https://playwright.dev/docs/api/class-page#page-wait-for-response
Description
I never knew if it was waiting for the correct response, so I added code to ensure that it was receiving the correct response. This was not included anywhere in the documentation nor was it in the community. I'm hoping this will save some other people a lot of time.
I included the code on the page that needs updating, but my addition is one comment, and the code
response.request().method() === 'GET | POST | PUT | etc.' &&
which is in the waitForResponse() function.
Enjoy!
The text was updated successfully, but these errors were encountered: