STAF.Playwright
2.2.0
dotnet add package STAF.Playwright --version 2.2.0
NuGet\Install-Package STAF.Playwright -Version 2.2.0
<PackageReference Include="STAF.Playwright" Version="2.2.0" />
<PackageVersion Include="STAF.Playwright" Version="2.2.0" />
<PackageReference Include="STAF.Playwright" />
paket add STAF.Playwright --version 2.2.0
#r "nuget: STAF.Playwright, 2.2.0"
#:package STAF.Playwright@2.2.0
#addin nuget:?package=STAF.Playwright&version=2.2.0
#tool nuget:?package=STAF.Playwright&version=2.2.0
STAF.Playwright
A .NET test automation framework for web and API testing using Microsoft Playwright and MSTest. STAF (Simple Test Automation Framework) provides base classes, page object support, HTML reporting with screenshots, and configuration for multi-environment test runs. Works with the Playwright C# MCP (Model Context Protocol) server for AI-assisted test generation in Cursor, VS Code, and Visual Studio.
Keywords: Playwright C#, Playwright .NET, C# Playwright, MSTest Playwright, .NET 10 test automation, MCP Playwright C#, Cursor MCP Playwright, VS Code Playwright MCP, Visual Studio Playwright, STAF Playwright, page object model C#, browser automation .NET, API testing .NET, OpenAPI contract testing C#.
Installation
Install the package from NuGet:
dotnet add package STAF.Playwright
Or from Package Manager Console in Visual Studio:
Install-Package STAF.Playwright
Requirements: .NET 10 or above, MSTest, Microsoft Playwright (browsers installed via playwright install when using the framework).
Release notes
- .NET 10 or above is required. This package targets
net10.0. Use a project that targets .NET 10 or later when referencing STAF.Playwright.
Quick Start
- Add the package to your test project (see above).
- Inherit from
BaseTestin your test classes to get Playwright browser, context, and page setup/teardown. - Use
BasePagefor page objects and automatic step reporting, or call reporting APIs manually.
Web test example
using Microsoft.VisualStudio.TestTools.UnitTesting;
using STAF.Playwright.Framework;
[TestClass]
public class LoginTests : BaseTest
{
[TestMethod]
public async Task Login_ValidCredentials_Succeeds()
{
await Page.GotoAsync(ConfigManager.GetBaseUrl());
// Your test steps; BasePage methods report steps automatically
await ReportResult.ReportResultPass(Page, TestContext, "Login", "Login flow completed.");
}
}
API test example
[TestMethod]
public void Api_HealthCheck_ReturnsOk()
{
// Use TestBaseAPI and ApiClient with TestContext for automatic request reporting
ReportResultAPI.ReportResultPass(TestContext, "API/Health", "Health check passed.");
}
Features
- Playwright + MSTest — Browser automation with MSTest lifecycle and parallel execution.
- Base classes —
BaseTestfor setup/teardown;BasePagefor page objects with automatic step reporting. - HTML reports — Generated in
TestResultswith screenshots on failure viaHtmlResult. - Reporting APIs —
ReportResult(UI) andReportResultAPI(API) for pass/fail/info steps. - Configuration —
.runsettingsand environment-specifictestdata.jsonwithConfigManager. - CI/CD — Override settings with
STAF_-prefixed environment variables. - Browser state persistence — Reuse login sessions across tests (cookies + storage). Supports automated login and optional manual MFA for local runs; use a non-MFA account in CI/CD (see Browser state and login).
- Extras — Excel driver, SQL client, OpenAPI contract testing support.
- MCP support — Use the Playwright C# MCP server with Cursor, VS Code, or Visual Studio for AI-assisted test and page object generation.
Key Components
| Component | Purpose |
|---|---|
| BaseTest | Initializes Playwright browser/context/page, base URL navigation, optional browser state reuse and login (see Browser state and login), cleanup, and execution timing. |
| BasePage | Page object base with GetLocator, FindAppElementAsync, ClickAsync, EnterTextAsync, PressAsync and automatic step reporting. |
| HtmlResult | Builds HTML result files and embeds screenshots for failed steps. |
| ReportResult | Reports UI test steps (pass/fail) and integrates with HtmlResult. |
| ReportResultAPI | Reports API test steps (pass/fail) for use in API test classes. |
| ConfigManager | Loads .runsettings and testdata.json, supports environment and STAF_ env overrides. |
Reporting
Automatic (default)
- UI: When using
BasePagemethods (FindAppElementAsync,ClickAsync,EnterTextAsync,PressAsync,GetLocator), steps are reported automatically. - API: When using
ApiClientwithTestContext(e.g. inTestBaseAPI), each request is reported by status (pass/fail).
Manual
ReportResult.ReportResultPass(Page, TestContext, "TestName", "Details.");
ReportResult.ReportResultFail(Page, TestContext, "TestName", "Details.");
ReportResultAPI.ReportResultPass(TestContext, "Module/Function", "Details");
ReportResultAPI.ReportResultFail(TestContext, "Module/Function", "Details");
Configuration
- Prerequisites: .NET 10 or above, MSTest, Microsoft.Playwright.
- Run settings: Use a
testsetting.runsettingsfile (e.g.Environment,BaseUrl,ApiBaseUrl,Browser,Headless). See CONFIGURATION.md for details. - Test data: Optional
testdata.jsonandtestdata.{Environment}.jsonmerged byConfigManager. - Environment variables: Override any runsettings parameter with
STAF_prefix (e.g.STAF_BaseUrl,STAF_Environment).
Browser state and login
When BrowserStateEnabled is true, the framework can reuse login sessions across tests by saving and loading browser state (cookies, localStorage) in browserstate_<username>.json. Configure LoginUrl and optional selectors for automated username/password + submit.
- Local runs: You can use MFAEnabled =
trueso the framework enters credentials and then waits for you to complete MFA manually in the browser; after that, state is saved and reused. Manual MFA is intended for local development only. - CI/CD: Use a user account that does not require MFA (e.g. a dedicated test/service account with MFA disabled). Set MFAEnabled =
falseand provide Username and Password in runsettings or viaSTAF_Username/STAF_Password(use secrets in your pipeline). The framework will perform a fully automated login and save state so subsequent tests reuse the session. Manual MFA cannot be completed in headless or unattended CI agents.
See CONFIGURATION.md – Browser State Persistence for all parameters (SmartSessionRefresh, ForceLoginRefresh, LoginVerificationUrl, etc.).
Using the MCP agent (Playwright C# MCP)
You can use the Playwright C# MCP server with STAF.Playwright for AI-assisted development: generate and refine tests and page objects from natural language in Cursor, VS Code, or Visual Studio. A ready-to-run sample with the MCP agent configured is in the STAF.Playwright.Tests repository.
Prerequisites
- .NET 10 SDK
- One of: Cursor, VS Code (with GitHub Copilot), or Visual Studio 2022 (17.14+ with GitHub Copilot)
Sample repository setup
- Clone the sample repo and open it as your workspace:
git clone https://github.com/sooraj171/STAF.Playwright.Tests.git cd STAF.Playwright.Tests - Open the repo root as the workspace (Cursor/VS Code: File ? Open Folder ? repo root; Visual Studio: File ? Open ? Project/Solution ?
STAF.Playwright.Tests.sln).
The repo includes the MCPAgent/ (Playwright C# MCP server), .cursor/mcp.json, .vscode/mcp.json, and .mcp.json (Visual Studio) so the MCP server is available without extra setup.
Cursor
- Open the STAF.Playwright.Tests repo as the workspace.
- Go to Cursor Settings ? Features ? MCP and ensure the project MCP is enabled.
- The Playwright C# tools appear in the AI/composer; use them to generate or refine tests and page objects.
- Cursor rules in
.cursor/rules/staf-playwright-framework.mdcare applied automatically so generated code follows STAF.Playwright patterns (base classes, page objects, reporting).
VS Code (GitHub Copilot)
- Open the repo as the workspace and ensure GitHub Copilot is set up.
- The first time you use the MCP server, trust it when prompted.
- In Copilot Chat, enable the playwrightCsharp tools and use Copilot (e.g. Agent mode) to generate or refine STAF.Playwright tests and page objects.
- Repo-level guidance is in
.github/copilot-instructions.md.
Visual Studio
- Open
STAF.Playwright.Tests.sln. Visual Studio picks up.mcp.jsonat the solution root. - In GitHub Copilot chat, switch to Agent mode, enable the playwrightCsharp tools, then ask Copilot to generate or refine tests or page objects (approve tool use when prompted).
- If the server does not start, set the
"command"in.mcp.jsonto the full path toMCPAgent/PlaywrightCSharpMcp.exe. See Use MCP servers in Visual Studio.
Summary
| Editor | Config / rules | MCP tools |
|---|---|---|
| Cursor | .cursor/mcp.json, .cursor/rules/staf-playwright-framework.mdc |
playwrightCsharp |
| VS Code | .vscode/mcp.json, .github/copilot-instructions.md |
playwrightCsharp |
| Visual Studio | .mcp.json at solution root |
playwrightCsharp |
For full details, clone sooraj171/STAF.Playwright.Tests and follow the README there.
Repository and support
- Source and issues: GitHub – STAF.Playwright.Tests
- MCP Playwright C# sample (Cursor, VS Code, Visual Studio): STAF.Playwright.Tests — clone for Playwright C# MCP server, rules, and config.
- Author: Sooraj Ramachandran
- Contributions and issues are welcome.
License and copyright
This project is licensed under the MIT License.
Copyright © 2026 Sooraj Ramachandran.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ClosedXML (>= 0.105.0)
- Microsoft.Data.SqlClient (>= 7.0.0)
- Microsoft.OpenApi (>= 3.5.2)
- Microsoft.Playwright (>= 1.59.0)
- MSTest.TestAdapter (>= 4.2.1)
- MSTest.TestFramework (>= 4.2.1)
- NJsonSchema (>= 11.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.