docs: waitForResponse method predicate example

Fixes https://github.com/microsoft/playwright/issues/30731
This commit is contained in:
Yury Semikhatsky 2024-05-09 17:26:57 -07:00
parent a50cd30519
commit a2496e951d
2 changed files with 6 additions and 6 deletions

View file

@ -4879,7 +4879,7 @@ const response = await responsePromise;
// Alternative way with a predicate. Note no await.
const responsePromise = page.waitForResponse(response =>
response.url() === 'https://example.com' && response.status() === 200
response.url() === 'https://example.com' && response.status() === 200 && response.request().method() === 'GET'
);
await page.getByText('trigger response').click();
const response = await responsePromise;
@ -4893,7 +4893,7 @@ Response response = page.waitForResponse("https://example.com/resource", () -> {
});
// Waits for the next response matching some conditions
Response response = page.waitForResponse(response -> "https://example.com".equals(response.url()) && response.status() == 200, () -> {
Response response = page.waitForResponse(response -> "https://example.com".equals(response.url()) && response.status() == 200 && "GET".equals(response.request().method()), () -> {
// Triggers the response
page.getByText("trigger response").click();
});
@ -4906,7 +4906,7 @@ response = await response_info.value
return response.ok
# or with a lambda
async with page.expect_response(lambda response: response.url == "https://example.com" and response.status == 200) as response_info:
async with page.expect_response(lambda response: response.url == "https://example.com" and response.status == 200 and response.request.method == "get") as response_info:
await page.get_by_text("trigger response").click()
response = await response_info.value
return response.ok
@ -4919,7 +4919,7 @@ response = response_info.value
return response.ok
# or with a lambda
with page.expect_response(lambda response: response.url == "https://example.com" and response.status == 200) as response_info:
with page.expect_response(lambda response: response.url == "https://example.com" and response.status == 200 and response.request.method == "get") as response_info:
page.get_by_text("trigger response").click()
response = response_info.value
return response.ok
@ -4936,7 +4936,7 @@ await page.RunAndWaitForResponseAsync(async () =>
await page.RunAndWaitForResponseAsync(async () =>
{
await page.GetByText("trigger response").ClickAsync();
}, response => response.Url == "https://example.com" && response.Status == 200);
}, response => response.Url == "https://example.com" && response.Status == 200 && response.Request.Method == "GET");
```
## async method: Page.waitForResponse

View file

@ -4768,7 +4768,7 @@ export interface Page {
*
* // Alternative way with a predicate. Note no await.
* const responsePromise = page.waitForResponse(response =>
* response.url() === 'https://example.com' && response.status() === 200
* response.url() === 'https://example.com' && response.status() === 200 && response.request().method() === 'GET'
* );
* await page.getByText('trigger response').click();
* const response = await responsePromise;