/// /** * Represents event-specific properties. Refer to the events documentation for * the lists of initial properties: * - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent) * - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent) * - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent) * - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent) * - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent) * - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent) * - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event) */ export type EvaluationArgument = object; export type PageFunction = string | ((arg: Unboxed) => R); export type PageFunctionOn = string | ((on: On, arg2: Unboxed) => R); export type Unboxed = Arg extends [infer A0, infer A1] ? [Unboxed, Unboxed] : Arg extends [infer A0, infer A1, infer A2] ? [Unboxed, Unboxed, Unboxed] : Arg extends [infer A0, infer A1, infer A2, infer A3] ? [Unboxed, Unboxed, Unboxed, Unboxed] : Arg extends Array ? Array> : Arg extends object ? { [Key in keyof Arg]: Unboxed } : Arg; /** * CPUProfile is the mandatory input to be passed into {@link Page}'s * `throttleCPU` method. */ export interface CPUProfile { /** * rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc). */ rate: number; } /** * NetworkProfile is the mandatory input to be passed into {@link Page}'s * `throttleNetwork` method. */ export interface NetworkProfile { /** * Minimum latency from request sent to response headers received (ms). */ latency: number; /** * Maximal aggregated download throughput (bytes/sec). -1 disables download * throttling. */ download: number; /** * Maximal aggregated upload throughput (bytes/sec). -1 disables upload * throttling. */ upload: number; } export interface SelectOptionsObject { /** * Matches by `option.value`. */ value?: string; /** * Matches by `option.label`. */ label?: string; /** * Matches by the index. */ index?: number; } export type ResourceType = | "document" | "stylesheet" | "image" | "media" | "font" | "script" | "texttrack" | "xhr" | "fetch" | "eventsource" | "websocket" | "manifest" | "other"; export type MouseButton = "left" | "right" | "middle"; export type KeyboardModifier = "Alt" | "Control" | "Meta" | "Shift"; export type ElementState = "attached" | "detached" | "visible" | "hidden"; export type InputElementState = ElementState | "enabled" | "disabled" | "editable"; export type LifecycleEvent = "load" | "domcontentloaded" | "networkidle"; export interface TimeoutOptions { /** * Maximum time in milliseconds. Pass 0 to disable the timeout. Default is overridden by the setDefaultTimeout option on `BrowserContext` or `Page`. * Defaults to 30000. */ timeout?: number; } export interface StrictnessOptions { /** * When `true`, the call requires selector to resolve to a single element. * If given selector resolves to more than one element, the call throws * an exception. Defaults to `false`. */ strict?: boolean; } export interface EventSequenceOptions { /** * Delay between events in milliseconds. Defaults to 0. */ delay?: number; } export interface File { /** * File name */ name: string; /** * File type */ mimeType: string; /** * File content */ buffer: ArrayBuffer; } export type ElementHandleOptions = { /** * Setting this to `true` will bypass the actionability checks (visible, * stable, enabled). Defaults to `false`. */ force?: boolean; /** * If set to `true` and a navigation occurs from performing this action, it will not wait for it to complete. * Defaults to `false`. */ noWaitAfter?: boolean; } & TimeoutOptions; export type ElementHandlePointerOptions = ElementHandleOptions & { /** * Setting this to `true` will perform the actionability checks without * performing the action. Useful to wait until the element is ready for the * action without performing it. Defaults to `false`. */ trial?: boolean; }; export type ElementClickOptions = ElementHandlePointerOptions & { /** * A point to use relative to the top left corner of the element. If not supplied, * a visible point of the element is used. */ position?: { x: number; y: number }; }; export type FrameCheckOptions = ElementClickOptions; export interface KeyboardModifierOptions { /** * `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the action. * If not specified, currently pressed modifiers are used. */ modifiers?: KeyboardModifier[]; } export type KeyboardPressOptions = & { /** * If set to `true` and a navigation occurs from performing this action, it * will not wait for it to complete. Defaults to `false`. */ noWaitAfter?: boolean; } & EventSequenceOptions & TimeoutOptions; export type MouseMoveOptions = ElementClickOptions & KeyboardModifierOptions; export type MouseClickOptions = { /** * The mouse button to use during the action. * Defaults to `left`. */ button?: MouseButton; } & EventSequenceOptions; export type MouseMultiClickOptions = MouseClickOptions & { /** * The number of times the action is performed. * Defaults to 1. */ clickCount?: number; }; export interface MouseDownUpOptions { /** * The mouse button to use during the action. * Defaults to `left`. */ button?: MouseButton; /** * Defaults to 1. */ clickCount?: number; } export type ContentLoadOptions = { /** * When to consider operation succeeded, defaults to `load`. Events can be * either: * - `'domcontentloaded'` - consider operation to be finished when the * `DOMContentLoaded` event is fired. * - `'load'` - consider operation to be finished when the `load` event is * fired. * - `'networkidle'` - **DISCOURAGED** consider operation to be finished * when there are no network connections for at least `500` ms. Don't use * this method for testing especially with chatty websites where the event * may never fire, rely on web assertions to assess readiness instead. */ waitUntil?: LifecycleEvent; } & TimeoutOptions; export type NavigationOptions = { /** * Referer header value. */ referer?: string; } & ContentLoadOptions; export interface ResourceTiming { /** * Request start time in milliseconds elapsed since January 1, 1970 00:00:00 UTC */ startTime: number; /** * Time immediately before the browser starts the domain name lookup for the resource. * The value is given in milliseconds relative to `startTime`, -1 if not available. */ domainLookupStart: number; /** * Time immediately after the browser ends the domain name lookup for the resource. * The value is given in milliseconds relative to `startTime`, -1 if not available. */ domainLookupEnd: number; /** * Time immediately before the user agent starts establishing the connection to the server * to retrieve the resource. The value is given in milliseconds relative to `startTime`, * -1 if not available. */ connectStart: number; /** * Time immediately before the browser starts the handshake process to secure the current * connection. The value is given in milliseconds relative to `startTime`, -1 if not available. */ secureConnectionStart: number; /** * Time immediately after the user agent establishes the connection to the server * to retrieve the resource. The value is given in milliseconds relative to `startTime`, * -1 if not available. */ connectEnd: number; /** * Time immediately before the browser starts requesting the resource from the server, * cache, or local resource. The value is given in milliseconds relative to `startTime`, * -1 if not available. */ requestStart: number; /** * Time immediately after the browser receives the first byte of the response from the server, * cache, or local resource. The value is given in milliseconds relative to `startTime`, * -1 if not available. */ responseStart: number; /** * Time immediately after the browser receives the last byte of the resource or immediately * before the transport connection is closed, whichever comes first. The value is given * in milliseconds relative to `startTime`, -1 if not available. */ responseEnd: number; } export interface SecurityDetailsObject { /** * Common Name component of the Issuer field. The value is extracted from the * certificate. This should only be used for informational purposes. */ issuer?: string; /** * The specific TLS protocol used. For example `TLS 1.3`. */ protocol?: string; /** * Common Name component of the Subject field. The value is extracted from the * certificate. This should only be used for informational purposes. */ subjectName?: string; /** * Unix timestamp (in seconds) specifying the exact date/time when this cert * becomes valid. */ validFrom?: number; /** * Unix timestamp (in seconds) specifying the exact date/time when this cert * becomes invalid. */ validTo?: number; /** * String with hex encoded SHA256 fingerprint of the certificate. The value is * extracted from the certificate. */ sanList?: string[]; } export interface Rect { /** * The x coordinate of the element in pixels. * (0, 0) is the top left corner of the viewport. */ x: number; /** * The y coordinate of the element in pixels. * (0, 0) is the top left corner of the viewport. */ y: number; /** * The width of the element in pixels. */ width: number; /** * The height of the element in pixels. */ height: number; } export type ImageFormat = "jpeg" | "png"; export interface ScreenshotOptions { /** * The file path to save the image to. The screenshot type will be inferred from file extension. */ path?: string; /** * The screenshot format. * @default 'png' */ type?: ImageFormat; /** * Hide default white background and allow capturing screenshots with transparency. * Not applicable to `jpeg` images. * @default false */ omitBackground?: boolean; /** * The quality of the image, between 0-100. Not applicable to `png` images. * @default 100 */ quality?: number; } /** * Methods to periodically check for a value. * - `raf` - use `requestAnimationFrame` callback to poll * - `mutation` - use a mutation observer * - `interval` - use a polling interval */ export type PollingMethod = number | "raf" | "mutation"; export interface PollingOptions { /** * If `polling` is `'raf'`, then `pageFunction` is constantly executed in * `requestAnimationFrame` callback. If the `polling` is `'mutation'` it * will be called when a change is made to the DOM tree. If `polling` is * a number, then it is treated as an interval in milliseconds at which * the function would be executed. Defaults to `raf`. */ polling?: PollingMethod; } export interface ElementStateFilter { /** * The element state to filter for. * @default 'visible' */ state?: ElementState; } /** * The `devices` named export defines emulation settings for many end-user * devices that can be used to simulate browser behavior on a mobile device. * * @example * ```js * import { browser, devices } from 'k6/browser'; * ... // redacted * const iphoneX = devices['iPhone X']; * const context = await browser.newContext(iphoneX); * ... // redacted * ``` */ export const devices: Record< | "Blackberry PlayBook" | "Blackberry PlayBook landscape" | "BlackBerry Z30" | "BlackBerry Z30 landscape" | "Galaxy Note 3" | "Galaxy Note 3 landscape" | "Galaxy Note II" | "Galaxy Note II landscape" | "Galaxy S III" | "Galaxy S III landscape" | "Galaxy S5" | "Galaxy S5 landscape" | "iPad" | "iPad landscape" | "iPad Mini" | "iPad Mini landscape" | "iPad Pro" | "iPad Pro landscape" | "iPhone 4" | "iPhone 4 landscape" | "iPhone 5" | "iPhone 5 landscape" | "iPhone 6" | "iPhone 6 landscape" | "iPhone 6 Plus" | "iPhone 6 Plus landscape" | "iPhone 7" | "iPhone 7 landscape" | "iPhone 7 Plus" | "iPhone 7 Plus landscape" | "iPhone 8" | "iPhone 8 landscape" | "iPhone 8 Plus" | "iPhone 8 Plus landscape" | "iPhone SE" | "iPhone SE landscape" | "iPhone X" | "iPhone X landscape" | "iPhone XR" | "iPhone XR landscape" | "JioPhone 2" | "JioPhone 2 landscape" | "Kindle Fire HDX" | "Kindle Fire HDX landscape" | "LG Optimus L70" | "LG Optimus L70 landscape" | "Microsoft Lumia 550" | "Microsoft Lumia 950" | "Microsoft Lumia 950 landscape" | "Nexus 10" | "Nexus 10 landscape" | "Nexus 4" | "Nexus 4 landscape" | "Nexus 5" | "Nexus 5 landscape" | "Nexus 5X" | "Nexus 5X landscape" | "Nexus 6" | "Nexus 6 landscape" | "Nexus 6P" | "Nexus 6P landscape" | "Nexus 7" | "Nexus 7 landscape" | "Nokia Lumia 520" | "Nokia Lumia 520 landscape" | "Nokia N9" | "Nokia N9 landscape" | "Pixel 2" | "Pixel 2 landscape" | "Pixel 2 XL" | "Pixel 2 XL landscape", Device >; /** * Device represents an end-user device (computer, tablet, phone etc.). */ export interface Device { /** * Name of the device. */ name: string; /** * User agent of the device. */ userAgent: string; /** * Viewport size of the device. */ viewport: { /** * page width in pixels. */ width: number; /** * page height in pixels. */ height: number; }; /** * Device viewport scale factor. */ deviceScaleFactor: number; /** * Indicates whether the device is a mobile device. */ isMobile: boolean; /** * Indicates whether the device support touch events. */ hasTouch: boolean; } /** * BrowserPermissions defines all the possible permissions that can be granted * to the browser application. */ export type BrowserPermissions = | "geolocation" | "midi" | "midi-sysex" | "notifications" | "camera" | "microphone" | "background-sync" | "ambient-light-sensor" | "accelerometer" | "gyroscope" | "magnetometer" | "accessibility-events" | "clipboard-read" | "clipboard-write" | "payment-handler"; export interface NewBrowserContextOptions { /** * Setting this to `true` will bypass a page's Content-Security-Policy. * Defaults to `false`. */ bypassCSP?: boolean; /** * Emulates `'prefers-colors-scheme'` media feature, supported values * are `'light'`, `'dark'`, and `'no-preference'`. Default to * `'light'`. */ colorScheme?: "light" | "dark" | "no-preference"; /** * Sets the resolution ratio in physical pixels to the resolution in * CSS pixels i.e. if set higher than 1, then images will look * sharper on high pixel density screens. Defaults to 1. */ deviceScaleFactor?: number; /** * Contains additional HTTP headers to be sent with every request, * where the keys are HTTP headers and values are HTTP header * values. Defaults to null. */ extraHTTPHeaders?: { [key: string]: string }; /** * Sets the user's geographical location. Defaults to null. */ geolocation?: { /** * latitude should be between -90 and 90. */ latitude: number; /** * longitude should be between -180 and 180. */ longitude: number; /** * accuracy should only be a non-negative number. Defaults to 0. */ accuracy: number; }; /** * Whether to simulate a device with touch events. Defaults to * `false`. */ hasTouch?: boolean; /** * Sets the credentials for HTTP authentication using Basic Auth. */ httpCredentials?: { username: string; password: string; }; /** * Whether to ignore HTTPS errors that may be caused by invalid * certificates. Defaults to `false`. */ ignoreHTTPSErrors?: boolean; /** * Whether to simulate a mobile device. Defaults to `false`. */ isMobile?: boolean; /** * Whether to activate JavaScript support for the context. Defaults * to `false`. */ javaScriptEnabled?: boolean; /** * Specifies the user's locale following ICU locale (e.g. 'en_US'). * Defaults to host system locale. */ locale?: string; /** * Whether to emulate an offline network. Defaults to `false`. */ offline?: boolean; /** * Permissions to grant for the context's pages. Defaults to * null. */ permissions?: BrowserPermissions[]; /** * Minimizes the amount of motion by emulating the * 'prefers-reduced-motion' media feature. Defaults to * `'no-preference'`. */ reducedMotion?: "reduce" | "no-preference"; /** * Sets a window screen size for all pages in the context. It can * only be used when the viewport is set. Defaults to * `{'width': 1280, 'height': 720}`. */ screen?: { /** * Page width in pixels. */ width: number; /** * Page height in pixels. */ height: number; }; /** * Changes the context's timezone. See ICU's metaZones.txt for a * list of supported timezone IDs. Defaults to what is set on the * system. */ timezoneID?: string; /** * Specifies the user agent to use in the context. Defaults to what * is set on the by the browser. */ userAgent?: string; /** * Sets a viewport size for all pages in the context. null disables * the default viewport. Defaults to `{'width': 1280, 'height': 720}`. */ viewport?: { /** * Page width in pixels. */ width: number; /** * Page height in pixels. */ height: number; }; } /** * The `browser` named export is the entry point for all your tests, * it interacts with the actual web browser via Chrome DevTools Protocol (CDP). */ export const browser: Browser; /** * The `chromium` named export allows attaching to an already running * Chromium-based browser over the Chrome DevTools Protocol (CDP), instead of * relying on the browser instance that k6 launches and manages for you. */ export const chromium: BrowserType; /** * `BrowserType` is the entry point to connect to an existing Chromium-based * browser. */ export interface BrowserType { /** * Attaches to an already running Chromium-based browser over the Chrome * DevTools Protocol (CDP), and returns the corresponding `Browser` * instance. * * The returned `Browser` is closed automatically at the end of the * iteration. Use {@link ConnectedBrowser.close | close} to release the * connection earlier. * * **Usage** * * ```js * const browser = await chromium.connectOverCDP('ws://localhost:9222/devtools/browser/'); * const page = await browser.newPage(); * * try { * await page.goto('https://quickpizza.grafana.com/'); * } finally { * await page.close(); * await browser.close(); * } * ``` * * @param wsEndpoint The WebSocket endpoint of the browser to attach to, * e.g. 'ws://localhost:9222/devtools/browser/'. */ connectOverCDP(wsEndpoint: string): Promise; } /** * `ConnectedBrowser` represents a web browser instance that k6 attached to over * the Chrome DevTools Protocol (CDP), rather than launched itself. * * On top of the `Browser` API, it exposes a `close` method, since the * connection is user managed and can be released on demand. */ export interface ConnectedBrowser extends Browser { /** * Closes the connection to the browser, and all of its `BrowserContext`s * and `Page`s. * * Calling this method is optional: the connection is closed automatically * at the end of the iteration. Closing an already closed `Browser` is a * no-op. */ close(): Promise; } /** * `Browser` represents the main web browser instance. */ export interface Browser { /** * Closes the current `BrowserContext`. If there is no active * `BrowserContext`, this method will throw an error. */ closeContext(): void; /** * Returns the current `BrowserContext`. There is a 1-to-1 mapping between * `Browser` and `BrowserContext`. If no `BrowserContext` has been * initialized, it will return null. */ context(): BrowserContext | null; /** * Indicates whether the CDP connection to the browser process is active or * not. */ isConnected(): boolean; /** * Creates and returns a new `BrowserContext` if one hasn't already been * initialized for the `Browser`. If one has already been initialized an * error is thrown. * * There is a 1-to-1 mapping between `Browser` and `BrowserContext`. Due to * this restriction, if one already exists, it must be closed first before * creating a new one. * @param options */ newContext( options?: NewBrowserContextOptions, ): Promise; /** * Creates and returns a new `Page` in a new `BrowserContext` if a * `BrowserContext` hasn't already been initialized for the `Browser`. If a * `BrowserContext` has already been initialized an error is thrown. * * There is a 1-to-1 mapping between `Browser` and `BrowserContext`. Due to * this restriction, if one already exists, it must be closed first before * creating a new one. * @param options */ newPage( options?: NewBrowserContextOptions, ): Promise; /** * Returns the browser application's user agent. */ userAgent(): string; /** * Returns the browser application's version. */ version(): string; } /** * `BrowserContext` provides a way to operate multiple independent sessions, with * separate pages, cache, and cookies. */ export interface BrowserContext { /** * Adds a script which will be evaluated in one of the following scenarios: * - Whenever a page is created in the browser context or is navigated. * - Whenever a child frame is attached or navigated in any page in the * browser context. In this case, the script is evaluated in the context * of the newly attached frame. * * The script is evaluated after the document is created but before any of * its scripts were run. This is useful to amend the JavaScript environment, * e.g. to override `Math.random`. * * **Usage** * * An example of overriding `Math.random` before the page loads: * * ```js * const browserContext = await browser.newContext(); * await browserContext.addInitScript("Math.random = function(){return 0}"); * * const page = await browserContext.newPage(); * await page.goto(url); * ``` * * @param script Script to be evaluated in all pages in the browser context. */ addInitScript(script: string | { content?: string }): Promise; /** * Returns the `Browser` instance that this `BrowserContext` belongs to. */ browser(): Browser; /** * Adds {@link Cookie | cookies} into this {@link BrowserContext}. * * @param cookies The {@link Cookie | cookies} to add to this {@link BrowserContext}. * @example * ```js * await context.addCookies([ * { name: 'foo', value: 'foovalue', sameSite: 'Lax', url: 'https://k6.io' }, * { name: 'bar', value: 'barvalue', sameSite: 'Strict', domain: 'test.k6.io', path: '/bar' }, * ]); * ``` */ addCookies(cookies: Cookie[]): Promise; /** * Clears the {@link Cookie | cookies} in this {@link BrowserContext}. * * @example * ```js * await context.addCookies([{ name: 'foo', value: 'bar', url: 'https://k6.io' }]); * context.cookies().length; // 1 * await context.clearCookies(); * context.cookies().length; // 0 * ``` */ clearCookies(): Promise; /** * Retrieves the {@link Cookie | cookies} in this {@link BrowserContext} filtered by provided URLs, * or all {@link Cookie | cookies} if no URLs are provided. * * @param urls URLs to filter {@link Cookie | cookies} by. * @example * ```js * // Get all cookies in the browser context * const cookies = await context.cookies(); * * // Get all cookies for the specified URLs * const cookies = await context.cookies('https://k6.io', 'https://test.k6.io'); * * // Get all cookies for the specified URLs and filter by name * const cookies = await context.cookies('https://k6.io', 'https://test.k6.io').filter(c => c.name === 'foo'); * ``` */ cookies(...urls: string[]): Promise; /** * Clears all permission overrides for the {@link BrowserContext}. * ```js * await context.clearPermissions(); * ``` */ clearPermissions(): Promise; /** * Close the `BrowserContext` and all its `Page`s. */ close(): Promise; /** * Grants specified permissions to the {@link BrowserContext}. * ```js * await context.grantPermissions(['geolocation']); * ``` */ grantPermissions( /** * A string array of permissions to grant. */ permissions: BrowserPermissions[], options?: { /** * The origin to grant permissions to, e.g. 'https://test.k6.com'. */ origin: string; }, ): Promise; /** * Creates a new `Page` in the `BrowserContext`. */ newPage(): Promise; /** * Returns a list of `Page`s that belongs to the `BrowserContext`. */ pages(): Page[]; /** * Sets the default navigation timeout in milliseconds. */ setDefaultNavigationTimeout( /** * The timeout in milliseconds. */ timeout: number, ): void; /** * Sets the default maximum timeout for all methods accepting a timeout * option in milliseconds. */ setDefaultTimeout( /** * The timeout in milliseconds. */ timeout: number, ): void; /** * Sets the `BrowserContext`'s geolocation. */ setGeolocation( geolocation?: { /** * latitude should be between -90 and 90. */ latitude: number; /** * longitude should be between -180 and 180. */ longitude: number; /** * accuracy should only be a non-negative number. Defaults to 0. */ accuracy: number; }, ): Promise; /** * Toggles the `BrowserContext`'s connectivity on/off. */ setOffline( /** * Whether to emulate the BrowserContext being disconnected (`true`) * or connected (`false`). Defaults to `false`. */ offline: boolean, ): Promise; /** * Waits for the event to fire and passes its value into the predicate * function. Currently the only supported event is 'page' which when used will * return the new {@link Page} that was created after `waitForEvent` was called. * * @example * ```js * // Call waitForEvent with a predicate which will return true once at least * // one page has been created. * const promise = context.waitForEvent("page", { * predicate: page => { * if (++counter >= 1) { * return true * } * * return false * } * }) * * // Now we create a page. * const page = await context.newPage() * * // Wait for the predicate to pass. * await promise * ``` */ waitForEvent( /** * Name of event to wait for. The only supported event is 'page'. If any * other value is used an error will be thrown. */ event: "page", /** * This is an optional argument. It can either be a predicate function or * an options object. */ optionsOrPredicate?: { /** * Optional function that will be called when the {@link Page} event is * emitted. The event data will be passed to it and it must return true * to continue. * * If {@link Page} is passed to predicate, this signals that a new page * has been created. */ predicate?: (page: Page) => boolean; /** * Maximum time to wait in milliseconds. Defaults to 30000 milliseconds or * the timeout set by setDefaultTimeout on the {@link BrowserContext}. */ timeout?: number; } | ((page: Page) => boolean), ): Promise; } /** * {@link ConsoleMessage} objects are dispatched by page via the * `page.on('console')` event. For each console message logged in the page, * k6 browser delivers it to the registered handlers. * * ```js * // Listen for all console log messages in the browser page and output them * // in the test logs * page.on('console', msg => console.log(msg.text())); * * // Listen for all console events and handle errors * page.on('console', msg => { * if (msg.type() === 'error') * console.log(`Error text: "${msg.text()}"`); * }); * * // Deconstruct console log arguments * await msg.args()[0].jsonValue(); // hello * await msg.args()[1].jsonValue(); // 42 * ``` */ export interface ConsoleMessage { /** * List of arguments passed to a `console` function call. See also * `page.on('console')`. */ args(): JSHandle[]; /** * The page that produced this console message, if any. */ page(): null | Page; /** * The text of the console message. */ text(): string; /** * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, * `'warning'`, `'dir'`, `'dirxml'`, `'table'`, `'trace'`, `'clear'`, * `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, * `'profile'`, `'profileEnd'`, `'count'`, `'timeEnd'`. */ type(): string; } /** * {@link MetricMessage} objects are dispatched by page via the * `page.on('metric')` event. For each metric that it measured and emitted for * the page, k6 browser delivers it to the registered handlers. * * ```js * // Listen for all metric messages in the page and call its tag method to * // tag matching URLs with the new tag name. * page.on('metric', (metric) => { * metric.tag({ * name: 'test', * matches: [ * {url: /^https:\/\/test\.k6\.io\/\?q=[0-9a-z]+$/, method: 'GET'}, * ] * }); * }); * ``` */ export interface MetricMessage { /** * tag will match the given `tagMatch.matches` with the current metric's URL * and name tags. When a match is found it will use `tagMatch.name` to replace * the existing URL and name tag values. * * Doing this helps group metrics with different URL and name tags that, in * fact, reference the same resource, allowing for correlation over time and * reducing the cardinality of the metrics. * @param tagMatch */ tag(tagMatch: { /** * The name value that replaces the current metric's URL and name * tag values, if a match is found. Required, and must not be an * empty string. */ name: string; /** * An array of objects containing the matchers which will be used * to match against the current metric's URL and name tags. * Required. */ matches: Array<{ /** * The regular expression used to find matches in the current * metric's URL and name tags. Required. */ url: RegExp; /** * Used to match the metric's method tag. It's optional, and when * it's not set it will group all metrics regardless of the method * tag. */ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD" | "TRACE" | "CONNECT"; }>; }): void; } /** * {@link Cookie} represents a cookie in a {@link BrowserContext}. * * @see * {@link BrowserContext} has methods to {@link BrowserContext.addCookies | add}, {@link BrowserContext.cookies | query} and {@link BrowserContext.clearCookies | clear} cookies. */ export interface Cookie { /** * The {@link Cookie | cookie}'s name. * * @defaultValue * The default is `''`. */ name: string; /** * The {@link Cookie | cookie}'s value. * * @defaultValue * The default is `''`. */ value: string; /** * The {@link Cookie | cookie}'s URL. * * Required unless one of {@link Cookie.domain | domain} or {@link Cookie.path | path} are specified. */ url?: string; /** * The {@link Cookie | cookie}'s domain. * * Required unless one of {@link Cookie.url | url} or {@link Cookie.path | path} are specified. */ domain?: string; /** * The {@link Cookie | cookie}'s path. * * Required unless one of {@link Cookie.url | url} or {@link Cookie.domain | domain} are specified. * * @defaultValue * The default is `'/'`. */ path?: string; /** * The {@link Cookie | cookie}'s expiration date as the number of seconds since the UNIX epoch. * * If omitted, the {@link Cookie | cookie} becomes a session cookie. * * @defaultValue * The default is `-1`, meaning a session cookie. */ expires?: number; /** * Whether the {@link Cookie | cookie} is http-only. * * @defaultValue * The default is `false`. */ httpOnly?: boolean; /** * Whether the {@link Cookie | cookie} is secure. * * @defaultValue * The default is `false`. */ secure?: boolean; /** * The {@link Cookie | cookie}'s same-site status. * * It can be one of `'Strict'`, `'Lax'`, or `'None'`. * * @defaultValue * The default is `'Lax'`. */ sameSite?: CookieSameSite; } /** * CookieSameSite represents the same-site status of a {@link Cookie | cookie}. * * @defaultValue * The default is `'Lax'`. */ export type CookieSameSite = "Strict" | "Lax" | "None"; /** * ElementHandle represents an in-page DOM element. */ export interface ElementHandle extends JSHandle { /** * Finds an element matching the specified selector in the `ElementHandle`'s subtree. * @param selector A selector to query element for. * @returns An `ElementHandle` pointing to the result element or `null`. */ $(selector: string): Promise; /** * Finds all elements matching the specified selector in the `ElementHandle`'s subtree. * @param selector A selector to query element for. * @returns A list of `ElementHandle`s pointing to the result elements. */ $$(selector: string): Promise; /** * This method returns the bounding box of the element. * @returns Element's bounding box. */ boundingBox(): Promise; /** * Checks the checkbox element. * @param options The options to use. */ check(options?: ElementClickOptions & StrictnessOptions): Promise; /** * Clicks the element. * @param options The options to use. * @returns A promise that resolves when the element is clicked. */ click( options?: { /** * The mouse button (`left`, `middle` or `right`) to use during the action. * Defaults to `left`. */ button?: MouseButton; /** * The number of times the action is performed. Defaults to `1`. */ clickCount?: number; /** * Milliseconds to wait between `mousedown` and `mouseup`. Defaults to `0`. */ delay?: number; /** * Setting this to `true` will bypass the actionability checks (`visible`, * `stable`, `enabled`). Defaults to `false`. */ force?: boolean; /** * `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the * action. If not specified, currently pressed modifiers are used, * otherwise defaults to `null`. */ modifiers?: KeyboardModifier[]; /** * If set to `true` and a navigation occurs from performing this action, it * will not wait for it to complete. Defaults to `false`. */ noWaitAfter?: boolean; /** * A point to use relative to the top left corner of the element. If not * supplied, a visible point of the element is used. */ position?: { x: number; y: number; }; /** * Maximum time in milliseconds. Defaults to `30` seconds. Default is * overridden by the `setDefaultTimeout` option on `BrowserContext` or * `page` methods. * * Setting the value to `0` will disable the timeout. */ timeout?: number; /** * Setting this to `true` will perform the actionability checks without * performing the action. Useful to wait until the element is ready for the * action without performing it. Defaults to `false`. */ trial?: boolean; }, ): Promise; /** * Get the content frame for element handles. * @returns The content frame handle of the element handle. */ contentFrame(): Promise; /** * Double clicks the element. * @param options The options to use. */ dblclick( options?: { /** * The mouse button (`left`, `middle` or `right`) to use during the action. * Defaults to `left`. */ button?: MouseButton; /** * Milliseconds to wait between `mousedown` and `mouseup`. Defaults to `0`. */ delay?: number; /** * Setting this to `true` will bypass the actionability checks (`visible`, * `stable`, `enabled`). Defaults to `false`. */ force?: boolean; /** * `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the * action. If not specified, currently pressed modifiers are used, * otherwise defaults to `null`. */ modifiers?: KeyboardModifier[]; /** * If set to `true` and a navigation occurs from performing this action, it * will not wait for it to complete. Defaults to `false`. */ noWaitAfter?: boolean; /** * A point to use relative to the top left corner of the element. If not * supplied, a visible point of the element is used. */ position?: { x: number; y: number; }; /** * Maximum time in milliseconds. Defaults to `30` seconds. Default is * overridden by the `setDefaultTimeout` option on `BrowserContext` or * `page` methods. * * Setting the value to `0` will disable the timeout. */ timeout?: number; /** * Setting this to `true` will perform the actionability checks without * performing the action. Useful to wait until the element is ready for the * action without performing it. Defaults to `false`. */ trial?: boolean; }, ): Promise; /** * Dispatches a DOM event to the element. * @param type DOM event type: `"click"` etc. * @param eventInit Optional event-specific initialization properties. * @param options */ dispatchEvent( type: string, eventInit?: EvaluationArgument, ): Promise; /** * Fill the `input` or `textarea` element with the provided `value`. * @param value Value to fill for the `input` or `textarea` element. * @param options Element handle options. */ fill(value: string, options?: ElementHandleOptions): Promise; /** * Focuses the element. */ focus(): Promise; /** * Fetch the element's attribute value. * @param name Attribute name to get the value for. * @returns Attribute value. */ getAttribute(name: string): Promise; /** * Scrolls element into view and hovers over its center point. * @param options Hover options. */ hover(options?: ElementClickOptions & KeyboardModifierOptions): Promise; /** * Returns the `element.innerHTML`. * @returns Element's innerHTML. */ innerHTML(): Promise; /** * Returns the `element.innerText`. * @returns Element's innerText. */ innerText(): Promise; /** * Returns `input.value` for the selected `input`, `textarea` or `select` element. * @returns The input value of the element. */ inputValue(options?: TimeoutOptions): Promise; /** * Checks if a checkbox or radio is checked. * @returns Whether the element is checked. */ isChecked(): Promise; /** * Checks if the element is disabled. * @returns Whether the element is disabled. */ isDisabled(): Promise; /** * Checks if the element is editable. * @returns Whether the element is editable. */ isEditable(): Promise; /** * Checks if the element is enabled. * @returns Whether the element is enabled. */ isEnabled(): Promise; /** * Checks if the element is hidden. * @returns Whether the element is hidden. */ isHidden(): Promise; /** * Checks if the element is visible. * @returns Whether the element is visible. */ isVisible(): Promise; /** * Returns the frame containing the given element. * @returns The frame that contains the element handle. */ ownerFrame(): Promise; /** * Focuses the element, and then uses `keyboard.down` and `keyboard.up` with the specified key. * @param key A keyboard key name or a single character to press. * @param options Keyboard press options. */ press(key: string, options?: KeyboardPressOptions): Promise; /** * This method scrolls element into view, if needed, and then captures a * screenshot of it. * @param options Screenshot options. * @returns An `ArrayBuffer` with the screenshot data. */ screenshot(options?: ScreenshotOptions & TimeoutOptions): Promise; /** * This method checks whether the element is actionable using provided options, and * then tries to scroll it into view, unless it is completely visible. * @param options Element handle options. */ scrollIntoViewIfNeeded(options?: ElementHandleOptions): Promise; /** * Select one or more options of a ``. * * @param text Text to locate the element by. * @param options Options to use. * @returns The locator to the element with the corresponding text content. */ getByText( text: string | RegExp, options?: { /** * Whether to find an exact match: case-sensitive and whole-string. * Default to false. Ignored when locating by a regular expression. * Note that exact match still trims whitespace. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding test ID. * Note that this method only supports the `data-testid` attribute. * * @example * HTML: * ```html * * ``` * * JavaScript: * ```js * const locator = frame.getByTestId('submit-button'); * * await locator.click(); * ``` * * @param testId The test ID of the element. * @returns The locator to the element with the corresponding test ID. */ getByTestId(testId: string | RegExp): Locator; /** * Returns {@link Locator} to the element with the corresponding placeholder text. * * @example * ```js * const locator = frame.getByPlaceholder('name@example.com'); * * await locator.fill('my.name@example.com'); * ``` * * @param placeholder The placeholder text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding placeholder text. */ getByPlaceholder( placeholder: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding title text. * * @example * ```js * const locator = frame.getByTitle('Information box'); * * await locator.click(); * ``` * * @param title The title text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding title text. */ getByTitle( title: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; } /** * FrameLocator makes it easier to locate elements within an `iframe` on the * page. `FrameLocator` are created by calling `page.locator(selector).contentFrame()`. * It works in the same way as `Locator` instances. */ export interface FrameLocator { /** * The method finds all elements matching the selector and creates a new * locator that matches all of them. This method can be used to further * refine the locator by chaining additional selectors. * * @example * ```js * const frame = page.frameLocator('iframe'); * const rows = frame.locator('table tr'); * const cell = rows.locator('.selected'); * * // Use with options to filter by text * const submitButton = frame.locator('button', { hasText: 'Submit' }); * ``` * * @param selector A selector to use when resolving DOM element. * @param options Options to use for filtering. * @returns The new locator. */ locator(selector: string, options?: LocatorOptions): Locator; /** * Returns {@link Locator} to the element with the corresponding role. * * @example * ```js * const locator = frameLocator.getByRole('button', { name: 'Pizza, Please!' }); * * await locator.click(); * ``` * * @param role The role of the element. * @param options Options to use. * @returns The locator to the element with the corresponding role. */ getByRole( role: | "alert" | "alertdialog" | "application" | "article" | "banner" | "blockquote" | "button" | "caption" | "cell" | "checkbox" | "code" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "dialog" | "directory" | "document" | "emphasis" | "feed" | "figure" | "form" | "generic" | "grid" | "gridcell" | "group" | "heading" | "img" | "insertion" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "meter" | "navigation" | "none" | "note" | "option" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "strong" | "subscript" | "superscript" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "time" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem", options?: { /** * Whether the accessible `options.name` should be checked exactly for equality. * * @defaultValue false */ exact?: boolean; /** * Whether to include elements that are normally excluded from the accessibility tree. * * @defaultValue false */ includeHidden?: boolean; /** * A number attribute that is traditionally used for headings h1-h6. */ level?: number; /** * An accessible name for the element, such as a text in a button or a label for an input. */ name?: string | RegExp; /** * A boolean attribute that can be used to indicate if a checkbox is checked or not. */ checked?: boolean; /** * A boolean attribute that can be used to indicate if an element is disabled or not. */ disabled?: boolean; /** * A boolean attribute that can be used to indicate if an element is expanded or not. */ expanded?: boolean; /** * A boolean attribute that can be used to indicate if an element is pressed or not. */ pressed?: boolean; /** * A boolean attribute that can be used to indicate if an element is selected or not. */ selected?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding alt text. * * @example * ```js * const locator = frameLocator.getByAltText('pizza'); * * await locator.click(); * ``` * * @param altText The alt text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding alt text. */ getByAltText( altText: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding label text. * * @example * ```js * const locator = frameLocator.getByLabel('Password'); * * await locator.fill('my-password'); * ``` * * @param label The label text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding label text. */ getByLabel( label: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Allows locating elements by their text content. Returns {@link Locator}. * * Consider the following DOM structure: * * ```html *
Hello world
*
Hello
* ``` * * You can locate by text substring, exact string, or a regular expression: * * @example * ```js * // Matches * frameLocator.getByText('world'); * * // Matches first
* frameLocator.getByText('Hello world'); * * // Matches second
* frameLocator.getByText('Hello', { exact: true }); * * // Matches both
s * frameLocator.getByText(/Hello/); * * // Matches second
* frameLocator.getByText(/^hello$/i); * ``` * * Matching by text always normalizes whitespace, even with exact match. For * example, it turns multiple spaces into one, turns line breaks into spaces * and ignores leading and trailing whitespace. * * Input elements of the type `button` and `submit` are matched by their * `value` instead of the text content. For example, locating by text * `"Log in"` matches ``. * * @param text Text to locate the element by. * @param options Options to use. * @returns The locator to the element with the corresponding text content. */ getByText( text: string | RegExp, options?: { /** * Whether to find an exact match: case-sensitive and whole-string. * Default to false. Ignored when locating by a regular expression. * Note that exact match still trims whitespace. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding test ID. * Note that this method only supports the `data-testid` attribute. * * @example * HTML: * ```html * * ``` * * JavaScript: * ```js * const locator = frameLocator.getByTestId('submit-button'); * * await locator.click(); * ``` * * @param testId The test ID of the element. * @returns The locator to the element with the corresponding test ID. */ getByTestId(testId: string | RegExp): Locator; /** * Returns {@link Locator} to the element with the corresponding placeholder text. * * @example * ```js * const locator = frameLocator.getByPlaceholder('name@example.com'); * * await locator.fill('my.name@example.com'); * ``` * * @param placeholder The placeholder text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding placeholder text. */ getByPlaceholder( placeholder: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding title text. * * @example * ```js * const locator = frameLocator.getByTitle('Information box'); * * await locator.click(); * ``` * * @param title The title text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding title text. */ getByTitle( title: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; } /** * JSHandle represents an in-page JavaScript object. */ export interface JSHandle { /** * Returns either `null` or the object handle itself, if the object handle is * an instance of `ElementHandle`. * @returns The ElementHandle if available. */ asElement(): Promise; /** * Stops referencing the element handle. */ dispose(): Promise; /** * Evaluates the page function and returns its return value. * This method passes this handle as the first argument to the page function. * @param pageFunction The function to be evaluated. * @param args The arguments to pass to the page function. * @returns The return value of `pageFunction`. */ evaluate(pageFunction: PageFunction, arg?: Arg): Promise; /** * Evaluates the page function and returns a `JSHandle`. * This method passes this handle as the first argument to the page function. * Unlike `evaluate`, `evaluateHandle` returns the value as a `JSHandle` * @param pageFunction The function to be evaluated. * @param args The arguments to pass to the page function. * @returns A JSHandle of the return value of `pageFunction`. */ evaluateHandle(pageFunction: PageFunction, arg?: Arg): Promise>; /** * Fetches a map with own property names of of the `JSHandle` with their values as * `JSHandle` instances. * @returns A map with property names as keys and `JSHandle` instances for the property values. */ getProperties(): Promise>; /** * Fetches a JSON representation of the object. * @returns A JSON representation of the object. */ jsonValue(): Promise; } /** * Keyboard provides an API for managing a virtual keyboard. */ export interface Keyboard { /** * Sends a key down message to a session target. * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values). * @param key Name of key to press, such as `ArrowLeft`. */ down(key: string): Promise; /** * Dispatches an `input` event with the given `text`. * This method does not emit `keyDown`, `keyUp` or `keyPress` events. * @param text Event text. */ insertText(text: string): Promise; /** * Sends a key press message to a session target. * A press message consists of successive key down and up messages. * @param key Sequence of keys to press. * @param options Specifies the typing options. */ press(key: string, options?: { delay?: number }): Promise; /** * Type sends a `press` message to a session target for each character in text. * It sends an insertText message if a character is not among * valid characters in the keyboard's layout. * Modifier keys `Shift`, `Control`, `Alt`, `Meta` are _not_ respected. * @param text A text to type into a focused element. * @param options Specifies the typing options. */ type(text: string, options?: { delay?: number }): Promise; /** * Sends a key up message to a session target. * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values). * @param key Name of key to release, such as `ArrowLeft`. */ up(key: string): Promise; } export interface LocatorOptions { /** * Matches only elements that contain the specified text. String or regular expression. */ hasText?: string | RegExp; /** * Matches only elements that do not contain the specified text. String or regular expression. */ hasNotText?: string | RegExp; } export interface LocatorFilterOptions { /** * Matches only elements that contain the specified text. String or regular expression. */ hasText?: string | RegExp; /** * Matches only elements that do not contain the specified text. String or regular expression. */ hasNotText?: string | RegExp; } /** * The Locator API makes it easier to work with dynamically changing elements. * Some of the benefits of using it over existing ways to locate an element * (e.g. Page.$()) include: * * - Helps with writing robust tests by finding an element even if the * underlying frame navigates. * - Makes it easier to work with dynamic web pages and SPAs built with Svelte, * React, Vue, etc. */ export interface Locator { /** * Returns an array of locators matching the selector. * * **Usage** * * ```js * // Select all options * for (const option of await page.locator('option').all()) * await option.click(); * ``` * * @returns Array of locators */ all(): Promise; /** * Returns the bounding box of the element that this locator points to. * * **Usage** * * ```js * const locator = page.locator('#my-element'); * const boundingBox = await locator.boundingBox(); * ``` * * @param options Options to use. * @returns The bounding box of the element, or null if the element is not visible. */ boundingBox(options?: TimeoutOptions): Promise; /** * Clears text boxes and input fields of any existing values. * * **Usage** * * ```js * // Clears the input field matching the selector. * page.locator('input[name="login"]').clear(); * ``` * * @param options Options to use. */ clear(options?: ElementHandleOptions): Promise; /** * Mouse click on the chosen element. * @param options Options to use. * @returns Promise which resolves when the element is successfully clicked. */ click(options?: MouseMoveOptions & MouseMultiClickOptions): Promise; /** * Returns a `FrameLocator` that can be used to locate elements within an * `iframe`. * @returns A `FrameLocator`. */ contentFrame(): FrameLocator; /** * Returns the number of elements matching the selector. * * **Usage** * * ```js * const count = await page.locator('input').count(); * ``` * * @returns Promise which resolves with the number of elements matching the selector. */ count(): Promise; /** * Mouse double click on the chosen element. * @param options Options to use. */ dblclick(options?: MouseMoveOptions & MouseMultiClickOptions): Promise; /** * Evaluates the page function and returns its return value. * This method passes this locator's matching element as the first argument to the page function. * * @param pageFunction Function to be evaluated in the page context. * @param arg Optional argument to pass to `pageFunction`. * @returns Return value of `pageFunction`. */ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics evaluate( pageFunction: PageFunctionOn, arg?: Arg, ): Promise; /** * Evaluates the page function and returns its return value as a [JSHandle]. * This method passes this locator's matching element as the first argument to the page function. * Unlike `evaluate`, `evaluateHandle` returns the value as a `JSHandle` * * @param pageFunction Function to be evaluated in the page context. * @param arg Optional argument to pass to `pageFunction`. * @returns JSHandle of the return value of `pageFunction`. */ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics evaluateHandle( pageFunction: PageFunctionOn, arg?: Arg, ): Promise>; /** * Use this method to select an `input type="checkbox"`. * @param options Options to use. */ check(options?: ElementClickOptions): Promise; /** * Use this method to unselect an `input type="checkbox"`. * @param options Options to use. */ uncheck(options?: ElementClickOptions): Promise; /** * Checks to see if the `input type="checkbox"` is selected or not. * @param options Options to use. * @returns `true` if the element is checked, `false` otherwise. */ isChecked(options?: TimeoutOptions): Promise; /** * Checks if the element is editable. * @param options Options to use. * @returns `true` if the element is editable, `false` otherwise. */ isEditable(options?: TimeoutOptions): Promise; /** * Checks if the element is `enabled`. * @param options Options to use. * @returns `true` if the element is enabled, `false` otherwise. */ isEnabled(options?: TimeoutOptions): Promise; /** * Checks if the element is `disabled`. * @param options Options to use. * @returns `true` if the element is disabled, `false` otherwise. */ isDisabled(options?: TimeoutOptions): Promise; /** * Checks if the element is `visible`. * @returns `true` if the element is visible, `false` otherwise. */ isVisible(): Promise; /** * Checks if the element is `hidden`. * @returns `true` if the element is hidden, `false` otherwise. */ isHidden(): Promise; /** * Fill an `input`, `textarea` or `contenteditable` element with the provided value. * @param value Value to fill for the `input` or `textarea` element. * @param options Options to use. */ fill(value: string, options?: ElementHandleOptions): Promise; /** * Returns locator to the first matching element. * * **Usage** * * ```js * const firstRow = await page.locator('tr').first(); * ``` * * @returns Locator. */ first(): Locator; /** * Focuses the element using locator's selector. * @param options Options to use. */ focus(options?: TimeoutOptions): Promise; /** * Returns the element attribute value for the given attribute name. * @param name Attribute name to retrieve value for. * @param options Options to use. * @returns Attribute value. */ getAttribute(name: string, options?: TimeoutOptions): Promise; /** * Returns the `element.innerHTML`. * @param options Options to use. * @returns Element's innerHTML. */ innerHTML(options?: TimeoutOptions): Promise; /** * Returns the `element.innerText`. * @param options Options to use. * @returns Element's innerText. */ innerText(options?: TimeoutOptions): Promise; /** * Returns the `element.textContent`. * @param options Options to use. * @returns Element's textContent. */ textContent(options?: TimeoutOptions): Promise; /** * Returns `input.value` for the selected `input`, `textarea` or `select` element. * @param options Options to use. * @returns The input value of the element. */ inputValue(options?: TimeoutOptions): Promise; /** * Returns locator to the last matching element. * * **Usage** * * ```js * const lastRow = await page.locator('tr').last(); * ``` * * @returns Locator. */ last(): Locator; /** * The method finds all elements matching the selector and creates a new * locator that matches all of them. This method can be used to further * refine the locator by chaining additional selectors. * * @example * ```js * const rows = page.locator('table tr'); * const cell = rows.locator('.selected'); * * // Use with options to filter * const orangeButton = fruitsSection.locator('button', { hasText: 'Add to Cart' }); * ``` * * @param selector A selector to use when resolving DOM element. * @param options Options to use for filtering. * @returns The new locator. */ locator(selector: string, options?: LocatorOptions): Locator; /** * Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element. * * **Usage** * * ```js * const secondRow = await page.locator('tr').nth(1); * ``` * * @param index * @returns Locator */ nth(index: number): Locator; /** * Select one or more options which match the values. If the select has the multiple attribute, all matching options are selected, * otherwise only the first option matching one of the passed options is selected. * * @example * ```js * // Single selection matching the value or label * locator.selectOption('blue'); * * // single selection matching the label * locator.selectOption({ label: 'Blue' }); * * // multiple selection * locator.selectOption(['red', 'green', 'blue']); * ``` * * @param values Values of options to select. * @param options Options to use. * @returns List of selected options. */ selectOption( values: string | string[] | { value?: string; label?: string; index?: number }, options?: ElementHandleOptions, ): Promise; /** * Checks or unchecks the input checkbox element. * @param checked Whether to check or uncheck the element. * @param options Options to customize the check action. * @returns A promise that resolves when the element is checked or unchecked. */ setChecked(checked: boolean, options?: FrameCheckOptions): Promise; /** * Press a single key on the keyboard or a combination of keys. * A superset of the key values can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values). * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. * @param options Keyboard press options. */ press(key: string, options?: KeyboardPressOptions): Promise; /** * Focuses the element and then sends a `keydown`, `keypress`/`input`, and * `keyup` event for each character in the text. * * This method is useful for simulating real user typing behavior when the page * has special keyboard event handling, such as input validation or autocomplete. * For simple text input without special keyboard handling, use {@link fill | fill()} * instead as it's faster and more reliable. * * @example * ```js * // Type text instantly * await locator.pressSequentially('Hello World'); * * // Type text with delay between keypresses (like a real user) * await locator.pressSequentially('Hello World', { delay: 100 }); * ``` * * @param text Text to type into the focused element character by character. * @param options Typing options. */ pressSequentially(text: string, options?: KeyboardPressOptions): Promise; /** * Type a text into the input field. * @param text Text to type into the input field. * @param options Typing options. */ type(text: string, options?: KeyboardPressOptions): Promise; /** * Hover over the element. * @param options Options to use. */ hover(options?: MouseMoveOptions): Promise; /** * Tap on the chosen element. * @param options Options to use. */ tap(options?: MouseMoveOptions): Promise; /** * Dispatches HTML DOM event types e.g. `click`. * @param type DOM event type. * @param eventInit Event-specific properties. * @param options Options to use. */ dispatchEvent(type: string, eventInit?: EvaluationArgument, options?: TimeoutOptions): Promise; /** * Wait for the element to be in a particular state e.g. `visible`. * @param options Wait options. */ waitFor(options?: { state?: ElementState } & TimeoutOptions): Promise; /** * Returns a new Locator that matches only elements with the given options. * * @example * ```js * // Filter list items that contain "Product 2" text * const product2Item = page * .locator('li') * .filter({ hasText: 'Product 2' }) * .first(); * * // Filter list items that do NOT contain "Product 2" using regex * const product1Item = page * .locator('li') * .filter({ hasNotText: /Product 2/ }) * .first(); * ``` * * @param options Filter options. * @returns A new filtered Locator that can be chained with other methods. */ filter(options: LocatorFilterOptions): Locator; /** * Returns {@link Locator} to the element with the corresponding role. * * @example * ```js * const locator = locator.getByRole('button', { name: 'Pizza, Please!' }); * * await locator.click(); * ``` * * @param role The role of the element. * @param options Options to use. * @returns The locator to the element with the corresponding role. */ getByRole( role: | "alert" | "alertdialog" | "application" | "article" | "banner" | "blockquote" | "button" | "caption" | "cell" | "checkbox" | "code" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "dialog" | "directory" | "document" | "emphasis" | "feed" | "figure" | "form" | "generic" | "grid" | "gridcell" | "group" | "heading" | "img" | "insertion" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "meter" | "navigation" | "none" | "note" | "option" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "strong" | "subscript" | "superscript" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "time" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem", options?: { /** * Whether the accessible `options.name` should be checked exactly for equality. * * @defaultValue false */ exact?: boolean; /** * Whether to include elements that are normally excluded from the accessibility tree. * * @defaultValue false */ includeHidden?: boolean; /** * A number attribute that is traditionally used for headings h1-h6. */ level?: number; /** * An accessible name for the element, such as a text in a button or a label for an input. */ name?: string | RegExp; /** * A boolean attribute that can be used to indicate if a checkbox is checked or not. */ checked?: boolean; /** * A boolean attribute that can be used to indicate if an element is disabled or not. */ disabled?: boolean; /** * A boolean attribute that can be used to indicate if an element is expanded or not. */ expanded?: boolean; /** * A boolean attribute that can be used to indicate if an element is pressed or not. */ pressed?: boolean; /** * A boolean attribute that can be used to indicate if an element is selected or not. */ selected?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding alt text. * * @example * ```js * const locator = locator.getByAltText('pizza'); * * await locator.click(); * ``` * * @param altText The alt text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding alt text. */ getByAltText( altText: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding label text. * * @example * ```js * const locator = locator.getByLabel('Password'); * * await locator.fill('my-password'); * ``` * * @param label The label text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding label text. */ getByLabel( label: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Allows locating elements by their text content. Returns {@link Locator}. * * Consider the following DOM structure: * * ```html *
Hello world
*
Hello
* ``` * * You can locate by text substring, exact string, or a regular expression: * * @example * ```js * // Matches * locator.getByText('world'); * * // Matches first
* locator.getByText('Hello world'); * * // Matches second
* locator.getByText('Hello', { exact: true }); * * // Matches both
s * locator.getByText(/Hello/); * * // Matches second
* locator.getByText(/^hello$/i); * ``` * * Matching by text always normalizes whitespace, even with exact match. For * example, it turns multiple spaces into one, turns line breaks into spaces * and ignores leading and trailing whitespace. * * Input elements of the type `button` and `submit` are matched by their * `value` instead of the text content. For example, locating by text * `"Log in"` matches ``. * * @param text Text to locate the element by. * @param options Options to use. * @returns The locator to the element with the corresponding text content. */ getByText( text: string | RegExp, options?: { /** * Whether to find an exact match: case-sensitive and whole-string. * Default to false. Ignored when locating by a regular expression. * Note that exact match still trims whitespace. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding test ID. * Note that this method only supports the `data-testid` attribute. * * @example * HTML: * ```html * * ``` * * JavaScript: * ```js * const locator = locator.getByTestId('submit-button'); * * await locator.click(); * ``` * * @param testId The test ID of the element. * @returns The locator to the element with the corresponding test ID. */ getByTestId(testId: string | RegExp): Locator; /** * Returns {@link Locator} to the element with the corresponding placeholder text. * * @example * ```js * const locator = locator.getByPlaceholder('name@example.com'); * * await locator.fill('my.name@example.com'); * ``` * * @param placeholder The placeholder text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding placeholder text. */ getByPlaceholder( placeholder: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; /** * Returns {@link Locator} to the element with the corresponding title text. * * @example * ```js * const locator = locator.getByTitle('Information box'); * * await locator.click(); * ``` * * @param title The title text of the element. * @param options Options to use. * @returns The locator to the element with the corresponding title text. */ getByTitle( title: string | RegExp, options?: { /** * Whether the locator should be exact. * * @defaultValue false */ exact?: boolean; }, ): Locator; } /** * Mouse provides an API for managing a virtual mouse. */ export interface Mouse { /** * Shortcut for `mouse.move(x, y)`, `mouse.down()`, `mouse.up()`. * @param x The x position. * @param y The y position. * @param options The click options. */ click(x: number, y: number, options?: MouseMultiClickOptions): Promise; /** * Shortcut for `mouse.move(x, y)`, `mouse.down()`, `mouse.up()`, `mouse.down()`, * `mouse.up()`. * @param x The x position. * @param y The y position. * @param options The click options. */ dblclick(x: number, y: number, options?: MouseClickOptions): Promise; /** * Dispatches a `mousedown` event. * @param options The mouse down options. */ down(options?: MouseDownUpOptions): Promise; /** * Dispatches a `mousemove` event. * @param x The x position. * @param y The y position. * @param options The mouse move options. */ move(x: number, y: number, options?: { steps?: number }): Promise; /** * Dispatches a `mouseup` event. * @param options The mouse up options. */ up(options?: MouseDownUpOptions): Promise; } /** * Page provides methods to interact with a single tab in a running web browser * instance. One instance of the browser can have many page instances. */ export interface Page { /** * Activates the browser tab so that it comes into focus and actions can be * performed against it. */ bringToFront(): Promise; /** * **NOTE** Use locator-based `locator.check([options])` instead. * * This method is used to select an input checkbox. * @param selector A selector to search for an element. If there are multiple * elements satisfying the selector, the first will be used. * @param options */ check( selector: string, options?: { /** * Setting this to `true` will bypass the actionability checks (visible, * stable, enabled). Defaults to `false`. */ force?: boolean; /** * If set to `true` and a navigation occurs from performing this action, it * will not wait for it to complete. Defaults to `false`. */ noWaitAfter?: boolean; /** * A point to use relative to the top left corner of the element. If not * supplied, a visible point of the element is used. */ position?: { x: number; y: number; }; /** * When `true`, the call requires selector to resolve to a single element. * If given selector resolves to more than one element, the call throws * an exception. Defaults to `false`. */ strict?: boolean; /** * Maximum time in milliseconds. Defaults to `30` seconds. Default is * overridden by the `setDefaultTimeout` option on `BrowserContext` or * `page` methods. * * Setting the value to `0` will disable the timeout. */ timeout?: number; /** * Setting this to `true` will perform the actionability checks without * performing the action. Useful to wait until the element is ready for the * action without performing it. Defaults to `false`. */ trial?: boolean; }, ): Promise; /** * **NOTE** Use locator-based `locator.click([options])` instead. * * This method clicks an element matching `selector`. * @param selector A selector to search for an element. If there are multiple * elements satisfying the selector, the first will be used. * @param options */ click( selector: string, options?: { /** * The mouse button (`left`, `middle` or `right`) to use during the action. * Defaults to `left`. */ button?: MouseButton; /** * The number of times the action is performed. Defaults to `1`. */ clickCount?: number; /** * Milliseconds to wait between `mousedown` and `mouseup`. Defaults to `0`. */ delay?: number; /** * Setting this to `true` will bypass the actionability checks (`visible`, * `stable`, `enabled`). Defaults to `false`. */ force?: boolean; /** * `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the * action. If not specified, currently pressed modifiers are used, * otherwise defaults to `null`. */ modifiers?: KeyboardModifier[]; /** * If set to `true` and a navigation occurs from performing this action, it * will not wait for it to complete. Defaults to `false`. */ noWaitAfter?: boolean; /** * A point to use relative to the top left corner of the element. If not * supplied, a visible point of the element is used. */ position?: { x: number; y: number; }; /** * When `true`, the call requires selector to resolve to a single element. * If given selector resolves to more than one element, the call throws * an exception. Defaults to `false`. */ strict?: boolean; /** * Maximum time in milliseconds. Defaults to `30` seconds. Default is * overridden by the `setDefaultTimeout` option on `BrowserContext` or * `page` methods. * * Setting the value to `0` will disable the timeout. */ timeout?: number; /** * Setting this to `true` will perform the actionability checks without * performing the action. Useful to wait until the element is ready for the * action without performing it. Defaults to `false`. */ trial?: boolean; }, ): Promise; /** * This will close the tab that this page is associated with. */ close(): Promise; /** * Gets the HTML contents of the page. */ content(): Promise; /** * Gets the `BrowserContext` that the page belongs to. */ context(): BrowserContext; /** * **NOTE** Use locator-based `locator.dblclick([options])` instead. * * Mouse double clicks an element matching provided selector. * @param selector A selector to search for an element. If there are multiple * elements satisfying the selector, the first will be used. * @param options */ dblclick( selector: string, options?: { /** * The mouse button (`left`, `middle` or `right`) to use during the action. * Defaults to `left`. */ button?: MouseButton; /** * Milliseconds to wait between `mousedown` and `mouseup`. Defaults to `0`. */ delay?: number; /** * Setting this to `true` will bypass the actionability checks (`visible`, * `stable`, `enabled`). Defaults to `false`. */ force?: boolean; /** * `Alt`, `Control`, `Meta` or `Shift` modifiers keys pressed during the * action. If not specified, currently pressed modifiers are used, * otherwise defaults to `null`. */ modifiers?: KeyboardModifier[]; /** * If set to `true` and a navigation occurs from performing this action, it * will not wait for it to complete. Defaults to `false`. */ noWaitAfter?: boolean; /** * A point to use relative to the top left corner of the element. If not * supplied, a visible point of the element is used. */ position?: { x: number; y: number; }; /** * When `true`, the call requires selector to resolve to a single element. * If given selector resolves to more than one element, the call throws * an exception. Defaults to `false`. */ strict?: boolean; /** * Maximum time in milliseconds. Defaults to `30` seconds. Default is * overridden by the `setDefaultTimeout` option on `BrowserContext` or * `page` methods. * * Setting the value to `0` will disable the timeout. */ timeout?: number; /** * Setting this to `true` will perform the actionability checks without * performing the action. Useful to wait until the element is ready for the * action without performing it. Defaults to `false`. */ trial?: boolean; }, ): Promise; /** * **NOTE** Use locator-based locator.dispatchEvent([options]) instead. * * @param selector A selector to search for an element. If there are multiple * elements satisfying the selector, the first will be used. * @param type DOM event type: `"click"` etc. * @param eventInit Optional event-specific initialization properties. * @param options */ dispatchEvent( selector: string, type: string, eventInit?: EvaluationArgument, options?: { /** * When `true`, the call requires selector to resolve to a single element. * If given selector resolves to more than one element, the call throws * an exception. Defaults to `false`. */ strict?: boolean; /** * Maximum time in milliseconds. Defaults to `30` seconds. Default is * overridden by the `setDefaultTimeout` option on `BrowserContext` or * `page` methods. * * Setting the value to `0` will disable the timeout. */ timeout?: number; }, ): Promise; /** * This method changes the `CSS media type` through the `media` argument, * and/or the `'prefers-colors-scheme'` media feature, using the `colorScheme` * argument. * @param options */ emulateMedia(options?: { /** * Emulates `'prefers-colors-scheme'` media feature, supported values are * `'light'`, `'dark'`, and `'no-preference'`. */ colorScheme?: "light" | "dark" | "no-preference"; /** * Changes the CSS media type of the page. The only allowed values are * `'screen'`, and `'print'`. */ media?: "screen" | "print"; /** * Emulates `'prefers-reduced-motion'` media feature, supported values are * `'reduce'`, `'no-preference'`. */ reducedMotion?: "reduce" | "no-preference"; }): Promise; /** * This emulates your website with the specified vision deficiency type. * The supported types are: * - none: default. * - blurredVision: where vision is less precise. * - protanopia: the inability to perceive any red light. * - deuteranopia: the inability to perceive any green light. * - tritanopia: the inability to perceive any blue light. * - achromatopsia: the inability to perceive any color except for shades of * grey (extremely rare). * @param type */ emulateVisionDeficiency( type: "none" | "blurredVision" | "deuteranopia" | "protanopia" | "tritanopia" | "achromatopsia", ): Promise; /** * Returns the value of the `pageFunction` invocation. * * A string can also be passed in instead of a function. * * @param pageFunction Function to be evaluated in the page context. * @param arg Optional argument to pass to `pageFunction`. */ evaluate(pageFunction: PageFunction, arg?: Arg): Promise; /** * Returns the value of the `pageFunction` invocation as a [JSHandle]. * * The only difference between page.evaluate(pageFunction[, arg]) and * page.evaluateHandle(pageFunction[, arg]) is that * page.evaluateHandle(pageFunction[, arg])returns [JSHandle]. * * @param pageFunction Function to be evaluated in the page context. * @param arg Optional argument to pass to `pageFunction`. */ evaluateHandle(pageFunction: PageFunction, arg?: Arg): Promise>; /** * **NOTE** Use locator-based `locator.fill(value[, options])` instead. * * Fill an `input`, `textarea` or `[contenteditable]` element with the * provided value. * * @param selector A selector to search for an element. If there are multiple * elements satisfying the selector, the first will be used. * @param value Value to fill for the ``, `