Load Testing With Playwright
- Overview
- Prerequisites
- Adapting Playwright Tests for Load Testing
- Project Setup
- PlaywrightHelper API
loadtest:record-playwrightGoal- Troubleshooting
- Related Documentation
This page covers the Playwright-specific aspects of load testing. For general load testing concepts, running tests, configuring think times, understanding k6 output, and more, see Load Testing. For an introduction to writing Playwright tests for Vaadin applications, see Testing with Playwright.
Overview
Unlike the TestBench path, which requires a BrowserMob Proxy to capture HTTP traffic, the Playwright path uses native HAR recording built into the browser. This results in fewer moving parts, and no proxy to run requests through.
The workflow is as follows:
-
Write standard Playwright integration tests that simulate real user scenarios
-
Record HTTP traffic automatically via Playwright’s native HAR capture
-
Convert the captured HAR into Vaadin-aware k6 scripts
-
Run the generated k6 scripts at scale against any target server
All steps after writing the tests are fully automated by the Maven plugin.
Prerequisites
The Playwright path requires the same base tools as the TestBench path (Java 21+, Maven 3.9+, k6), but does not require Chrome or ChromeDriver. Playwright downloads and manages its own browser binaries automatically.
Adapting Playwright Tests for Load Testing
Playwright tests for load testing are standard JUnit 5 integration tests — see Testing with Playwright for the basics of writing them.
The only load-testing-specific requirement is using PlaywrightHelper.createBrowserContext(browser) to create the browser context.
This enables transparent HAR recording when the test is run by the Maven plugin, and is a no-op during normal development runs.
Source code
Java
context = PlaywrightHelper.createBrowserContext(browser); 1
page = context.newPage();
page.navigate(PlaywrightHelper.getBaseUrl() + "/my-view"); 2-
PlaywrightHelper.createBrowserContext()enables HAR recording when thek6.harOutputPathsystem property is set by the Maven plugin. When running tests normally (e.g., during development), it creates a plain browser context with no recording overhead. -
PlaywrightHelper.getBaseUrl()resolves the deployment URL from theHOSTNAMEenvironment variable andserver.portsystem property, defaulting tohttp://localhost:8080.
Best Practices for Load Test Scenarios
-
One scenario per test class — each test class maps to one k6 script. Keep scenarios focused on a single user journey.
-
Use semantic locators — prefer
getByLabel(),getByRole(), andgetByText()over CSS selectors. They are more resilient to UI changes. -
Include assertions — assertions verify correctness during recording and serve as documentation. They don’t affect the generated k6 script.
-
Avoid destructive-only tests — if a test only deletes data, mark it with
@Destructiveso it can be skipped during recording runs. Prefer tests that create-then-delete. -
Run headless during recording — use
setHeadless(true)for CI and recording runs.
Project Setup
Application Module Dependencies
Add the testbench-loadtest-support and Playwright dependencies to your Vaadin application module:
Source code
XML
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>testbench-loadtest-support</artifactId>
<version>${vaadin.testbench.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.58.0</version>
<scope>test</scope>
</dependency>Load Test Orchestration
Add a load test profile or create a separate Maven module (packaging pom) that orchestrates the recording and load test execution.
The key difference from the TestBench orchestration module is using the record-playwright goal instead of the record goal.
Source code
Minimal Load Test
<properties>
<app.port>8081</app.port>
<management.port>8082</management.port>
<k6.vus>100</k6.vus>
<k6.duration>30s</k6.duration>
<k6.testDir>${project.build.directory}/k6/tests</k6.testDir>
</properties>
<build>
<plugins>
<!-- Load test plugin -->
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>testbench-converter-plugin</artifactId>
<version>${vaadin.testbench.version}</version>
<executions>
<!-- 1. Start the application -->
<execution>
<id>start-server</id>
<goals><goal>start-server</goal></goals>
<configuration>
<serverJar>${project.build.directory}/my-app.jar</serverJar>
<serverPort>${app.port}</serverPort>
<managementPort>${management.port}</managementPort>
</configuration>
</execution>
<!-- 2. Record Playwright scenarios -->
<execution>
<id>record</id>
<phase>integration-test</phase>
<goals><goal>record-playwright</goal></goals>
<configuration>
<testClasses>
<testClass>MyScenarioPlaywrightIT</testClass>
</testClasses>
<appPort>${app.port}</appPort>
<testWorkDir>${project.basedir}</testWorkDir>
<harDir>${project.build.directory}</harDir>
<outputDir>${k6.testDir}</outputDir>
</configuration>
</execution>
<!-- 3. Run k6 load tests -->
<execution>
<id>run</id>
<phase>integration-test</phase>
<goals><goal>run</goal></goals>
<configuration>
<testDir>${k6.testDir}</testDir>
<virtualUsers>${k6.vus}</virtualUsers>
<duration>${k6.duration}</duration>
<appPort>${app.port}</appPort>
<managementPort>${management.port}</managementPort>
</configuration>
</execution>
<!-- 4. Stop the application -->
<execution>
<id>stop-server</id>
<goals><goal>stop-server</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>PlaywrightHelper API
The PlaywrightHelper class in testbench-loadtest-support provides two static methods:
loadtest:record-playwright Goal
Records Playwright tests and converts captured HAR files to k6 scripts.
| Parameter | Type | Default | Description |
|---|---|---|---|
| List<String> | required | Playwright test class names to record (without package prefix). |
| int |
| Port where the application is running. |
| String | required | Working directory of the application module (where |
| String |
| Directory where HAR files are written. |
| String |
| Directory where generated k6 scripts are placed. |
| boolean |
| Skip recording. |
For parameters related to running the generated k6 scripts (loadtest:run), configuring think times, combined scenarios, and understanding k6 output, see the main Load Testing documentation.
Troubleshooting
Related Documentation
-
Testing with Playwright — Setting up Playwright and writing your first tests
-
Load Testing — General load testing setup, running tests, think time, k6 output, server metrics, and remote testing
-
Load Testing Thresholds — Configure thresholds for load tests
-
Load Profiles and Ramping — configure load patterns (ramp, stress, soak, custom)
-
Custom Response Checks — Add custom validation to generated k6 scripts