Skip to main content
k6 browser enables end-to-end testing of web applications using real browser automation. Built on the Chrome DevTools Protocol, it provides a Playwright-compatible API for interacting with web pages, perfect for testing user journeys and frontend performance.

Getting Started

Browser tests use the k6/browser module and require async functions:
Browser tests require the browser scenario option and must use async/await syntax. The browser module is currently available for Chromium-based browsers.

Browser Configuration

Configure browser behavior in scenario options:

Browser Options

Navigate to pages and wait for different load states:

Element Interaction

Locators

Locators provide a robust way to find and interact with elements:

Locator Methods

Form Interaction

Fill forms and submit data:

Screenshots and Debugging

Capture screenshots for visual verification:

Waiting Strategies

Different ways to wait for elements and conditions:

Advanced Interactions

Mouse and Keyboard

Cookies

Local Storage and Session Storage

Network Control

Request Interception

Network Throttling

Device Emulation

Multiple Pages and Contexts

Web Vitals

k6 browser automatically collects Web Vitals metrics:

Page Object Model

Organize tests using the Page Object pattern:
Browser tests consume more resources than protocol-level tests. Use them strategically for critical user journeys and complement with HTTP tests for higher load levels.

Best Practices

  1. Always close pages and contexts to free up resources
  2. Use locators over selectors for resilience across page changes
  3. Wait for navigation when actions trigger page loads
  4. Set up waiters before actions to avoid race conditions
  5. Use Page Object Model for maintainable test code
  6. Combine with HTTP tests for comprehensive coverage
  7. Monitor Web Vitals to ensure performance standards
  8. Use headless mode in CI/CD environments

Metrics

k6 browser collects comprehensive metrics:
  • browser_web_vital_* - Core Web Vitals (FCP, LCP, CLS, etc.)
  • browser_http_req_duration - HTTP request durations
  • browser_http_req_failed - Failed HTTP requests
  • browser_data_sent / browser_data_received - Network traffic