No results for

Powered byAlgolia

xk6-browser brings browser automation and end-to-end web testing to k6 while supporting core k6 features. It adds browser-level scripting APIs to interact with real browsers and collect frontend metrics as part of your k6 tests.

import launcher from 'k6/x/browser';
export default function () {
const browser = launcher.launch('chromium', { headless: false });
const context = browser.newContext();
const page = context.newPage();
page.screenshot({ path: `example-chromium.png` });


xk6-browser is currently being developed as a k6 extension. You have to run a k6 version built with the browser extension to use the browser-level APIs in your k6 tests.

Download a release binary

The quickest way to get started is to download a release binary from GitHub.

Build from source

If you're more adventurous or want to get the latest changes of the xk6-browser extension, you can also build from source.

To build a k6 binary with the extension, first, ensure you have installed Go and Git; the following steps are:

# Install xk6
go install
# Build the k6 binary
xk6 build --with
... [INFO] Build environment ready
... [INFO] Building k6
... [INFO] Build complete: ./k6

xk6 will create the k6 binary in the local folder.

To learn more about how to build custom k6 versions, check out xk6

Browser-level APIs

xk6-browser uses Chrome DevTools Protocol to instrument and interact with the browser. The xk6-browser APIs aims for rough compatibility with the Playwright API for NodeJS.

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

Here's a list of the fully (✅) or partially (🚧) implemented classes of the Playwright API (with a more detailed breakdown of missing APIs in the table below):

k6 ClassMissing Playwright APIs
Browseron() (dependent on event-loop support in k6), startTracing(), stopTracing()
BrowserContextaddCookies(), backgroundPages(), cookies(), exposeBinding(), exposeFunction(), newCDPSession(), on() (dependent on event-loop support in k6), route() (dependent on event-loop support in k6), serviceWorkers(), storageState(), unroute() (dependent on event-loop support in k6), waitForEvent() (dependent on event-loop support in k6), tracing
BrowserTypeconnect(), connectOverCDP(), launchPersistentContext(), launchServer()
ElementHandle$eval(), $$eval(), setInputFiles()
Frame$eval(), $$eval(), addScriptTag(), addStyleTag(), dragAndDrop(), locator(), setInputFiles()
Page$eval(), $$eval(), addInitScript(), addScriptTag(), addStyleTag(), dragAndDrop(), exposeBinding(), exposeFunction(), frame(), goBack(), goForward(), locator(), on() (dependent on event-loop support in k6), pause(), pdf(), route() (dependent on event-loop support in k6), unroute() (dependent on event-loop support in k6), video(), waitForEvent() (dependent on event-loop support in k6), waitForResponse() (dependent on event-loop support in k6), waitForURL() (dependent on event-loop support in k6), workers()
Requestfailure() (dependent on event-loop support in k6), postDataJSON(), redirectFrom(), redirectTo()
Responsefinished() (dependent on event-loop support in k6)

The following Playwright APIs are not supported yet: