k6/browser module provides a browser automation API for running browser-based load tests. It uses the Chrome DevTools Protocol (CDP) to interact with Chromium-based browsers, enabling you to test real user workflows including page loads, interactions, and modern web features.
Overview
The browser module is inspired by Playwright and other frontend testing frameworks. It manages browser contexts and pages, allowing you to simulate real user behavior in performance tests.Make sure you are using the latest k6 version to work with the browser module.
Importing the Module
Properties
object
Entry point for all browser tests. Manages BrowserContext and Page instances via Chrome DevTools Protocol.
object
Predefined emulation settings for many end-user devices. Use to simulate browser behavior on mobile devices.
Browser Module API
The browser module is the entry point for all your tests. It manages:- BrowserContext: Control browser behavior, set attributes, manage cookies and cache
- Page: Display and interact with your rendered site
Methods
function
Closes the current BrowserContext.
function
Returns the current BrowserContext.
boolean
Indicates whether the CDP connection to the browser process is active.
function
Creates and returns a new BrowserContext.Parameters:
options(optional): Configuration object for the browser context
function
Creates a new Page in a new BrowserContext and returns the page.Parameters:
options(optional): Configuration object for the page
function
Returns the browser application’s version.
Browser-Level APIs
The following classes provide the browser automation functionality:Examples
Basic Browser Test
Running Browser Tests
Browser Module Options
Customize the browser module’s behavior using environment variables:Related Resources
BrowserContext
Manage isolated browser sessions
Page
Interact with browser pages
Locator
Find and interact with elements
Browser Options
Configure browser behavior