Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions apps/site/docs/en/automate-with-scripts-in-yaml.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ agent:
# Maximum AI replanning cycle limit, optional, defaults to 20 (40 for UI-TARS model)
replanningCycleLimit: <number>

# Background knowledge to send to the AI model when calling aiAct, optional
# Additional AI guidance, optional. default is the shared fallback.
aiContexts:
default: <string>
aiAct: <string>
aiQuery: <string>

# Deprecated compatibility alias for aiContexts.aiAct, optional
aiActContext: <string>
# Legacy alias (aiActionContext) remains for backward compatibility, but avoid using it in new scripts
# The older deprecated alias aiActionContext also remains available for compatibility

# Cache configuration, optional
cache:
Expand All @@ -104,7 +110,8 @@ agent:

- **Applicable environments**: Web, iOS, and Android environments all support `agent` configuration
- **testId priority**: CLI parameter > YAML agent.testId > filename
- **aiActContext**: Provides background knowledge to the AI model, like how to handle popups, business introduction, etc. A legacy alias remains for backward compatibility (see inline comment) but should not be used in new scripts.
- **aiContexts**: Provides additional AI guidance such as business facts, rules, constraints, or output requirements. If `default` is configured, it is used only when neither the current call nor the matching API has its own context. A per-call `context` overrides the API value, which overrides `default`; these values are not automatically merged. Empty strings explicitly clear inherited user context.
- **aiActContext**: Deprecated compatibility field for `aiContexts.aiAct`. `aiContexts.aiAct` wins when both are present. The older `aiActionContext` alias is also deprecated and remains available only for compatibility.
- **Cache configuration**: For detailed usage, refer to the [Caching documentation](./caching.mdx)

:::
Expand All @@ -121,7 +128,9 @@ agent:
autoPrintReportMsg: false
reportFileName: "checkout-report"
replanningCycleLimit: 30
aiActContext: "If any popup appears, click agree. If login page appears, skip it."
aiContexts:
default: "Prices are displayed in USD."
aiAct: "If any popup appears, click agree. If login page appears, skip it."
cache:
id: "checkout-cache"
strategy: "read-write"
Expand Down
20 changes: 17 additions & 3 deletions apps/site/docs/en/basics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,24 @@ await agent.aiAct(
);
```

To give every subsequent `aiAct` call more business context, use [`agent.setAIActContext()`](./reference/#agentsetaiactcontext):
A context is additional guidance for the AI. It can contain business facts, decision or interaction rules, constraints, and output requirements. It supplements the main prompt instead of replacing it.

To share the same guidance across every AI-powered Agent API, set `aiContexts.default` when creating the Agent. `aiContexts.default` is only a fallback: Midscene uses it, if configured, when neither the current call nor the matching API has its own context. API-specific and per-call contexts override it instead of being automatically merged with it.

```typescript
const agent = new PlaywrightAgent(page, {
aiContexts: {
default: 'Prices are shown in USD.',
aiQuery: 'Return monetary values as numbers without currency symbols.',
},
});
```

To change a context after creating the Agent, use [`agent.setAIContext()`](./reference/#agentsetaicontext):

```typescript
agent.setAIActContext(
agent.setAIContext(
'aiAct',
'Close the cookie consent dialog first if it appears. Prices are shown in USD.',
);
```
Expand All @@ -36,7 +50,7 @@ agent.setAIActContext(

- `deepThink`: focuses more on task decomposition and uses separate model calls for planning and element localization. It can make complex tasks more stable, but increases model calls and latency.
- `deepLocate`: uses an additional model call to improve element localization accuracy. Enable it when a target is small or difficult to distinguish from nearby elements.
- `context`: provides business knowledge or other background for this call only. For `aiAct`, it overrides the Agent-level `aiActContext`, including when it is explicitly set to an empty string.
- `context`: provides additional AI guidance for this call only, such as business facts, rules, constraints, or output requirements. It overrides `aiContexts.aiAct`, which overrides the shared fallback in `aiContexts.default`. An explicitly empty string disables inherited user context for this call.

```typescript
await agent.aiAct('Complete the checkout form and stop before placing the order', {
Expand Down
18 changes: 9 additions & 9 deletions apps/site/docs/en/extend-test-runner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ The `ctx` passed to `execute(ctx)` contains these commonly used fields:
- `$`: general Step properties controlled by the runner, such as normalized `timeout` and `continue-on-error` values.
- `signal`: an `AbortSignal` triggered by a timeout or cancellation. Use it in asynchronous requests or long-running tasks to exit early and cleanly.
- `context`: Project-level runtime resources returned by `defineProjectSetup()` and shared within the Project.
- `history`: deeply read-only, JSON-compatible history of executed Nodes. AI Agent Nodes automatically read this field to understand context.
- `onTeardown()`: registers cleanup functions for resources created by the current Node. Cleanup can use attempt or Document scope and runs in LIFO order.
- `scope`: identifies the current Node execution boundary as either `case` or `document`.
- `case` or `document`: detailed runtime information for the current execution position.

Nodes do not receive previous Node results automatically. When later Nodes need a value, store it explicitly in the Project `context` as described below.

## Share state across Nodes

In real-world tests, multiple Nodes often need to share state. For example, an order refund test can create an order and store its ID in `beforeEach`, access the ID from `steps`, and clean up the data in `afterEach`.
Expand Down Expand Up @@ -386,14 +387,14 @@ const playwrightNodes = createPlaywrightNodes<ProjectContext>({
```

`setCookies` does not accept cookie values in YAML. Test Runner persists every
Node input in the run result and workflow history. An inline cookie would be
copied into those records.
Node input in the run result. An inline cookie would be copied into that
record.

Use exactly one of `cookiesEnv`, `profile`, or `storageStatePath` as a cookie
reference. The Node resolves the actual cookies only at execution time and
passes them directly to the Playwright BrowserContext. Its result contains only
the reference name and cookie count. Cookie names, values, and scopes are not
written to the run result or workflow history.
written to the run result.

An environment variable may contain a Cookie header, a JSON cookie array, or
Playwright storage-state JSON. Relative storage-state paths resolve from the
Expand Down Expand Up @@ -463,11 +464,10 @@ steps:
```

`runAdbShell` and `runWdaRequest` preserve their complete response in the Node
result and workflow history. Test Runner limits only the history representation
passed to later Midscene Agent calls: oversized values become bounded previews
with their original character count, and recent entries take priority when the
total context is too large. Use command-side filtering when the complete output
is not needed in the run result.
result, but Test Runner does not automatically pass that response to later
Nodes or Midscene Agent calls. Use command-side filtering when the complete
output is not needed in the run result, or explicitly store only the value a
later Node needs in the Project `context`.

`launch` and `gotoUrl` are intentionally not aliases. `launch` manages an app,
URL, or URI through a device Agent. `gotoUrl` navigates the current Playwright
Expand Down
Loading
Loading