STAF.Playwright 2.2.0

dotnet add package STAF.Playwright --version 2.2.0
                    
NuGet\Install-Package STAF.Playwright -Version 2.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="STAF.Playwright" Version="2.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="STAF.Playwright" Version="2.2.0" />
                    
Directory.Packages.props
<PackageReference Include="STAF.Playwright" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add STAF.Playwright --version 2.2.0
                    
#r "nuget: STAF.Playwright, 2.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package STAF.Playwright@2.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=STAF.Playwright&version=2.2.0
                    
Install as a Cake Addin
#tool nuget:?package=STAF.Playwright&version=2.2.0
                    
Install as a Cake Tool

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#.

NuGet
.NET 10
License: MIT


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

  1. Add the package to your test project (see above).
  2. Inherit from BaseTest in your test classes to get Playwright browser, context, and page setup/teardown.
  3. Use BasePage for 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 classesBaseTest for setup/teardown; BasePage for page objects with automatic step reporting.
  • HTML reports — Generated in TestResults with screenshots on failure via HtmlResult.
  • Reporting APIsReportResult (UI) and ReportResultAPI (API) for pass/fail/info steps.
  • Configuration.runsettings and environment-specific testdata.json with ConfigManager.
  • 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 BasePage methods (FindAppElementAsync, ClickAsync, EnterTextAsync, PressAsync, GetLocator), steps are reported automatically.
  • API: When using ApiClient with TestContext (e.g. in TestBaseAPI), 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.runsettings file (e.g. Environment, BaseUrl, ApiBaseUrl, Browser, Headless). See CONFIGURATION.md for details.
  • Test data: Optional testdata.json and testdata.{Environment}.json merged by ConfigManager.
  • 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 = true so 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 = false and provide Username and Password in runsettings or via STAF_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

  1. Clone the sample repo and open it as your workspace:
    git clone https://github.com/sooraj171/STAF.Playwright.Tests.git
    cd STAF.Playwright.Tests
    
  2. 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

  1. Open the STAF.Playwright.Tests repo as the workspace.
  2. Go to Cursor Settings ? Features ? MCP and ensure the project MCP is enabled.
  3. The Playwright C# tools appear in the AI/composer; use them to generate or refine tests and page objects.
  4. Cursor rules in .cursor/rules/staf-playwright-framework.mdc are applied automatically so generated code follows STAF.Playwright patterns (base classes, page objects, reporting).

VS Code (GitHub Copilot)

  1. Open the repo as the workspace and ensure GitHub Copilot is set up.
  2. The first time you use the MCP server, trust it when prompted.
  3. In Copilot Chat, enable the playwrightCsharp tools and use Copilot (e.g. Agent mode) to generate or refine STAF.Playwright tests and page objects.
  4. Repo-level guidance is in .github/copilot-instructions.md.

Visual Studio

  1. Open STAF.Playwright.Tests.sln. Visual Studio picks up .mcp.json at the solution root.
  2. 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).
  3. If the server does not start, set the "command" in .mcp.json to the full path to MCPAgent/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


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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0 98 4/24/2026
2.1.0 117 3/4/2026
2.0.0 112 2/12/2026
1.2.0 111 2/7/2026
1.1.0 226 11/23/2025
1.0.2 220 10/31/2025
1.0.1 154 9/12/2025