Browser Testing Overview
The k6 browser module brings browser automation and end-to-end web testing to k6 while supporting core k6 features. It adds browser-level APIs to interact with browsers and collect frontend performance metrics as part of your k6 tests.To work with the browser module, make sure you are using the latest k6 version, and install a Chromium-based browser on your machine (such as Google Chrome).
Why Browser Testing?
Browser-level testing provides a way to measure user experience and find issues that are difficult to catch on the protocol level. Browser testing helps you answer questions like:- When my application receives thousands of simultaneous requests from the protocol-level, what happens to the frontend?
- How can I get metrics specific to browsers, like total page load time?
- Are all my elements interactive on the frontend?
- Are there any loading spinners that take a long time to disappear?
Key Features
Real Browser Automation
The browser module uses Chromium to simulate real user interactions:- Navigate to pages and click elements
- Fill out forms and submit data
- Take screenshots and capture metrics
- Verify page content and UI elements
Web Vitals Metrics
k6 browser automatically collects Core Web Vitals metrics:- FCP (First Contentful Paint) - Loading performance
- LCP (Largest Contentful Paint) - Main content rendering
- CLS (Cumulative Layout Shift) - Visual stability
- FID (First Input Delay) - Interactivity
- INP (Interaction to Next Paint) - Responsiveness
- TTFB (Time to First Byte) - Server response time
Hybrid Performance Testing
Combine browser tests with protocol-level tests in a single script to:- Test real user flows on the frontend while generating higher load in the backend
- Measure both backend and frontend performance in the same test execution
- Increase collaboration between backend and frontend teams
Quick Start
Create a browser test using the k6 CLI:Example Browser Test
Here’s a simple browser test that navigates to a page and takes a screenshot:Browser Metrics Output
After running a browser test, k6 displays browser-specific metrics:Use Cases
Next Steps
Getting Started
Write your first k6 browser test
How to Write Tests
Learn browser testing concepts and patterns
Best Practices
Optimize your browser tests for reliability