Getting Started
Browser tests use thek6/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
Page Navigation
Navigate to pages and wait for different load states:- Wait Conditions
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:Best Practices
- Always close pages and contexts to free up resources
- Use locators over selectors for resilience across page changes
- Wait for navigation when actions trigger page loads
- Set up waiters before actions to avoid race conditions
- Use Page Object Model for maintainable test code
- Combine with HTTP tests for comprehensive coverage
- Monitor Web Vitals to ensure performance standards
- 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 durationsbrowser_http_req_failed- Failed HTTP requestsbrowser_data_sent/browser_data_received- Network traffic