![]() |
VOOZH | about |
dotnet add package STAF.UI.API --version 4.4.2
NuGet\Install-Package STAF.UI.API -Version 4.4.2
<PackageReference Include="STAF.UI.API" Version="4.4.2" />
<PackageVersion Include="STAF.UI.API" Version="4.4.2" />Directory.Packages.props
<PackageReference Include="STAF.UI.API" />Project file
paket add STAF.UI.API --version 4.4.2
#r "nuget: STAF.UI.API, 4.4.2"
#:package STAF.UI.API@4.4.2
#addin nuget:?package=STAF.UI.API&version=4.4.2Install as a Cake Addin
#tool nuget:?package=STAF.UI.API&version=4.4.2Install as a Cake Tool
C# Selenium | .NET Selenium Framework | MCP Server for Selenium C# | Selenium WebDriver C# | Test Automation .NET | UI Testing C# | API Testing .NET | MSTest Selenium
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.
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:
.cursor/rules, .github/copilot-instructions.md, and repo-level .mcp.json so assistants follow STAF patterns (TestBaseClass, FindAppElement, ReportResult, etc.).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.
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 |
| 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) |
| 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 |
| 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) |
| 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 |
| 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) |
| 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) |
| 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() |
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).
Configure run settings: Test > Configure Run Settings > Select Solution Wide runsettings File > choose testrunsetting.runsettings.
Build and run tests from Test Explorer or CLI: dotnet test.
[TestMethod]
public void TestLogin()
{
var element = FindAppElement(By.Id("loginButton"), "Login button");
ReportResult.ReportResultPass(driver, TestContext, "Login", "Login button is visible");
}
[TestMethod]
public void TestAPIStatus()
{
ReportResultAPI.ReportResultPass(TestContext, "API", "Status check passed");
}
testrunsetting.runsettings)browser (e.g. chrome), driverPath, url, optional email/smtp settingsheadless: 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)Parallelize (e.g. Workers=4, Scope=MethodLevel).\TestResultsAppConfig.GetConfig() looks for appsettings.json in this order: AppContext.BaseDirectory, the executing assembly directory, then Directory.GetCurrentDirectory(). The first match wins.
DefaultConnection for DbHelperprotected 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.
ReportResult.ReportResultPass(driver, TestContext, "ModuleName", "Description");
ReportResult.ReportResultFail(driver, TestContext, "ModuleName", "Description", "exception text");
// API tests (no driver)
ReportResultAPI.ReportResultPass(TestContext, "ModuleName", "Description");
element.ReportElementExists(driver, TestContext, testName, "Element exists", ProdceedFlag: true);
element.ReportElementIsDisplayed(driver, TestContext, testName, "Element is displayed", ProdceedFlag: true);
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.
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.
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.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.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. |
var excel = new ExcelDriver();
ExcelCompareStatus res = excel.CompareFiles("path/Excel1.xlsx", "path/Excel2.xlsx", sheetIndex1: 1, sheetIndex2: 1);
if (res.IsMatching) return true;
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
Configure connection in appsettings.json under ConnectionStrings:DefaultConnection, then use:
DbHelper.VerifyConnection();
var value = DbHelper.ExecuteScalar<int>("SELECT COUNT(*) FROM Users");
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 for full terms.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.4.2 | 96 | 6/4/2026 |
| 4.4.0 | 143 | 3/2/2026 |
| 4.3.3 | 164 | 12/30/2025 |
| 4.3.0 | 352 | 11/16/2025 |
| 4.2.0 | 278 | 10/31/2025 |
| 4.1.0 | 356 | 8/7/2025 |
| 4.0.3 | 297 | 6/26/2025 |
| 4.0.2 | 265 | 3/28/2025 |
| 4.0.0 | 291 | 3/20/2025 |
| 3.4.1 | 697 | 12/12/2023 |
| 3.3.0 | 1,007 | 7/16/2023 |
| 3.2.9 | 697 | 5/21/2023 |
| 3.2.8 | 1,269 | 4/20/2023 |
| 3.2.1 | 722 | 4/7/2023 |
| 3.2.0 | 754 | 4/1/2023 |
| 3.1.7 | 794 | 2/5/2023 |
| 3.1.0 | 817 | 1/25/2023 |
| 3.0.0 | 830 | 1/17/2023 |
| 2.0.2 | 876 | 1/16/2023 |
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