No results for

Powered byAlgolia
⚠️ This documentation is outdated. Please visit grafana.com for the latest k6 documentation.📚

Browser class

The Browser class is the entry point for all your tests, and it is what interacts with the actual web browser via Chrome DevTools Protocol (CDP). It manages:

  • BrowserContext which is where you can set a variety of attributes to control the behavior of pages;
  • and Page which is where your rendered site is displayed.

A new Browser instance (hence a new browser process) can be created using the launch() method of the chromium module from 'k6/experimental/browser'.

MethodDescription
browser.close()Closes the browser and all of its pages (if any were opened).
browser.contexts()Lets you access all open BrowserContexts.
browser.isConnected
Indicates whether the CDP connection to the browser process is active or not.
browser.newContext([options])
Creates and returns a new BrowserContext.
browser.newPage([options])
Creates a new Page in a new BrowserContext and returns the page.
browser.on('disconnected')Detects the disconnected event from the browser application.
browser.version()Returns the browser application's version.

Example

import { chromium } from 'k6/experimental/browser';
export default async function () {
const browser = chromium.launch();
const context = browser.newContext();
const page = context.newPage();
try {
await page.goto('https://test.k6.io/');
} finally {
page.close();
browser.close();
}
}