Scope: HTTP/API tests using TestBaseAPI, ApiClient, and ReportResultAPI from STAF.Playwright.Framework.
- Always use the framework
ApiClient(fromTestBaseAPI) for requests—do not spin up ad-hocHttpClientinstances for test code unless the framework truly lacks a capability (then document why). - Validate:
- Status codes — assert expected codes for happy/negative paths.
- Response shape — JSON/XML parsing; for contract-level guarantees prefer
OpenApiContractTestBaseand specs underOpenAPI/. - Business logic — assert domain fields (IDs, state transitions), not only HTTP success.
- Chaining: use values from response N as inputs to request N+1 inside the same test (local variables), or via a small private helper—not static mutable state.
- Base URL:
ConfigManager.GetParameter("ApiBaseUrl")(fromtestsetting.runsettingsorSTAF_ApiBaseUrl). - Paths: lead with
/for absolute paths on the host (e.g.GetAsync("/posts/1")).
- After important calls, use
ReportResultAPI.ReportResultPass(and fail variants as provided by the framework) withTestContext, including status code and concise context—never log secrets or full auth tokens.
- API test methods —
[TestMethod],async Task, inheritTestBaseAPI. - Request builders — if the API is complex, add small builder/helper methods in the test class or a dedicated
Clients//Builders/type in the test project—still delegating transport toApiClient. - Validation logic — parse body with
System.Text.Jsonor project conventions; assert withAssert.*.
- Prefer
[DataRow]/ dynamic data for parameter variations. - For environment-specific payloads, use
testdata.jsonpatterns viaConfigManager(seetest-data.md).
- Hardcoded production URLs.
- Assertions that only check “response is not null” on success paths.
- Shared static last-response caches across tests (breaks parallel isolation).