Degraded state with soft assertions
If you want to monitor your service for non-critical errors or performance degradations you can use the degraded check state. This allows you to signal that parts of a Browser check performed slower than expected, or that it triggered assertions that are of lower criticality.
The degraded state does not affect your check’s success ratio like a failed state does. You can configure alert channels to notifiy you when a check has degraded.
To catch errors that are relevant for a degraded scenario you can use soft assertions. Soft assertions keeps your Playwright test running after it has encountered an error, unlike regular assertions which terminate the test. See the playwright docs for more information on soft assertions.
Playwright-helpers library
To trigger a degraded state, checks use a helper library, @checkly/playwright-helpers
, which is included in runtimes 2023.09
and later.
The helper library contains two methods, markCheckAsDegraded
and getAPIResponseTime
.
Installing and importing
@checkly/playwright-helpers
is also available for use in Browser and Multistep checks.
markCheckAsDegraded
Marks a check as degraded if:
- The check is failing with soft assertions, or
- The check has no failures
If your check is failing due to a timeout or failed non-soft assertion it will be considered failing, even if markCheckAsDegraded
is called.
Usage
Arguments
reason
String (optional). Logged when the method is called. Used to identify which method caused the degradation.
getAPIResponseTime
Gets the request response time.
Usage
Arguments
response
APIResponse (required). A response from a Playwright API request.
Triggering a degraded state
A check is marked as degraded when markCheckAsDegraded
is called and there are no regular assertions triggered.
In this example we do a simple site navigation and measure the time the test takes. At the end of the check we mark the check as degraded if the duration of the test is too long, or if the site header has changed.
Triggering a soft assertion in a check but not calling markCheckAsDegraded
will fail the check at the end instead of marking as degraded.
Last updated on December 13, 2024. You can contribute to this documentation by editing this page on Github