SimpleApiPlaywright 1.0.4
dotnet add package SimpleApiPlaywright --version 1.0.4
NuGet\Install-Package SimpleApiPlaywright -Version 1.0.4
<PackageReference Include="SimpleApiPlaywright" Version="1.0.4" />
<PackageVersion Include="SimpleApiPlaywright" Version="1.0.4" />
<PackageReference Include="SimpleApiPlaywright" />
paket add SimpleApiPlaywright --version 1.0.4
#r "nuget: SimpleApiPlaywright, 1.0.4"
#:package SimpleApiPlaywright@1.0.4
#addin nuget:?package=SimpleApiPlaywright&version=1.0.4
#tool nuget:?package=SimpleApiPlaywright&version=1.0.4
SimpleApiPlaywright
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:
- API Only: For standalone API testing. Requires only
IAPIRequestContext. - 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 forIAPIRequestContextandIPage.TokenStorage: Centralized, parallel-safe authentication management.
Part of a larger portfolio demonstrating advanced automation patterns. See the Implementation Demo.
| 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
- Microsoft.Playwright (>= 1.59.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.