From 25022e46856b0be0676830cdc84200d40594a1cb Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 13 Feb 2020 14:18:18 -0800 Subject: [PATCH] feat(api): introduce default timeouts on BrowserContext (#992) --- docs/api.md | 121 ++++++++++++++++++++++------------------ src/browserContext.ts | 11 ++++ src/page.ts | 2 +- src/timeoutSettings.ts | 11 +++- test/navigation.spec.js | 22 ++++++++ 5 files changed, 111 insertions(+), 56 deletions(-) diff --git a/docs/api.md b/docs/api.md index 5af1c4165e..c7ab0a6b7e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -268,6 +268,8 @@ await context.close(); - [browserContext.newPage()](#browsercontextnewpage) - [browserContext.pages()](#browsercontextpages) - [browserContext.setCookies(cookies)](#browsercontextsetcookiescookies) +- [browserContext.setDefaultNavigationTimeout(timeout)](#browsercontextsetdefaultnavigationtimeouttimeout) +- [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) - [browserContext.setGeolocation(geolocation)](#browsercontextsetgeolocationgeolocation) - [browserContext.setPermissions(origin, permissions[])](#browsercontextsetpermissionsorigin-permissions) @@ -350,6 +352,27 @@ An array of all pages inside the browser context. await browserContext.setCookies([cookieObject1, cookieObject2]); ``` +#### browserContext.setDefaultNavigationTimeout(timeout) +- `timeout` <[number]> Maximum navigation time in milliseconds + +This setting will change the default maximum navigation time for the following methods and related shortcuts: +- [page.goBack([options])](#pagegobackoptions) +- [page.goForward([options])](#pagegoforwardoptions) +- [page.goto(url[, options])](#pagegotourl-options) +- [page.reload([options])](#pagereloadoptions) +- [page.setContent(html[, options])](#pagesetcontenthtml-options) +- [page.waitForLoadState([options])](#pagewaitforloadstateoptions) +- [page.waitForNavigation([options])](#pagewaitfornavigationoptions) + +> **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout) and [`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) take priority over [`browserContext.setDefaultNavigationTimeout`](#browsercontextsetdefaultnavigationtimeouttimeout). + +#### browserContext.setDefaultTimeout(timeout) +- `timeout` <[number]> Maximum time in milliseconds + +This setting will change the default maximum time for all the methods accepting `timeout` option. + +> **NOTE** [`page.setDefaultNavigationTimeout`](#pagesetdefaultnavigationtimeouttimeout), [`page.setDefaultTimeout`](#pagesetdefaulttimeouttimeout) and [`browserContext.setDefaultNavigationTimeout`](#browsercontextsetdefaultnavigationtimeouttimeout) take priority over [`browserContext.setDefaultTimeout`](#browserContextsetdefaulttimeouttimeout). + #### browserContext.setGeolocation(geolocation) - `geolocation` <[Object]> - `latitude` <[number]> Latitude between -90 and 90. @@ -682,7 +705,7 @@ Shortcut for [page.mainFrame().$eval(selector, pageFunction)](#frameevalselector - `selector` <[string]> A selector of an element to wait for - `options` <[Object]> - `visibility` <"visible"|"hidden"|"any"> Wait for element to become visible (`visible`), hidden (`hidden`), present in dom (`any`). Defaults to `any`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. + - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - returns: <[Promise]> Promise which resolves when element specified by selector string is added to DOM. Resolves to `null` if waiting for `hidden: true` and selector is not found in DOM. Wait for the `selector` to appear in page. If at the moment of calling @@ -737,7 +760,7 @@ To disable authentication, pass `null`. - `selector` <[string]> A selector to search for checkbox or radio button to check. If there are multiple elements satisfying the selector, the first will be checked. - `options` <[Object]> - `waitFor` <"visible"|"hidden"|"any"|"nowait"> Wait for element to become visible (`visible`), hidden (`hidden`), present in dom (`any`) or do not wait at all (`nowait`). Defaults to `visible`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. + - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully checked. The Promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector`, if element is not already checked, it scrolls it into view if needed, and then uses [page.click](#pageclickselector-options) to click in the center of the element. @@ -756,7 +779,7 @@ Shortcut for [page.mainFrame().check(selector[, options])](#framecheckselector-o - y <[number]> - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - `waitFor` <"visible"|"hidden"|"any"|"nowait"> Wait for element to become visible (`visible`), hidden (`hidden`), present in dom (`any`) or do not wait at all (`nowait`). Defaults to `visible`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. + - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully clicked. The Promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to click in the center of the element. @@ -812,7 +835,7 @@ Get the browser context that the page belongs to. - y <[number]> - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the double click, and then restores current modifiers back. If not specified, currently pressed modifiers are used. - `waitFor` <"visible"|"hidden"|"any"|"nowait"> Wait for element to become visible (`visible`), hidden (`hidden`), present in dom (`any`) or do not wait at all (`nowait`). Defaults to `visible`. - - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) method. + - `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully double clicked. The Promise will be rejected if there is no element matching `selector`. This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to double click in the center of the element. @@ -1010,7 +1033,7 @@ const fs = require('fs'); - `value` <[string]> Value to fill for the ``, `