STAF.UI.API 4.4.2

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

STAF - Simple Test Automation Framework

C# Selenium | .NET Selenium Framework | MCP Server for Selenium C# | Selenium WebDriver C# | Test Automation .NET | UI Testing C# | API Testing .NET | MSTest Selenium

NuGet .NET 10 License: MIT

STAF is a production-ready .NET test automation framework for Selenium-based UI testing, API testing, and Excel validation. It provides base classes, HTML reporting, parallel execution, and optional database and accessibility support. The framework is distributed as the STAF.UI.API NuGet package and targets .NET 10 with MSTest.

Note: This release targets .NET 10. Projects consuming STAF.UI.API must use .NET 10 or above.


Table of Contents


AI-assisted development and MCP (implementation repo)

This repository contains the STAF.UI.API framework source and ships the NuGet package. It does not include the MCP server executable or editor-specific AI configuration—those live in the official implementation / sample repository so you can pair the package with real projects and tooling.

Use this together with the implementation project:

Piece Where it lives
STAF.UI.API NuGet package This repo / NuGet.org — add it to any .NET 10+ test project
Sample solution, MCP server, and AI workflows STAF.Selenium.Tests on GitHub

STAF.Selenium.Tests is the official template that references STAF.UI.API and adds:

  • MCP (Model Context Protocol) server for Selenium + STAF — a self-contained agent you can attach to Cursor, VS Code, or Visual Studio (Copilot agent mode) to drive browsers and generate tests from natural language.
  • Editor rules — e.g. .cursor/rules, .github/copilot-instructions.md, and repo-level .mcp.json so assistants follow STAF patterns (TestBaseClass, FindAppElement, ReportResult, etc.).
  • Working samples for UI, API, Excel, database, reporting, accessibility, and parallel runs.

Clone the implementation repo to run MCP, copy its config into your own solution, or start new suites from the template while keeping STAF.UI.API as the shared framework dependency:

git clone https://github.com/sooraj171/STAF.Selenium.Tests
cd STAF.Selenium.Tests
dotnet restore
dotnet build

For MCP setup (paths to MCPAgent/publish/..., tool list, troubleshooting), see MCPAgent/README.md and the main README in STAF.Selenium.Tests.


Overview

STAF streamlines automated testing for web applications and APIs using Selenium WebDriver and C#. It supports:

Area Capability
UI automation Page Object Model-style tests with Selenium (Chrome, Edge, local or remote)
API automation REST-style tests with the same reporting and lifecycle as UI tests
HTML reporting Per-test and assembly-level HTML reports with pass/fail summary and optional screenshots
Parallel execution Per-test AsyncLocal state, per-report-file locking, file-based assembly accumulator; MSTest parallelization (method-level, configurable workers)
Excel Compare workbooks/sheets and read/write cell data via ClosedXML
Database SQL Server helpers (connection, query, scalar, non-query) using configuration
Accessibility Axe-core (Deque.AxeCore.Selenium) integration for accessibility scans and HTML reports
AI / MCP (optional) Not in this repo — use STAF.Selenium.Tests with this NuGet package for an MCP server and Cursor / Copilot integration

Features

Feature Description
Base classes TestBaseClass (UI), TestBaseAPI (API), PageBaseClass (elements and waits)
Browser support Chrome, Edge; local or remote WebDriver. Overridable options and driver creation
HTML reporting In-test step reporting (Pass/Fail/Warn/Info) and assembly summary (ResultTemplateFinal.html)
Parallel execution Parallel-safe paths and fail flags (AsyncLocal); per-file HTML locks; MSTest Parallelize (e.g. 4 workers, method scope)
Excel Compare two workbooks/sheets; get/set cell data; row/column counts
Database DbHelper: connection strings from config, execute query/scalar/non-query
Configuration appsettings.json (resolved from base directory, assembly folder, or cwd) and run settings (browser, headless, driver path, URL, test parameters)
Email Optional email of test results (SMTP via config or TestContext)
Accessibility Axe-core page/element scans and styled HTML reports
Report generator TestReportGenerator.GenerateTestReport(filePath, TestResultData) for programmatic HTML (plus sidecar CSS/JS)
AI-assisted authoring Implemented in STAF.Selenium.Tests via MCP + editor rules; consumes STAF.UI.API like any other test project

Key Components

Test and Page Base Classes

Class Purpose
TestBaseClass Inherit for UI tests. Initializes WebDriver (from TestContext/run settings), sets up per-test HTML result file, and cleans up (including reporting to the assembly summary)
TestBaseAPI Inherit for API tests. Same startup/cleanup and reporting as UI tests, without a browser
PageBaseClass Wraps element location with wait: FindAppElement(By), FindAppElement(By, description), FindAppElement(parent, By, description)

Browser and Driver

Class Purpose
BrowserDriver Creates IWebDriver for Chrome or Edge, local or remote. Override parameterless SetChromeOptions() / SetEdgeOptions() for custom arguments; optional headless runsetting applies headless flags after your options

Reporting

Class Purpose
ReportResult Log steps for UI tests: ReportResultPass/Fail/Warn/Info(driver, TestContext, moduleName, description[, exception])
ReportResultAPI Same for API tests: ReportResultPass/Fail/Warn/Info(TestContext, moduleName, description[, exception])
HtmlResult Creates and appends to per-test HTML files. Used by report classes; supports screenshots on fail
ReportElement (extensions) Assert and report in one call: ReportElementExists, ReportElementIsDisplayed, ReportElementIsEnabled (with optional proceed-on-fail flag)

WebDriver Extensions

Method Purpose
CloseAllTabsExceptCurrent Close all browser tabs except the current one
getTotalTabsCount Return number of open tabs
waitForFindElement Find element with explicit timeout (uses SeleniumWaitConditions.ElementExists)
SeleniumWaitConditions Selenium 4 wait predicates for WebDriverWait (replaces legacy ExpectedConditions / WaitHelpers)
waitForElementExist / waitForElementNotExist Wait for element presence/absence
WaitForElementDisapper Wait until element is no longer present (By)
WaitForDocumentReady Wait for document ready and (if present) jQuery idle (default timeout 30 seconds; optional timeoutSeconds parameter)

Excel, Database & Accessibility

Class Purpose
ExcelDriver CompareFiles, GetExcelWorkbook, GetExcelCellData, SetExcelCellData, GetExcelRowCount, GetExcelColumnCount
DbHelper Connection strings from AppConfig. OpenConnection, VerifyConnection, ExecuteQuery, ExecuteScalar, ExecuteNonQuery
AxeAccessibility Deque Axe-core: AnalyzePage(), AnalyzePageAndSaveHtml(), AnalyzeCssSelector(), AnalyzeElement(), AnalyzeWithConfigurator()

Getting Started

Prerequisites

  • .NET 10 SDK
  • Visual Studio 2022 (or later) or VS Code with C# extension
  • Chrome or Edge (for UI tests)
  • MSTest (included via package reference)

Install

  1. Add the NuGet package to your test project:

    dotnet add package STAF.UI.API
    

    Or use the STAF.Selenium.Tests implementation project for samples, runsettings, and optional MCP / AI tooling (see AI-assisted development and MCP).

  2. Configure run settings: Test > Configure Run Settings > Select Solution Wide runsettings File > choose testrunsetting.runsettings.

  3. Build and run tests from Test Explorer or CLI: dotnet test.

Sample UI Test

[TestMethod]
public void TestLogin()
{
    var element = FindAppElement(By.Id("loginButton"), "Login button");
    ReportResult.ReportResultPass(driver, TestContext, "Login", "Login button is visible");
}

Sample API Test

[TestMethod]
public void TestAPIStatus()
{
    ReportResultAPI.ReportResultPass(TestContext, "API", "Status check passed");
}

Configuration

Run settings (testrunsetting.runsettings)

  • TestRunParameters: browser (e.g. chrome), driverPath, url, optional email/smtp settings
  • headless: set to true for CI/agents (Chrome/Edge headless is applied after your SetChromeOptions / SetEdgeOptions overrides)
  • killOrphanChromedrivers: default false. Set to true only on isolated agents if you still need assembly-level cleanup that terminates all chromedriver processes (avoid on shared build machines)
  • MSTest: Parallelize (e.g. Workers=4, Scope=MethodLevel)
  • ResultsDirectory: e.g. .\TestResults

appsettings.json

AppConfig.GetConfig() looks for appsettings.json in this order: AppContext.BaseDirectory, the executing assembly directory, then Directory.GetCurrentDirectory(). The first match wins.

  • ConnectionStrings: e.g. DefaultConnection for DbHelper
  • Email: SmtpHost, SmtpPort, UseDefaultCred, Username, Password (optional)

Overriding browser options

protected override ChromeOptions SetChromeOptions()
{
    var options = new ChromeOptions();
    options.AddArguments("start-maximized");
    return options;
}

Use runsetting headless=true for pipelines; the framework adds headless arguments after this method runs, so existing overrides stay valid.


Reporting

In-test step reporting

ReportResult.ReportResultPass(driver, TestContext, "ModuleName", "Description");
ReportResult.ReportResultFail(driver, TestContext, "ModuleName", "Description", "exception text");

// API tests (no driver)
ReportResultAPI.ReportResultPass(TestContext, "ModuleName", "Description");

Element assertions with reporting

element.ReportElementExists(driver, TestContext, testName, "Element exists", ProdceedFlag: true);
element.ReportElementIsDisplayed(driver, TestContext, testName, "Element is displayed", ProdceedFlag: true);

Assembly summary

After all tests, AssemblyCleanup merges per-test HTML fragments using a file-based accumulator, appends them to ResultTemplate.html, and copies the outcome to ResultTemplateFinal.html next to the test run output. Those files are created under TestContext.TestRunDirectory when the test host provides it (typical under TestResults); otherwise the framework falls back to the test assembly base directory.

Fail screenshots are written next to the per-test HTML report with unique names; the report still embeds them as base64 for the same in-browser experience as before.

Programmatic HTML (TestReportGenerator)

TestReportGenerator.GenerateTestReport(@"C:\out\my_report.html", myTestResultData);

Use a unique filePath when multiple processes or tools might generate reports at the same time.


Parallel execution and thread safety

  • Per-test state (result HTML path, failure flag) uses AsyncLocal so parallel MSTest workers do not overwrite each other. The framework still mirrors failFlag and per-test path keys to environment variables for backward compatibility in sequential runs.
  • HTML append uses a lock per report file path, not one global lock, so different tests can write their own reports concurrently.
  • ReportResult / ReportResultAPI resolve the report file via the active test context first, then fall back to Environment.GetEnvironmentVariable(TestContext.TestName) if you use a custom startup path.

Upgrading and migration

When updating from older STAF.UI.API builds, check the following:

Topic What changed
ChromeDriver cleanup Killing every chromedriver process at assembly start/end is off by default. Set killOrphanChromedrivers=true in runsettings only if you need the old behavior on a dedicated agent.
Aggregate report location ResultTemplate.html, ResultBodyAccumulator.txt, and the merged ResultTemplateFinal.html path are rooted in TestRunDirectory when available. Pipelines or scripts that assumed bin\Debug\... only should publish TestResults (or your configured ResultsDirectory) instead.
Headless CI Prefer headless=true in runsettings rather than only custom options.
TestReportGenerator Use the public GenerateTestReport(string filePath, TestResultData results) API; avoid hard-coding a shared filename like test_report.html when running in parallel.
Public API Existing entry points (TestBaseClass, TestBaseAPI, CommonAction.setStartUpValues / setCleanUpValues, ReportResult, HtmlResult, parameterless SetChromeOptions / SetEdgeOptions) are preserved for consuming projects.

Usage Guide

Excel comparison

var excel = new ExcelDriver();
ExcelCompareStatus res = excel.CompareFiles("path/Excel1.xlsx", "path/Excel2.xlsx", sheetIndex1: 1, sheetIndex2: 1);
if (res.IsMatching) return true;

Accessibility (Axe)

var axe = new AxeAccessibility(driver);
axe.AnalyzePage();                                    // Full page scan
axe.AnalyzePageAndSaveHtml("report.html");            // Run and save HTML report
axe.AnalyzeCssSelector("#main");                      // Scoped scan
axe.AnalyzeWithConfigurator(b => b.Include(".modal")); // Custom configuration

Database (DbHelper)

Configure connection in appsettings.json under ConnectionStrings:DefaultConnection, then use:

DbHelper.VerifyConnection();
var value = DbHelper.ExecuteScalar<int>("SELECT COUNT(*) FROM Users");

License

This project is licensed under the MIT License.

Author: Sooraj Ramachandran
Copyright (c) 2026 Sooraj Ramachandran. All rights reserved.


Links
NuGet: STAF.UI.API
Implementation project, samples & MCP (AI): STAF.Selenium.Tests

This software is provided "as is", without warranty of any kind. See the license for full terms.

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
4.4.2 0 6/4/2026
4.4.0 139 3/2/2026
4.3.3 160 12/30/2025
4.3.0 347 11/16/2025
4.2.0 275 10/31/2025
4.1.0 353 8/7/2025
4.0.3 293 6/26/2025
4.0.2 259 3/28/2025
4.0.0 288 3/20/2025
3.4.1 695 12/12/2023
3.3.0 1,005 7/16/2023
3.2.9 695 5/21/2023
3.2.8 1,268 4/20/2023
3.2.1 722 4/7/2023
3.2.0 753 4/1/2023
3.1.7 794 2/5/2023
3.1.0 816 1/25/2023
3.0.0 830 1/17/2023
2.0.2 872 1/16/2023
Loading failed

This release targets .NET 10. Underlying projects consuming STAF.UI.API must use .NET 10 or above.
UI and API test framework for Selenium.
Supports Chrome, Edge & Remote Drivers.
Supports Parallel execution and is thread safe.
Click the repository link to setup and get started quickly with a sample project.
https://github.com/sooraj171/STAF.Selenium.Tests