Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
Hybrid load testing using Playwright C# with JMeter or k6
Run a hybrid load test using Playwright C# scripts on BrowserStack Load Testing
Run a hybrid load test that combines your Playwright browser tests written in C# with a JMeter or k6 protocol load test. BrowserStack restores and builds your .NET test project, then runs it for every browser virtual user.
Supported versions
BrowserStack supports the following framework and engine versions for hybrid load tests with Playwright C#:
Framework
.NET version
Test frameworks
Playwright versions
Protocol engine
Playwright C#
.NET 8, .NET 10
NUnit, MSTest, xUnit, Reqnroll
1.60, 1.61, 1.62, 1.63, 1.64
JMeter 5.6.3, k6 2.0.0
The table lists the five most recent Playwright versions. The list moves forward with each Playwright release.
BrowserStack username and access key. You can find these under your account profile.
An existing JMeter script.
One .NET test project that:
References the Microsoft.Playwright package.
Uses NUnit, MSTest, xUnit, or Reqnroll, such as through Microsoft.Playwright.NUnit, Microsoft.Playwright.MSTest, or Microsoft.Playwright.Xunit.
Targets net8.0 or net10.0.
Access from the BrowserStack load generator IP addresses to your private NuGet feed, if the feed is behind a firewall. For the list of IP addresses to allowlist, see Test private websites and APIs.
Tests that use the NUnit, MSTest, or xUnit Playwright base classes run without code changes.
Run a test
Perform the following steps to run a hybrid load test with JMeter and your Playwright test suite written in C#:
You can start a new test from the Quick Start page or the Load Tests page on the Load Testing dashboard.
On the dashboard, click Create Load Test.
Enter a Test Name for your load test, select Hybrid, and click Upload scripts.
Upload your scripts
A hybrid test combines a JMeter script with a Playwright C# project. JMeter generates API-level load, and Playwright drives browser-level load to simulate real user interactions.
Before you upload, zip the folder that contains your .sln file, or the .csproj file of your test project if you don’t use a solution. Leave out the bin/ and obj/ folders.
The Load Sources step has two sections:
API Load Source: Select Upload Script, select JMeter from the dropdown, and upload your JMeter script. Then, select your main script from the Select Main JMeter script dropdown.
Browser Load Source: Select Upload Automation Project, select Playwright - C# from the dropdown, and upload your ZIP file. The ZIP file can be up to 250 MB. Then, select the .csproj file of your test project from the Select dependencies dropdown.
After you upload the files, BrowserStack validates them and lists any issues to fix. For a list of validation messages and fixes for your C# project, see Troubleshoot C# load tests.
To try hybrid load testing with Playwright C# before you upload your own files, click Use Sample Scripts on the Load Sources step to run a hybrid load test with the sample scripts.
You must complete both sections. After you upload both files, click Configure Load to move to the next step.
Configure load and run test
You can configure the following load parameters to customize your load test:
To run only some of your browser tests, enable Multiple Scenarios in the Load Configuration section and add one scenario. Filter the scenario by one of the following selectors:
Tag: An NUnit or MSTest category, or an xUnit Category trait.
Extract the downloaded ZIP file and place the browserstack-cli binary in the root folder of your project. If you use a .sln file, the root folder is the folder that contains it. Otherwise, the root folder is the folder that contains the .csproj file of your test project. Run all later CLI commands from this folder.
On macOS or Linux, run the following command to make the binary executable:
On Windows, run .\browserstack-cli.exe in place of ./browserstack-cli in the commands that follow.
Initialize your project for load testing
Run the following command from the root folder of your project to generate the browserstack-load.yml file. This file contains the configuration for your load test.
Open the generated browserstack-load.yml file and update it with the details of your test. The following steps describe the C# settings in the sample configuration:
Specify the tests
The tests block defines the combination of test types that you want to run as part of a hybrid load test. Set testType to Playwright in one sub-block and to JMeter in the other.
In the Playwright sub-block, set the following values:
browserLoadPercent: The percentage of the total virtual users that run your Playwright tests.
language: The language of your tests. Set it to csharp.
files: The project to run. Under dependencies, set the first entry to the .csproj file of your test project. If your test project references library projects in sibling folders, use your .sln file instead, for example ./MySolution.sln. C# load tests don’t use testConfigs.
In the JMeter sub-block, set the following values:
apiLoadPercent: The percentage of the total virtual users that run your JMeter script.
testScripts: The path to your .jmx file.
When you run the test, the CLI zips the folder of the first dependency. At every folder level, the CLI leaves out the bin/, obj/, .vs/, and TestResults/ folders and all *.user files.
Select the tests to run
By default, BrowserStack runs all the tests in your project. To run only some tests, add one entry under scenarios in the Playwright sub-block and set its testSelector to one of the following types:
type: tag: Matches an NUnit or MSTest category, or an xUnit Category trait.
type: title: Matches part of the fully qualified test name.
A scenario changes the structure of the configuration file in the following ways:
The scenario sets its own vus, regions, and either duration or iterations.
The API load moves to the loadProfile.API block at the root of the file. This block sets the type, vus, duration, and regions of your JMeter script.
The file has no root vus, and the tests entries have no browserLoadPercent or apiLoadPercent.
The following configuration runs only the Playwright tests tagged smoke, alongside your JMeter script:
Use projectName to group related tests under the same project on the dashboard. Use testName to group multiple runs of the same test. Keep projectName and testName consistent across different runs of the same test.
You can use the following characters in projectName and testName:
Letters, A to Z and a to z
Digits, 0 to 9
The special characters ., :, -, [], /, @, &, ', and _
BrowserStack ignores all other characters.
You can configure the following load parameters to customize your load test:
BrowserStack username and access key. You can find these under your account profile.
An existing k6 script.
One .NET test project that:
References the Microsoft.Playwright package.
Uses NUnit, MSTest, xUnit, or Reqnroll, such as through Microsoft.Playwright.NUnit, Microsoft.Playwright.MSTest, or Microsoft.Playwright.Xunit.
Targets net8.0 or net10.0.
Access from the BrowserStack load generator IP addresses to your private NuGet feed, if the feed is behind a firewall. For the list of IP addresses to allowlist, see Test private websites and APIs.
Tests that use the NUnit, MSTest, or xUnit Playwright base classes run without code changes.
Run a test
Perform the following steps to run a hybrid load test with k6 and your Playwright test suite written in C#:
You can start a new test from the Quick Start page or the Load Tests page on the Load Testing dashboard.
On the dashboard, click Create Load Test.
Enter a Test Name for your load test, select Hybrid, and click Upload scripts.
Upload your scripts
A hybrid test combines a k6 script with a Playwright C# project. k6 generates API-level load, and Playwright drives browser-level load to simulate real user interactions.
Before you upload, zip the folder that contains your .sln file, or the .csproj file of your test project if you don’t use a solution. Leave out the bin/ and obj/ folders.
The Load Sources step has two sections:
API Load Source: Select Upload Script, select k6 from the dropdown, and upload your k6 script. Then, select your main script from the Select Main k6 script dropdown.
Browser Load Source: Select Upload Automation Project, select Playwright - C# from the dropdown, and upload your ZIP file. The ZIP file can be up to 250 MB. Then, select the .csproj file of your test project from the Select dependencies dropdown.
After you upload the files, BrowserStack validates them and lists any issues to fix. For a list of validation messages and fixes for your C# project, see Troubleshoot C# load tests.
To try hybrid load testing with Playwright C# before you upload your own files, click Use Sample Scripts on the Load Sources step to run a hybrid load test with the sample scripts.
You must complete both sections. After you upload both files, click Configure Load to move to the next step.
Configure load and run test
You can configure the following load parameters to customize your load test:
To run only some of your browser tests, enable Multiple Scenarios in the Load Configuration section and add one scenario. Filter the scenario by one of the following selectors:
Tag: An NUnit or MSTest category, or an xUnit Category trait.
Extract the downloaded ZIP file and place the browserstack-cli binary in the root folder of your project. If you use a .sln file, the root folder is the folder that contains it. Otherwise, the root folder is the folder that contains the .csproj file of your test project. Run all later CLI commands from this folder.
On macOS or Linux, run the following command to make the binary executable:
On Windows, run .\browserstack-cli.exe in place of ./browserstack-cli in the commands that follow.
Initialize your project for load testing
Run the following command from the root folder of your project to generate the browserstack-load.yml file. This file contains the configuration for your load test.
Open the generated browserstack-load.yml file and update it with the details of your test. The following steps describe the C# settings in the sample configuration:
Specify the tests
The tests block defines the combination of test types that you want to run as part of a hybrid load test. Set testType to Playwright in one sub-block and to k6 in the other.
In the Playwright sub-block, set the following values:
browserLoadPercent: The percentage of the total virtual users that run your Playwright tests.
language: The language of your tests. Set it to csharp.
files: The project to run. Under dependencies, set the first entry to the .csproj file of your test project. If your test project references library projects in sibling folders, use your .sln file instead, for example ./MySolution.sln. C# load tests don’t use testConfigs.
In the k6 sub-block, set the following values:
apiLoadPercent: The percentage of the total virtual users that run your k6 script.
testScripts: The path to your .js file.
When you run the test, the CLI zips the folder of the first dependency. At every folder level, the CLI leaves out the bin/, obj/, .vs/, and TestResults/ folders and all *.user files.
Select the tests to run
By default, BrowserStack runs all the tests in your project. To run only some tests, add one entry under scenarios in the Playwright sub-block and set its testSelector to one of the following types:
type: tag: Matches an NUnit or MSTest category, or an xUnit Category trait.
type: title: Matches part of the fully qualified test name.
A scenario changes the structure of the configuration file in the following ways:
The scenario sets its own vus, regions, and either duration or iterations.
The API load moves to the loadProfile.API block at the root of the file. This block sets the type, vus, duration, and regions of your k6 script.
The file has no root vus, and the tests entries have no browserLoadPercent or apiLoadPercent.
The following configuration runs only the Playwright tests tagged smoke, alongside your k6 script:
Use projectName to group related tests under the same project on the dashboard. Use testName to group multiple runs of the same test. Keep projectName and testName consistent across different runs of the same test.
You can use the following characters in projectName and testName:
Letters, A to Z and a to z
Digits, 0 to 9
The special characters ., :, -, [], /, @, &, ', and _
BrowserStack ignores all other characters.
You can configure the following load parameters to customize your load test:
BrowserStack restores the NuGet packages of your project before the test starts. To use packages from a private feed, follow these steps:
Place your nuget.config file in the folder that you zip, next to the .csproj or .sln file.
In nuget.config, write each credential as an environment variable reference, such as %NUGET_TOKEN%. Don’t write the credential itself in the file.
When you configure the test, add each variable as an environment variable and mask it. In the UI Builder, add the variable on the Env Variables tab and click the closed-eye icon next to it. In browserstack-load.yml, set isMasked: true for the variable.
The following nuget.config file adds a private feed named company and reads its credentials from the NUGET_USER and NUGET_TOKEN environment variables. NuGet replaces each %NAME% reference with the variable value when it restores the packages:
Review the following behavior before you analyze your test results:
Browser: BrowserStack runs the browser part of your hybrid test on Chrome. BrowserStack ignores any Firefox and WebKit settings in your project or .runsettings file and shows a note when you upload the project.
Playwright version: BrowserStack runs your project with the closest supported Playwright version. If this version differs from the version in your project, you see a note when you upload the project.
Test results: Each test appears on the Tests tab. You don’t need to change your project.
Test data: Your tests can read CSV test data files by their relative paths.
Setup time: BrowserStack must restore and build your project within 10 minutes.
Scenarios: The browser part of a hybrid test accepts only one scenario. Filter the scenario by tag or by title.
Troubleshoot C# load tests
BrowserStack validates your project when you upload it and when the test starts. The following table lists the messages you might see when you upload your project:
Message
How to fix
We couldn’t find a .NET test project in your upload.
Add the folder that contains your test .csproj file to the ZIP file and upload it again.
Your upload contains more than one test project.
C# load tests run one project. Zip only the project you want to load test and upload it again.
Browser load tests need a Playwright project. Add the Microsoft.Playwright package or select another framework.
We couldn’t find a test runner in <project>.
Add a reference to NUnit, MSTest, or xUnit, such as the Microsoft.Playwright.NUnit package, and upload the project again.
<project> targets <framework>.
C# load tests run projects that target net8.0 or net10.0. Change TargetFramework in your .csproj file and upload the project again.
nuget.config uses %NAME%, but no environment variable named NAME is set on this test.
Add the variable on the Env Variables tab. Without it, the package restore can fail.
The following table lists the messages you might see when the test starts:
Message
How to fix
Restoring NuGet packages failed on <feed>.
Check the feed URL and the credentials in your environment variables. The logs contain the full NuGet output.
The project failed to build.
Review the compiler output in the logs and fix the build errors.
Restoring and building the project took longer than 10 minutes.
Reduce the package dependencies of your project or contact support.
No tests were found in your test project.
Check that your project references the test adapter for its framework, such as NUnit3TestAdapter, MSTest.TestAdapter, or xunit.runner.visualstudio. Then run the test again.