Loading

Best practices for Scout API tests

Best practices specific to Scout API tests.

Tip

For guidance that applies to both UI and API tests, see the general Scout best practices. Scout is built on Playwright, so the official Playwright Best Practices also apply.

Use the right fixture for the right purpose:

Fixture Use for
apiClient The endpoint under test (with scoped credentials from API auth)
apiServices Setup/teardown and side effects
kbnClient, esClient, etc. Lower-level setup when apiServices doesn’t have a suitable helper

Prefer tests that read like “call endpoint X as role Y, assert outcome”.

This pattern validates both endpoint behavior and the permission model.

Scout supports two authentication methods for API tests. Choose based on endpoint type:

Endpoint type Auth method Fixture
Public APIs (api/*) API key requestAuth + apiKeyHeader
Internal APIs (internal/*) Cookie-based session samlAuth + cookieHeader

See API authentication for details and examples.

Status code assertions are necessary but not sufficient. Also validate shape and key fields.