SimpleApiPlaywright 1.0.4

dotnet add package SimpleApiPlaywright --version 1.0.4
                    
NuGet\Install-Package SimpleApiPlaywright -Version 1.0.4
                    
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="SimpleApiPlaywright" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpleApiPlaywright" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="SimpleApiPlaywright" />
                    
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 SimpleApiPlaywright --version 1.0.4
                    
#r "nuget: SimpleApiPlaywright, 1.0.4"
                    
#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 SimpleApiPlaywright@1.0.4
                    
#: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=SimpleApiPlaywright&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=SimpleApiPlaywright&version=1.0.4
                    
Install as a Cake Tool

SimpleApiPlaywright

NuGet npm GitHub

Make API requests like this:

var response = await UsersApi.CreateUser(user).RequestAsync();

Or API waits like this:

var userResponseTask = UsersApi.GetUser().WaitAsync();
await Task.WhenAll(
    Page.LoginButton.ClickAsync(),
    userResponseTask
);

Before that, define your API endpoints like this:

using SimpleApiPlaywright;
using SimpleApiPlaywright.Types;

public class UsersApi : ApiEndpointBase("api/users")
{
public ApiAction<UserResponse> GetUser() =>
    Action<UserResponse>(new() { Url = "login", Method = ApiHttpMethod.GET } );

public ApiAction<UserResponse> CreateUser(UserPayload payload) =>
    Action<UserResponse>(new() { Url = "login", Method = ApiHttpMethod.POST, Body = payload } );
}

A lightweight wrapper for Playwright .NET that unifies API requests and UI network assertions. Designed for high-performance automation suites requiring parallel execution and clean architecture.

🚀 Key Features

  • Unified Interface: Use the same endpoint definitions for standalone API tests (RequestAsync) and UI network synchronization (WaitAsync).
  • Parallel Safe: Built-in AsyncLocal<ApiContext> management prevents state leakage across concurrent tests.
  • Smart Assertions: Automatic status code validation with descriptive error messages including method and route details.
  • Tracing Integration: Automatically groups requests in Steps (Playwright Trace Groups) for better debugging.
  • Global Configuration: Set base URLs and timeouts once at the suite level.

📖 Usage Modes

The library is flexible and adapts to your testing context:

  1. API Only: For standalone API testing. Requires only IAPIRequestContext.
  2. UI Integrated: For waiting on network calls triggered by UI actions. Requires IPage.

📦 Installation

dotnet add package SimpleApiPlaywright

🛠️ Quick Start

1. Define your Endpoint

using SimpleApiPlaywright;
using SimpleApiPlaywright.Types;

public class UsersApi : ApiEndpointBase("api/users")
{
public ApiAction<UserResponse> GetUser() =>
    Action<UserResponse>(new() { Url = "login", Method = ApiHttpMethod.GET } );

public ApiAction<UserResponse> CreateUser(UserPayload payload) =>
    Action<UserResponse>(new() { Url = "login", Method = ApiHttpMethod.POST, Body = payload } );
}

2. Global & Test Setup

Before executing requests, you must initialize the global configuration and set the current test context (usually in a test hook):

// Once per suite:
ApiClient.SetInitialConfig(apiWaitTimeout: 5000, expectedStatusCodes: [200, 201], baseUrl: "https://api.example.com");

// Once per test (mandatory):
ApiClient.SetContext(new ApiContext(requestContext, page)); 

3. Standalone API Call

Requires IAPIRequestContext context

var response = await Api.Auth.PostLogin(credentials).RequestAsync();
Assert.Equal(200, response.Response.Status);

4. UI Synchronization (XHR/Fetch)

Requires IPage context

// Define the task to wait for the network response
var loginTask = Api.Auth.PostLogin(credentials).WaitAsync();

// Trigger the UI action
await Page.GetByRole(AriaRole.Button, new() { Name = "Login" }).ClickAsync();

// Await the network response
var response = await loginTask;

🏗️ Architecture

SimpleApiPlaywright is built with SDET efficiency in mind:

  • ApiClient: Core engine handling the request/wait logic.
  • ApiContext: Thread-safe container for IAPIRequestContext and IPage.
  • TokenStorage: Centralized, parallel-safe authentication management.

Part of a larger portfolio demonstrating advanced automation patterns. See the Implementation Demo.

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
1.0.4 96 4/24/2026
1.0.3 99 4/21/2026
1.0.2 82 4/21/2026
1.0.1 92 4/20/2026
1.0.0 105 4/15/2026