Skip to main content

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

NameTypeDescription
urlStringThe page URL.
WaitOptsObjectPage waiting parameters. Optional, as are all its fields.

WaitOpts

NameTypeDescription
selectorString|String[]Selector(s) of element(s) that must exist on the loaded page.
predicate() => Promise<bool> | boolPredicate that returns true if the page is loaded. Executed in the browser context: waitUntil.
waitNetworkIdleBooleanIf true, waits for the completion of all network requests. Default is true. Only works in CDP browsers; ignored for others.
waitNetworkIdleTimeoutNumberTime (in milliseconds) after the completion of all network requests to consider the network idle. Default is 500.
failOnNetworkErrorBooleanWhether to throw an error on network errors. Default is true. Only works in CDP browsers; ignored for others.
shouldThrowError(match) => BooleanPredicate 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.
ignoreNetworkErrorsPatternsArray<String | RegExp>Patterns of resource URLs for which load success checks are ignored. Takes precedence over shouldThrowError.
timeoutNumberPage 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");
});