fix(types): add typed cb for Page.waitForResponse (#4575)

This commit is contained in:
Max Schmitt 2020-12-03 18:20:53 +01:00 committed by GitHub
parent 95c502d274
commit d2b7e0d1df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 9 deletions

View file

@ -2135,7 +2135,7 @@ await page.waitForRequest(request => request.url().searchParams.get('foo') === '
``` ```
#### page.waitForResponse(urlOrPredicate[, options]) #### page.waitForResponse(urlOrPredicate[, options])
- `urlOrPredicate` <[string]|[RegExp]|[Function]> Request URL string, regex or predicate receiving [Response] object. - `urlOrPredicate` <[string]|[RegExp]|[function]\([Response]\):[boolean]> Request URL string, regex or predicate receiving [Response] object.
- `options` <[Object]> Optional waiting parameters - `options` <[Object]> Optional waiting parameters
- `timeout` <[number]> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - `timeout` <[number]> Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
- returns: <[Promise]<[Response]>> Promise which resolves to the matched response. - returns: <[Promise]<[Response]>> Promise which resolves to the matched response.

View file

@ -26,7 +26,7 @@ type AssertNotAny<S> = {notRealProperty: number} extends S ? false : true;
await page.goto('https://example.com'); await page.goto('https://example.com');
await page.screenshot({ path: 'example.png' }); await page.screenshot({ path: 'example.png' });
browser.close(); await browser.close();
})(); })();
(async () => { (async () => {
@ -35,7 +35,7 @@ type AssertNotAny<S> = {notRealProperty: number} extends S ? false : true;
await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle' }); await page.goto('https://news.ycombinator.com', { waitUntil: 'networkidle' });
await page.pdf({ path: 'hn.pdf', format: 'A4' }); await page.pdf({ path: 'hn.pdf', format: 'A4' });
browser.close(); await browser.close();
})(); })();
(async () => { (async () => {
@ -54,7 +54,7 @@ type AssertNotAny<S> = {notRealProperty: number} extends S ? false : true;
console.log('Dimensions:', dimensions); console.log('Dimensions:', dimensions);
browser.close(); await browser.close();
})(); })();
// The following examples are taken from the docs itself // The following examples are taken from the docs itself
@ -105,7 +105,7 @@ playwright.chromium.launch().then(async browser => {
const myHash = await (window as any).md5(myString); const myHash = await (window as any).md5(myString);
console.log(`md5 of ${myString} is ${myHash}`); console.log(`md5 of ${myString} is ${myHash}`);
}); });
browser.close(); await browser.close();
page.on('console', console.log); page.on('console', console.log);
await page.exposeFunction('readfile', async (filePath: string) => { await page.exposeFunction('readfile', async (filePath: string) => {
@ -189,7 +189,7 @@ playwright.chromium.launch().then(async browser => {
page.on('dialog', async dialog => { page.on('dialog', async dialog => {
console.log(dialog.message()); console.log(dialog.message());
await dialog.dismiss(); await dialog.dismiss();
browser.close(); await browser.close();
}); });
const inputElement = (await page.$('input[type=submit]'))!; const inputElement = (await page.$('input[type=submit]'))!;
@ -214,7 +214,7 @@ playwright.chromium.launch().then(async browser => {
await page.goto('https://example.com'); await page.goto('https://example.com');
await page.screenshot({ path: 'example.png' }); await page.screenshot({ path: 'example.png' });
browser.close(); await browser.close();
})(); })();
// Test v0.12 features // Test v0.12 features
@ -315,7 +315,7 @@ playwright.chromium.launch().then(async browser => {
console.log(await resultHandle.jsonValue()); console.log(await resultHandle.jsonValue());
await resultHandle.dispose(); await resultHandle.dispose();
browser.close(); await browser.close();
})(); })();
// test $eval and $$eval // test $eval and $$eval
@ -384,7 +384,7 @@ playwright.chromium.launch().then(async browser => {
const assertion: AssertType<string, typeof value> = true; const assertion: AssertType<string, typeof value> = true;
} }
} }
browser.close(); await browser.close();
})(); })();
// waitForEvent // waitForEvent
@ -781,6 +781,18 @@ playwright.chromium.launch().then(async browser => {
.off('close', listener); .off('close', listener);
}); });
// waitForResponse callback predicate
(async () => {
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
await Promise.all([
page.waitForResponse(response => response.url().includes('example.com')),
page.goto('https://example.com')
]);
await browser.close();
})();
// exported types // exported types
import { import {
LaunchOptions, LaunchOptions,