playwright.controller.AppTestValues
playwright.controller.AppTestValues(page)Read a Shiny session's test-mode snapshot of input, output, and export values from a running app.
Requires the app to be running in test mode (construct the app with App(test_mode=True) or set the SHINY_TESTMODE=1 environment variable); otherwise the snapshot endpoint is not served and the methods raise a RuntimeError. The pytest app-launch fixtures (local_app, create_app_fixture) enable test mode by default.
The snapshot URL is discovered from the Shiny client itself (window.Shiny.shinyapp.getTestSnapshotBaseUrl(...)) and fetched over HTTP, so the app must be loaded in the page before these methods are called.
Examples
from shiny.playwright import controller
app_values = controller.AppTestValues(page)
app_values.expect_input("name", "abc")
app_values.expect_output("greeting", "Hello abc")
app_values.expect_export("upper", "ABC")
snapshot = app_values.get() # {"input": {...}, "output": {...}, "export": {...}}
# Expected values may also be predicates (any callable taking the actual
# value); prefer named functions over lambdas for readable failure messages.
def is_integer(value):
return isinstance(value, int)
app_values.expect_input("n", is_integer)See Also
export_test_valuessnapshot_preprocess_inputsnapshot_preprocess
Attributes
| Name | Description |
|---|---|
| page | Playwright Page of the Shiny app. |
Methods
| Name | Description |
|---|---|
| expect_export | Expect the exported value key to equal value (JSON-decoded), retrying until it matches or timeout seconds elapse. |
| expect_exports | Expect the export block to contain values (JSON-decoded), retrying until it matches or timeout seconds elapse. |
| expect_input | Expect the input key to equal value (JSON-decoded), retrying until it matches or timeout seconds elapse. |
| expect_inputs | Expect the input block to contain values (JSON-decoded), retrying until it matches or timeout seconds elapse. |
| expect_output | Expect the output key to equal value (JSON-decoded), retrying until it matches or timeout seconds elapse. |
| expect_outputs | Expect the output block to contain values (JSON-decoded), retrying until it matches or timeout seconds elapse. |
| get | Return the raw test-mode snapshot. |
expect_export
playwright.controller.AppTestValues.expect_export(key, value, *, timeout=None)Expect the exported value key to equal value (JSON-decoded), retrying until it matches or timeout seconds elapse.
value may instead be a predicate; see expect_input for the semantics.
expect_exports
playwright.controller.AppTestValues.expect_exports(
values,
*,
match='subset',
timeout=None,
)Expect the export block to contain values (JSON-decoded), retrying until it matches or timeout seconds elapse.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| values | dict[str, Any] |
A mapping of (namespaced) exported names to their expected values. Any expected value may instead be a predicate (a callable taking the actual value); see expect_input for the semantics. |
required |
| match | Literal[‘subset’, ‘exact’] | "subset" (the default) requires every key in values to be present and equal, ignoring any additional keys in the snapshot. "exact" additionally requires the snapshot’s key set to equal values’ keys. |
'subset' |
| timeout | float | None | Seconds to retry before failing. | None |
expect_input
playwright.controller.AppTestValues.expect_input(key, value, *, timeout=None)Expect the input key to equal value (JSON-decoded), retrying until it matches or timeout seconds elapse.
value may instead be a predicate (a callable taking the actual value): the expectation retries until it returns a truthy value. A predicate may also raise AssertionError itself to provide a richer failure message; any other exception it raises propagates immediately without retrying.
expect_inputs
playwright.controller.AppTestValues.expect_inputs(
values,
*,
match='subset',
timeout=None,
)Expect the input block to contain values (JSON-decoded), retrying until it matches or timeout seconds elapse.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| values | dict[str, Any] |
A mapping of (namespaced) input ids to their expected values. Any expected value may instead be a predicate (a callable taking the actual value); see expect_input for the semantics. |
required |
| match | Literal[‘subset’, ‘exact’] | "subset" (the default) requires every key in values to be present and equal, ignoring any additional keys in the snapshot. "exact" additionally requires the snapshot’s key set to equal values’ keys. |
'subset' |
| timeout | float | None | Seconds to retry before failing. | None |
expect_output
playwright.controller.AppTestValues.expect_output(key, value, *, timeout=None)Expect the output key to equal value (JSON-decoded), retrying until it matches or timeout seconds elapse.
value may instead be a predicate; see expect_input for the semantics.
expect_outputs
playwright.controller.AppTestValues.expect_outputs(
values,
*,
match='subset',
timeout=None,
)Expect the output block to contain values (JSON-decoded), retrying until it matches or timeout seconds elapse.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| values | dict[str, Any] |
A mapping of (namespaced) output ids to their expected values. Any expected value may instead be a predicate (a callable taking the actual value); see expect_input for the semantics. |
required |
| match | Literal[‘subset’, ‘exact’] | "subset" (the default) requires every key in values to be present and equal, ignoring any additional keys in the snapshot. "exact" additionally requires the snapshot’s key set to equal values’ keys. |
'subset' |
| timeout | float | None | Seconds to retry before failing. | None |
get
playwright.controller.AppTestValues.get()Return the raw test-mode snapshot.
Returns
| Name | Type | Description |
|---|---|---|
dict[str, Any] |
A dict with "input", "output", and "export" keys, each mapping (namespaced) ids to their JSON-decoded values. Performs a single fetch (no retry). |