Skip to main content
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin 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.

Prerequisites

  • 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#:

Create a load test

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.

Load Testing dashboard with the Create Load Test button highlighted

Enter a Test Name for your load test, select Hybrid, and click Upload scripts.

Test name field with the Hybrid load test type selected on the Load Testing dashboard

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.

Load Sources step of a hybrid test with a validated JMeter script and a validated Playwright C# project

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.
  • Title: Part of the fully qualified test name.

After you finish configuring load parameters, click RUN TEST.

Use packages from a private NuGet feed

BrowserStack restores the NuGet packages of your project before the test starts. To use packages from a private feed, follow these steps:

  1. Place your nuget.config file in the folder that you zip, next to the .csproj or .sln file.
  2. In nuget.config, write each credential as an environment variable reference, such as %NUGET_TOKEN%. Don’t write the credential itself in the file.
  3. 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:

nuget.config

The element name under packageSourceCredentials must match the key of the feed under packageSources. The key can’t contain spaces.

For more information about masked variables, see Environment variables.

How BrowserStack runs your C# tests

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.
  • Solution files: BrowserStack supports .sln files. BrowserStack doesn’t support .slnx files.
  • 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.
<project> doesn’t reference Microsoft.Playwright. 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.

If you run into issues, try the troubleshooting steps or contact us for help.

What’s next

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle