Skip to content
Back to skills

Functional Testing

ASecurity

Mandatory conventions for authoring Playwright + .NET 10 + NUnit + Page-Object-Model UI functional tests for the application. In this project, "functional tests" = UI Playwright tests and they live under tests/functional/. Trigger words include playwright, functional, functional tests, functional testing, ui automation, ui tests, browser tests, automation framework, automation project, test fixture, test suite, page object, pom, test category, test categories, smoke test, scaffold a test proj...

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
ai-agentsgobashsqltestingapidatabasebackend

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 4, 2026

npx -y skills add elhajahmadj/SDLCskill --skill functional-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Functional Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Functional Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/elhajahmadj-functional-testing/badge)](https://www.skillsdirectory.com/skills/elhajahmadj-functional-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: functional-testing
description: Mandatory conventions for authoring Playwright + .NET 10 + NUnit + Page-Object-Model UI functional tests for the application. In this project, "functional tests" = UI Playwright tests and they live under tests/functional/. Trigger words include playwright, functional, functional tests, functional testing, ui automation, ui tests, browser tests, automation framework, automation project, test fixture, test suite, page object, pom, test category, test categories, smoke test, scaffold a test project, new test project, add a test, add a test method, write a playwright test, UI test, NUnit, run the functional tests, run a browser test.
---

# UI Functional Tests — Mandatory Conventions

> **In this project, "functional tests" means UI Playwright tests.** They live at `tests/functional/`
> (relocated there from the old `automation/` folder). This skill is the rulebook enforced on
> **every** change to that suite. It was built from the architecture spec `functional-tests-prompt.md`;
> when one changes, update the other.

This skill encodes **non-negotiable** rules. Treat it as mandatory whenever it applies.

## When this skill applies

Trigger for UI functional automation work only:

- "add a test fixture / test method / test suite"
- "scaffold a test project for a new feature"
- "add a page object for X"
- "add test categories for X"
- "create functional/UI tests for X"
- "run the functional tests" / "run a browser test" — see §16

**Do NOT apply for:** backend unit tests (`backend-unit-tests`, under `tests/back-end unit/`),
API/integration tests, application source code, or infrastructure unrelated to this suite.

**Boundary with end-to-end:** one page, dialog, form, or feature in isolation — **this skill**.
A multi-page workflow in a single browser session (a "user journey") — the e2e journey suite.

## Project layout (follow exactly)

```text
tests/functional/
├── App.Automation.sln
├── appsettings.json                     — SINGLE shared root config (per-role sections)
├── appsettings.Local.json               — SINGLE shared root local override
├── parallel.runsettings
├── scripts/ensure-browser.sh
├── App.Automation.Shared/               — class lib, NO Playwright, written ONCE
├── App.Automation.Infrastructure/       — class lib, owns Playwright lifecycle, written ONCE
└── Roles/                                        — a role = a distinct login/auth context (same web BaseUrl)
        └── App.<Role>.Automation.Tests/          — one project per role/suite (no intermediate folder)
            ├── Constants/  (<Feature>Selectors.cs, UrlEndpoints.cs)
            ├── TestCategories/  (MANDATORY folder, one <Suite>TestCategories.cs per suite)
            ├── PageObjects/  (I<Page>PageActions.cs + <Page>PageActions.cs pairs, TestData.cs)
            └── TestSuites/  (<Suite>Tests.cs)
            (NO appsettings.json here — config lives ONLY in the shared root files)
```

`TestCategories/` is mandatory at creation time even if it starts empty.

Reference chain, one way only:
`App.<Feature>.Automation.Tests → App.Automation.Infrastructure → App.Automation.Shared`
Feature projects never reference each other; `Shared` never references `Infrastructure` or Playwright.

---

## Mandatory rules — enforce on every change

### 1. FluentAssertions pinned to 7.2.0
Never upgrade FluentAssertions to 8.x (license change). `7.2.0` is what `FluentAssertions.Analyzers 0.34.1`
was validated against. Reject any csproj edit that floats or bumps it.

### 2. Pinned NuGet versions (do not float)
`Microsoft.Playwright` **1.58.0** · `NUnit` **4.3.2** · `NUnit3TestAdapter` **5.0.0** ·
`NUnit.Analyzers` **4.7.0** · `FluentAssertions` **7.2.0** · `Bogus` **35.6.1** ·
`Microsoft.NET.Test.Sdk` **17.14.0** · `coverlet.collector` **6.0.4** · TFM `net10.0`.

`Microsoft.Extensions.*` / `Microsoft.EntityFrameworkCore.*` must **match or exceed** what the application's
projects pin (a lower direct pin than the transitive requirement is **NU1605 — an error**). Bump in lockstep.

### 3. Test method naming — `Given_When_Then` + `Async()` (no exceptions)
```
Given<Precondition>_When<Action>_Then<ExpectedOutcome>Async()
```
Exactly three underscore-separated segments, in order; always `async Task` ending `Async()`; PascalCase per
segment; business terms, not Playwright/CSS terms.

**Test-plan ID prefix.** From an external test plan with a case ID, prefix `Tc<id>_` (capital T, lowercase c,
numeric id, one underscore, then the three-segment name). Prefix is the only addition. Keep the ID in the
**method name only** — never in `[Description]` or a comment. Duplicate `Tc<id>_` prefixes are allowed. Tests
not from a plan get no prefix.

### 4. Test categories — one `{Suite}TestCategories.cs` per suite
Every `*Tests.cs` has a paired `<Suite>TestCategories.cs` (plural) under **`TestCategories/`** (not
`Constants/`). One `public const string` per category. Every `[Test]` carries at least one
`[Category(<Suite>TestCategories.<Const>)]`. **Inline `[Category("literal")]` strings are forbidden** —
always reference the constant.

### 5. Page Object Model rules
- Every page is an `I<Page>PageActions` interface + `<Page>PageActions` class pair.
- Locators are `ILocator` **properties** (re-resolve on every access, survive re-render), not methods. Locators
  needing an argument are methods: `ILocator RowById(string id)`.
- Behaviors are `async Task` methods composing locators into **business** actions.
- **Never assert inside a page object** — assertions live in the `[Test]`.
- URLs are composed from `TestConfig.Urls["BaseUrl"]` + `UrlEndpoints` constants — never hardcoded inline.

### 6. Selectors and routes — centralized
Selectors live in `Constants/<Feature>Selectors.cs` or as `ILocator` properties. Routes in
`Constants/UrlEndpoints.cs`. **Never inline in a test.**

**Selector priority (strict — walk top to bottom, use the first that exists on the element):**
1. **`data-testid`** → `Page.GetByTestId(...)`. Required first choice; if you own the source and the element
   lacks one, **add a `data-testid`** rather than dropping down.
2. **`id`** → `Page.Locator("#id")`.
3. **XPath** → `Page.Locator("xpath=...")`.
4. **Text / role+name** → `Page.GetByText(...)` / `GetByRole(...)`.
5. **Anything else** (CSS structural, `nth`, sibling traversal) — true last resort.

CSS-structural and text selectors are the entire population of flaky UI tests.

### 7. Fixture / lifecycle rules
- Every test class inherits `TestFixture` from `App.Automation.Infrastructure`.
- Wire page objects in the `OnTestFixtureSetupAsync` override — **not** your own `[SetUp]`.
- `IBrowserManager` is registered **transient** — each test gets its own browser. Never singleton.
- **Never** dispose the DI container in `[OneTimeTearDown]` — disposal belongs on `AppDomain.ProcessExit`
  (NUnit may reuse the process across fixtures).
- No `HttpClient`, no `Thread.Sleep`, no `WaitForTimeoutAsync` in tests or page objects. Use the
  `LocatorFluentAssertions` helpers (auto-wait then assert) — the only place a wait is allowed.
- Diagnostics via `TestContext.Progress.WriteLine`, never `Console.WriteLine`.

### 8. Configuration — ONE shared root file (no per-project appsettings)
Exactly one `appsettings.json` + one `appsettings.Local.json`, both at `tests/functional/`. **Never** create
per-project `appsettings*.json` — when a test needs config, edit the shared root file. Root files use
per-role sections under `Roles:<Role>` (e.g. `Public` = anonymous, `User`/`Admin` = that role's
credentials); top-level scalars (`Headless`, `PlaywrightTimeout`, `Environment`, …) are shared; `Urls` and
`Auth` (that role's distinct `Username`/`Password`) live under the role's section — all roles share the web `BaseUrl`.

Each project selects its role in its **csproj** (`<AssemblyMetadata Include="TestRole" Value="Public" />`), never
in JSON, and links the shared root files with `<None Include="..\..\appsettings*.json" Link=...>` (Include,
never Update; `..\..\` from `Roles/<Project>/`). Role resolution: `TEST_ROLE` env var → `TestRole`
metadata. Override order (last wins): appsettings.json → appsettings.Local.json → appsettings.<env>.json →
env vars. Read config via the static `TestConfig` — **never** `new ConfigurationBuilder()` in a test. Run each
role's project in its own host process (the `dotnet test` default); `TestConfig` is process-global static, so
the loader **throws** if two roles land in one process. **Secrets are never committed** — credential fields
ship empty; real values come from env vars.

### 9. Browser start-up is opt-in — `FunctionalTest` on every UI test (mandatory)
`TestFixture` launches a browser **only** for tests carrying
`[Category(AutomationTestCategories.FunctionalTest)]`. Any test that drives a UI **must** have it; any test
that does not touch the UI **must not**. A missing category shows up as a null `Page` / actionable throw — the
fix is to **add the category**, never to re-enable an unconditional launch. Exclude UI tests where no browser
exists: `--filter "TestCategory!=FunctionalTest"`; run only them: `-- NUnit.Where="cat==FunctionalTest"`.

### 10. Database verification — EF Core via the shared project (category-gated) — *future*
The optional DB-verification capability (shared data-access project referencing the app's EF Core
`*.Infrastructure`, `GetDatabaseService<TContext>()` gated by `[Category(DbContextNames.<Ctx>)]`, EF Core only,
never `EnsureCreated`/`Migrate`) is **not yet built** in the project's `tests/functional`. When added: EF Core only
(no raw SQL), category-gated, lazy, auto-disposed in `TearDown`.

### 11. Test data factories — `{Service}TestData.cs` (mandatory for inserted data)
Any test that inserts data builds entities from a shared per-service factory — never inline `new Entity{…}`.
Static values as `public const`; dynamic values from the shared thread-local Bogus faker or
`AutomationTestData.UniqueName("<suffix>")` → `"Automation<suffix>_<guid>"`. Every generated row embeds the
`AutomationTestData.Marker` (`"Automation"`) in a searchable column so cleanup can find it.

### 12. Automation data cleanup — automatic after each suite — *pairs with §10/§11*
When DB verification exists, `TestFixture` sweeps every `DbContext` its tests touched in `[OneTimeTearDown]`,
deleting rows whose `CreatedBy` **contains** `"Automation"` (or `Name` **starts with** it), via EF Core
`ExecuteDeleteAsync` only, gated by `AutomationDatabase:CleanupAfterRun`, best-effort, never failing a green run.
Never put the word `Automation` into rows you want to keep.

### 13. Email verification — shared mailbox (category-gated, serialized) — *future*
The optional email capability (`[Category(AutomationTestCategories.EmailServiceRqrd)]`; self-skips when
unconfigured, purges the inbox before the body, serializes via `[NonParallelizable]`; assert on an
`EmailMessage` DTO; isolate via a unique recipient alias + `ReceivedAfter` stamped before the action) is **not
yet built**. Wire it the same way when added.

### 14. Framework unit-test coverage — keep in sync (when a unit-test project exists)
When a change touches framework code under `App.Automation.{Infrastructure,Shared}` (config/role resolution,
`TestConfig`, guards, helpers, factory methods), add/update the matching hermetic unit test in the same change.
`TestConfig` is process-global static (snapshot/restore + disable parallelization in tests that mutate it), and
Playwright/NUnit-coupled code (browser drivers, `TestFixture`, `BrowserManager`, sign-in past its guards) cannot
be unit-tested — document those gaps rather than skipping.

---

## Recipes

### A — add a test method to an existing suite
1. Open the `*Tests.cs`; confirm its `<Suite>TestCategories.cs` exists (add a `const` first if a new category is needed).
2. Add the method: `[Test]` + `[Category(AutomationTestCategories.FunctionalTest)]` (if it drives the UI) +
   `[Category(<Suite>TestCategories.<Const>)]` + a `Given_When_Then…Async()` name (+ `Tc<id>_` only if from a plan).
3. Drive the page through existing page-object methods (add a locator/behavior to the page object if missing —
   never inline a selector).
4. Assert with `LocatorFluentAssertions` helpers or FluentAssertions `Should()…`.

### B — add a new test suite
1. `TestSuites/<Feature>Tests.cs` with `class <Feature>Tests : TestFixture`.
2. `TestCategories/<Feature>TestCategories.cs` with at least a top-level constant.
3. Override `OnTestFixtureSetupAsync` to instantiate the page objects (create the `I<Page>PageActions` +
   `<Page>PageActions` pair first if needed). Add tests per Recipe A.

### C — scaffold a new per-feature test project
1. `cd tests/functional/Roles && dotnet new nunit -n App.<Role>.Automation.Tests -f net10.0`
2. Replace the csproj with the template: pinned versions (§2), `<AssemblyMetadata Include="TestRole" .../>`, and
   the two linked root-config `<None Include="..\..\..\appsettings*.json" Link=…>` items. **Do NOT** add
   `<None Update>` and **do NOT** create a per-project appsettings.
3. Add references to `App.Automation.Infrastructure` and `App.Automation.Shared`.
4. Config: reuse the role section in the shared root, or add a new `Roles:<Role>` section and point `TestRole` at it.
5. Create `Constants/`, `TestCategories/`, `PageObjects/`, `TestSuites/`.
6. Add ONE smoke test (`GivenHomePage_WhenUserNavigates_ThenHeadingIsVisibleAsync`) + `SmokeTestCategories.cs`
   and prove it green before adding more.
7. Register the project in `App.Automation.sln`.

---

## Pre-merge checklist (run mentally on every functional PR)
- [ ] Every `[Test]` has a `Given_When_Then…Async()` name; test-plan tests carry `Tc<id>_` on the **method name only**.
- [ ] Every `[Test]` has ≥1 `[Category(<Suite>TestCategories.<Const>)]` — no inline strings.
- [ ] Every UI test carries `[Category(AutomationTestCategories.FunctionalTest)]`; non-UI tests do **not**.
- [ ] No assertions in any page object; no raw selectors/URLs in any test method.
- [ ] Selectors follow the §6 ladder: `data-testid` first, then `id` → XPath → text → other.
- [ ] No `Thread.Sleep` / `WaitForTimeoutAsync` / `HttpClient` in tests or page objects.
- [ ] csproj versions match §2 exactly; FluentAssertions stays `7.2.0`.
- [ ] Each new `*Tests.cs` has a paired `*TestCategories.cs` under `TestCategories/`.
- [ ] No per-project `appsettings*.json`; new projects have `<AssemblyMetadata TestRole>` + the two linked root `<None>` items.
- [ ] No credential value committed anywhere.
- [ ] `IBrowserManager` still transient; the DI container is still **not** disposed in `[OneTimeTearDown]`.

---

## §16 Running the tests (including inside a headless agent container)

**Golden rule — know which environment you target.** The suite layers `appsettings.<env>.json` on the base
files; `TEST_ENVIRONMENT=Local` keeps localhost values. The configured `BaseUrl` is used as-is — no runtime
origin rewriting.

**Browser overrides required in a container** (headless Linux, Chromium only) — they win as the last config
layer, and without them the launch hard-fails:
```bash
Headless=true UseChromium=true DefaultBrowser=chromium dotnet test …
```

Steps:
```bash
export XDG_CACHE_HOME="$PWD/.cache"        # persistent Playwright browser cache
bash tests/functional/scripts/ensure-browser.sh          # one-time, idempotent
cd tests/functional
dotnet build Roles/<Project>/<Project>.csproj -tl:off          # build FIRST (cold `dotnet test` times out)
Headless=true UseChromium=true DefaultBrowser=chromium \
  dotnet test Roles/<Project>/<Project>.csproj --no-build --filter "FullyQualifiedName~<Name>" -tl:off
```
Full-suite parallel: `dotnet test App.Automation.sln --no-build --settings parallel.runsettings -tl:off`
(`MaxCpuCount=0` → one host process per project). A runsettings XML comment must not contain a double-dash.

Capture output reliably (the .NET logger swallows inline `echo $?`):
```bash
(dotnet test <proj> --no-build -tl:off > /tmp/ftest.log 2>&1; echo "RC=$?" >> /tmp/ftest.log); tail -40 /tmp/ftest.log
```
Category filters: no browser → `--filter "TestCategory!=FunctionalTest"`; only UI → `-- NUnit.Where="cat==FunctionalTest"`.

**Note:** a green UI run needs the web app reachable at the configured `BaseUrl` **and** Chromium
installed. In an environment without the running app, build-green is the achievable bar; the green run happens
in CI / against a deployed environment.

### Troubleshooting
| Symptom | Cause / fix |
|---|---|
| `Executable doesn't exist` / launch fails | Browser not installed (run `ensure-browser.sh`) or missing the §16 env overrides. |
| Parks on the login route then times out | Login handshake didn't complete — confirm the app is reachable at `BaseUrl`. Environment issue, not a test defect. |
| `Page` is null / `NullReferenceException` in a UI test | Missing `[Category(AutomationTestCategories.FunctionalTest)]` (§9). Add the category. |
| Loader throws demanding `TEST_ROLE` | Two roles' assemblies in one host process (§8). Run per-project or pin `TEST_ROLE`. |

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.