A comprehensive demonstration framework showcasing advanced UI test automation using Playwright with .NET (C#) and NUnit.
This project serves as a practical example and learning resource, illustrating best practices for building robust and maintainable tests.
- Foundation:
- Page Object Model (POM) for clean UI interaction logic.
- Reusable Element Abstractions (Button, TextBox, etc.) and Page Fragments (e.g. Navigation).
- Configuration:
- Easily configure test runs (browser, headless mode, timeouts, etc.) via
.runsettings
files. - Centralized
Settings.cs
for accessing configuration values.
- Easily configure test runs (browser, headless mode, timeouts, etc.) via
- Diagnostics & Artifacts:
- Detailed logging per test using Serilog.
- Configurable Playwright Tracing (Always, OnFail, Never) for easy debugging via
trace.playwright.dev
. - Configurable Video Recording (Always, OnFail, Never).
- On-demand Screenshot generation for pages or elements.
- Execution:
- Custom Retry Logic (
UIRetryAttribute
) specifically designed for flaky UI tests. - Support for parallel execution via NUnit attributes.
- Custom Retry Logic (
- Test Capabilities:
- Examples of Functional, Visual Comparison (using ImageSharpCompare), Accessibility (using AxeCore), and Performance metric tests.
- Custom HTML Reporting:
- Standalone reporting tool generates a detailed HTML report from NUnit results.
- Automatically links artifacts (logs, videos, traces, screenshots) directly to test results in the report.
- GitHub Actions are used to automatically build and run the tests on push/pull requests to the
main
branch. - The workflow (
.github/workflows/playwright.yml
) performs:- Code checkout
- .NET setup
- Playwright browser installation
- Dependency restoration
- Project build
- Test execution (using configured
.runsettings
)
- You can view the status and logs of the CI runs in the Actions tab.
- .NET / C#
- Playwright .NET: Core browser automation library.
- NUnit: Test framework and runner.
- Serilog: Structured logging.
- Deque.AxeCore.Playwright: Accessibility testing engine.
- Codeuctivity.ImageSharpCompare: Visual comparison library.
- RazorLight: HTML templating engine for the reporting project.
Automation/
: Contains the core test framework.Reporting/
: A separate console application to parse test results and generate the HTML report.
-
Clone the repository:
git clone https://github.com/petrjancar/PlaywrightDemo.git cd PlaywrightDemo
-
Build the
Automation
project after cloning so theplaywright.ps1
is available inside thebin
directory:dotnet build
-
Install required browsers:
pwsh Automation/bin/Debug/net8.0/playwright.ps1 install
The tests target the public "Evil Tester" Simple Todo List as the application under test. It serves as a practical example and learning resource.
-
Run tests using
dotnet test
: Specify a.runsettings
file for configuration (examples provided inAutomation/Configuration/RunSettings/
).# Example using Chromium, non-headless dotnet test --settings Automation/Configuration/RunSettings/demo-chromium.runsettings
Note: Adjust paths in
.runsettings
(likeLogFileName
andResultsDirectory
) if needed for your environment.
-
After the test run completes, generate the HTML report using the
Reporting
project. Pass the path to the test result XML file (e.g.,test.xml
specified in therunsettings
).# Assuming default ResultsDirectory C:\TestResults from demo-chromium.runsettings dotnet run --project Reporting/Reporting.csproj -- "C:\TestResults\test.xml"
-
Open the generated
report.html
(located in the same directory as the.xml
file, e.g.,C:\TestResults
) in your browser.
This project is licensed under the MIT License - see the LICENSE file for details.
Application Under Test: Evil Tester Simple Todo List by Alan Richardson.