No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.44. Go to the latest version.

Experimental module

While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the extension graduation process.

Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to open an issue if you have any feedback or suggestions.

The browser module APIs aim for rough compatibility with the Playwright API for NodeJS.

Note that because k6 does not run in NodeJS, the browser module APIs will slightly differ from their Playwright counterparts.

note

To work with the browser module, make sure you are using k6 version 0.43.0 or above.

Modules

The table below lists the importable properties from the top level module ('k6/experimental/browser').

PropertyDescription
chromiumA BrowserType to launch tests in a Chromium-based browser.
devicesReturns predefined emulation settings for many end-user devices that can be used to simulate browser behavior on a mobile device. See the devices example below.
versionReturns the version number of k6 browser.

Devices Example

To emulate the browser behaviour on a mobile device and approximately measure the browser performance, you can import devices from k6/experimental/browser.

script.js
1import { chromium, devices } from 'k6/experimental/browser';
2
3export default async function () {
4 const browser = chromium.launch({ headless: false });
5 const iphoneX = devices['iPhone X'];
6 const context = browser.newContext(iphoneX);
7 const page = context.newPage();
8
9 try {
10 await page.goto('https://test.k6.io/');
11 } finally {
12 page.close();
13 browser.close();
14 }
15}

Browser-level APIs

k6 ClassDescription
Browser
The entry point for all tests and used to launch BrowserContexts and Pages.
BrowserContext
Enables independent browser sessions with separate Pages, cache, and cookies.
BrowserTypeThe BrowserType is the entry point into launching a browser process; chromium is currently the only supported BrowserType.
ElementHandle
Represents an in-page DOM element.
Frame
Access and interact with the Page.'s Frames.
JSHandleRepresents an in-page JavaScript object.
KeyboardUsed to simulate the keyboard interactions with the associated Page.
LocatorThe Locator API makes it easier to work with dynamically changing elements.
MouseUsed to simulate the mouse interactions with the associated Page.
Page
Provides methods to interact with a single tab in a Browser.
Request
Used to keep track of the request the Page makes.
Response
Represents the response received by the Page.
TouchscreenUsed to simulate touch interactions with the associated Page.
WorkerRepresents a WebWorker.