STAF.Playwright
1.1.0
dotnet add package STAF.Playwright --version 1.1.0
NuGet\Install-Package STAF.Playwright -Version 1.1.0
<PackageReference Include="STAF.Playwright" Version="1.1.0" />
<PackageVersion Include="STAF.Playwright" Version="1.1.0" />
<PackageReference Include="STAF.Playwright" />
paket add STAF.Playwright --version 1.1.0
#r "nuget: STAF.Playwright, 1.1.0"
#:package STAF.Playwright@1.1.0
#addin nuget:?package=STAF.Playwright&version=1.1.0
#tool nuget:?package=STAF.Playwright&version=1.1.0
STAF.Playwright
About:
- STAF stands for Simple Test Automation Framework.
- STAF.Playwright is a NuGet package for Page Object Model implementation using Microsoft Playwright and MSTest.
Overview
This repository contains an automation test framework built using Microsoft Playwright and C#. It is designed to streamline the creation and execution of automated UI tests for web applications, providing efficient reporting, error handling, and easy extensibility.
The framework consists of the following key components:
- BaseTest: A base test class for initializing and cleaning up Playwright browser, context, and page objects.
- HtmlResult: A utility class to handle HTML reporting of test results, including screenshots for failed steps.
- ReportResult & ReportResultAPI: Utility classes for reporting test results (pass/fail/info) for UI and API scenarios.
What it has
- STAF is a test automation framework for C# projects using Playwright.
- Supports UI automation using Playwright with MSTest.
- Provides base classes for easy test and page object inheritance.
- Generates detailed HTML reports with screenshots for failures.
- Parallel execution support.
- Maintained by https://github.com/sooraj171
How to implement
From your Visual Studio IDE:
- Install the NuGet package
STAF.Playwrightinto your test project. - Reference your test project to the framework.
- Inherit from
BaseTestfor your test classes. - Use the provided reporting utilities for result logging.
- Build and run your tests from Test Explorer.
How to Use the Reporting options
Usage:
ReportResult.ReportResultPass(Page, TestContext, "TestName", "Details.");
ReportResultAPI.ReportResultPass(TestContext, "ModuleName/FunctionName", "Details");
Other Options:
ReportResultFailReportResultAPI.ReportResultFail
Key Classes
1. BaseTest
- Purpose: Handles Playwright browser, context, and page initialization and cleanup. Provides access to Playwright objects and test context.
- Main Features:
- Initializes Playwright browser and page for each test.
- Handles navigation to base URL.
- Cleans up resources after test execution.
- Records test execution time.
2. HtmlResult
- Purpose: Generates HTML reports for test results, including screenshots for failed steps.
- Main Features:
- Creates and appends to HTML result files.
- Embeds screenshots for failed steps.
- Marks test status (Pass/Fail/Not Run).
3. ReportResult & ReportResultAPI
- Purpose: Utility classes for reporting test results.
- Main Features:
- Report test results with various statuses: Pass, Fail.
- Integrates with
HtmlResultfor HTML reporting. - Can be used for both Playwright-based UI tests and API-related tests.
Setup & Configuration
Prerequisites
- .NET 8 (or compatible .NET version)
- Microsoft.Playwright: Used for browser automation.
- MSTest: Used for test structure and execution.
Environment Variables
BaseUrl: The base URL for your tests.currTestName: The current test name (set automatically by the framework).- Test Report Location: Reports are generated in the
TestResultsdirectory by default.
Running Tests
Web Tests
- Inherit from BaseTest: Your test classes should inherit from
BaseTest. - Write Test: Create test methods using MSTest attributes. Example:
[TestMethod]
public async Task TestLogin()
{
await Page.GotoAsync("https://example.com/login");
// Test code here
await ReportResult.ReportResultPass(Page, TestContext, "Login", "Login page loaded successfully");
}
API Tests
- Use
ReportResultAPIfor reporting API test results. Example:
[TestMethod]
public void TestAPIStatus()
{
// API test code here
ReportResultAPI.ReportResultPass(TestContext, "API", "Status check passed");
}
For more details and sample usage, see the GitHub repository.
Contributions and issues are welcome!
License:
This project is licensed under the MIT License.
� 2025 Sooraj Ramachandran. All Rights Reserved.
THIS 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 AUTHOR 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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- ClosedXML (>= 0.105.0)
- Microsoft.Playwright (>= 1.56.0)
- MSTest.TestAdapter (>= 4.0.2)
- MSTest.TestFramework (>= 4.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.