openAndWait
Overview
Use the openAndWait
command to open a page and wait for it to load (based on a combination of specified factors).
Functions for waiting for network idle and failing on network errors are only available when using browsers that support Chrome DevTools Protocol (CDP).
Usage
await browser.openAndWait("some/url", {
selector: [".some", ".selector"],
predicate: () => document.isReady,
ignoreNetworkErrorsPatterns: ["https://mc.yandex.ru", "https://avatars.mds.yandex.net/*"],
waitNetworkIdle: true,
waitNetworkIdleTimeout: 500,
failOnNetworkError: true,
timeout: 20000,
});
Command Parameters
Name | Type | Description |
url | String | The page URL. |
WaitOpts | Object | Page waiting parameters. Optional, as are all its fields. |
WaitOpts
Name | Type | Description |
selector | String|String[] | Selector(s) of element(s) that must exist on the loaded page. |
predicate | () => Promise<bool> | bool | Predicate that returns true if the page is loaded. Executed in the browser context: waitUntil. |
waitNetworkIdle | Boolean | If true , waits for the completion of all network requests. Default is true . Only works in CDP browsers; ignored for others. |
waitNetworkIdleTimeout | Number | Time (in milliseconds) after the completion of all network requests to consider the network idle. Default is 500. |
failOnNetworkError | Boolean | Whether to throw an error on network errors. Default is true . Only works in CDP browsers; ignored for others. |
shouldThrowError | (match) => Boolean | Predicate that should return true by Match if the network error is considered critical for proper page loading. By default, returns true for images, styles, and fonts. |
ignoreNetworkErrorsPatterns | Array<String | RegExp> | Patterns of resource URLs for which load success checks are ignored. Takes precedence over shouldThrowError . |
timeout | Number | Page load timeout. By default, the pageLoadTimeout value is used. An exception is thrown if selectors still do not exist or the predicate still resolves to false after the time has elapsed. |
Usage Examples
it("some test", async ({ browser }) => {
// With `waitNetworkIdle` also wait for loading images, fonts, styles, ignoring metric errors
await browser.openAndWait("some/url", {
selector: [".selector"],
predicate: () => document.isReady,
ignoreNetworkErrorsPatterns: ["https://mc.yandex.ru"],
waitNetworkIdle: true,
waitNetworkIdleTimeout: 500,
failOnNetworkError: true,
timeout: 20000,
});
await browser.assertView("plain", ".selector");
});