STAF.Playwright
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package STAF.Playwright --version 1.0.1
NuGet\Install-Package STAF.Playwright -Version 1.0.1
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.Playwright" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="STAF.Playwright" Version="1.0.1" />
<PackageReference Include="STAF.Playwright" />
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.Playwright --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: STAF.Playwright, 1.0.1"
#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.Playwright@1.0.1
#: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.Playwright&version=1.0.1
#tool nuget:?package=STAF.Playwright&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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!
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Playwright (>= 1.50.0)
- MSTest.TestAdapter (>= 3.8.0)
- MSTest.TestFramework (>= 3.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.