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
15 changes: 15 additions & 0 deletions docs-site/src/content/docs/api/E2E.Engine/EngineInitInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ The run's environment with what prepare left in it.

**Value:** [IReadOnlyDictionary<string, string>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary-2)

<a id="E2E_Engine_EngineInitInfo_Headed_"></a>
<a id="E2E_Engine_EngineInitInfo_Headed"></a>

### Headed


```csharp
public bool Headed { get; init; }
```


Whether the run asked for a visible surface (`--headed`). Upstream's `headed`.

**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

<a id="E2E_Engine_EngineInitInfo_Log_"></a>
<a id="E2E_Engine_EngineInitInfo_Log"></a>

Expand Down
15 changes: 15 additions & 0 deletions docs-site/src/content/docs/api/E2E.Engine/EnginePrepareInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ environment.

**Value:** [IReadOnlyDictionary&lt;string, string&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary-2)

<a id="E2E_Engine_EnginePrepareInfo_Headed_"></a>
<a id="E2E_Engine_EnginePrepareInfo_Headed"></a>

### Headed


```csharp
public bool Headed { get; init; }
```


Whether the run would show the surface (`--headed`). Upstream's `headed`.

**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

<a id="E2E_Engine_EnginePrepareInfo_Log_"></a>
<a id="E2E_Engine_EnginePrepareInfo_Log"></a>

Expand Down
15 changes: 15 additions & 0 deletions docs-site/src/content/docs/api/E2E.Engine/EngineStartOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ fails the attempt for it.

**Value:** [Action&lt;IReadOnlyDictionary&lt;string, string&gt;&gt;](https://learn.microsoft.com/dotnet/api/system.action-1)

<a id="E2E_Engine_EngineStartOptions_Headed_"></a>
<a id="E2E_Engine_EngineStartOptions_Headed"></a>

### Headed


```csharp
public bool Headed { get; init; }
```


Whether the run asked for a visible surface (`--headed`). .NET-only place: upstream hands it to `init` ([Headed](/api/E2E.Engine/EngineInitInfo/#E2E_Engine_EngineInitInfo_Headed)), which the port does not call per worker, so a session start carries it.

**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

<a id="E2E_Engine_EngineStartOptions_LaunchArguments_"></a>
<a id="E2E_Engine_EngineStartOptions_LaunchArguments"></a>

Expand Down
15 changes: 15 additions & 0 deletions docs-site/src/content/docs/api/E2E/LaunchOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ The environment the engine reads; default the process environment.

**Value:** [IReadOnlyDictionary&lt;string, string&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary-2)

<a id="E2E_LaunchOptions_Headed_"></a>
<a id="E2E_LaunchOptions_Headed"></a>

### Headed


```csharp
public bool Headed { get; init; }
```


Shows the browser window; default false. Devices ignore it. Upstream's `headed`.

**Value:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

<a id="E2E_LaunchOptions_OnNotice_"></a>
<a id="E2E_LaunchOptions_OnNotice"></a>

Expand Down
4 changes: 3 additions & 1 deletion docs-site/src/content/docs/docs/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ foreach (var sku in new[] { "A-1001", "B-2040" })
| Timeouts | An action, a wait, or a read gets 30 seconds. `App.OpenAsync()` and `App.RestartAsync()` get 120 seconds. `LaunchOptions.Timeout` or `session.SetDefaultTimeout(timeout)` sets one value for all of them, for the operations that start from then on. There is no session deadline. |
| Cancellation | The token passed to `LaunchAsync` and `NewSessionAsync` stops what is running. |
| App links | On a device, `LaunchApp.LinkBase` (an absolute URL or a scheme such as `shopapp://`, with no query or fragment) makes `session.App.OpenAsync("/orders/42")` open `shopapp://orders/42` in the pinned app. An absolute link opens as given; a `file:`, `data:`, `javascript:`, `view-source:`, `blob:`, or `filesystem:` link is `POLICY_DENIED`. An engine with no link hook, such as `WebEngine`, refuses a link base with `INVALID_CONFIG`. |
| Window | `LaunchOptions.Headed` shows the browser window; the default is hidden. A device ignores it. |
| Files | Screenshots and downloads go to a temp directory that is deleted when the host closes. Set `ArtifactsDir` to keep them; a relative path resolves from `Cwd`. |
| Closing | `CloseAsync` is idempotent and throws an `AggregateException` of the failures closing found. |

<Aside type="note">
Not ported yet: closing the host on SIGINT, SIGTERM, and SIGHUP, and `createAgent`. A web engine shows its window through its own options, not a `Headed` launch option. Issues [#1676](https://github.com/hardkoded/e2e-dotnet/issues/1676), [#1677](https://github.com/hardkoded/e2e-dotnet/issues/1677), and [#1678](https://github.com/hardkoded/e2e-dotnet/issues/1678) track them.
Not ported yet: closing the host on SIGINT, SIGTERM, and SIGHUP, and `createAgent`. Issues [#1676](https://github.com/hardkoded/e2e-dotnet/issues/1676) and [#1677](https://github.com/hardkoded/e2e-dotnet/issues/1677) track them.
</Aside>

## Keep a signed-in state
Expand Down Expand Up @@ -86,6 +87,7 @@ Every failure is an `E2EException` with a `Code`. A step that fails in a session
| Code | When |
| --- | --- |
| `LOCATOR_NOT_FOUND` | Nothing matched before the timeout. |
| `CANCELLED` | A token aborted the operation, or the session is closed: an action, a read, or an app call on a closed session fails with the message `the session is closed`. |
| `WORKER_PROTOCOL` | A second session on a host, a second host on one engine instance, or a closed host. |
| `SESSION_MISMATCH` | A state restored on another engine, platform, or app. |
| `SESSION_INVALID` | A state document that is not `session-state-1`, or that failed authentication. |
Expand Down
2 changes: 2 additions & 0 deletions docs-site/src/content/docs/reference/engine.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ public async Task<IReadOnlyList<VideoSegment>> StopVideoAsync(CancellationToken

### Contributed fixtures

A fixture name may not shadow a universal fixture (`agent`, `app`, `screen`, `platform`, `session`), nor take the name of a method of every core session (`close`, `saveState`, `setDefaultTimeout`): `EngineManifest.DefineEngine` refuses either with `INVALID_CONFIG`.

Upstream lets an engine contribute named surfaces to the test fixtures through `fixtures`, built by `EngineFixtureFactory` functions given an `EngineFixtureContext` and recorded through `context.fixture(name, surface, operations)`. The port's seam is smaller:

- A session that implements `IEngineFixtureHost` receives its `EngineFixtureContext` through `CreateFixtures(context)` once per attempt, after it starts.
Expand Down
2 changes: 1 addition & 1 deletion docs-site/src/content/docs/reference/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The codes an agent step may end with, from upstream's `AGENT_CODE_TABLE`. `block
| `APP_ALREADY_RUNNING` | The ready URL answered before the target's app command was spawned | infrastructure | 3 |
| `BROWSER_INSTALL_FAILED` | Browser provisioning failed: the first-launch Playwright install exited non-zero. The message names the exit code | infrastructure | 3 |
| `MODEL_PROVIDER_FAILED` | Provider transport failure (network error, 5xx, rate limit, or no response within 120 s) after the adapter's transport retries | infrastructure | 3 |
| `CANCELLED` | The runner cancelled the operation without a process signal | infrastructure | 3 |
| `CANCELLED` | The runner cancelled the operation without a process signal. In a core `Host`, an operation a token aborted, or one on a closed session | infrastructure | 3 |
| `MODEL_OUTPUT_INVALID` | Structured output still failed validation after the repair budget was spent | test | 1 |
| `APP_NOT_OPEN` | An operation needed an open app: `App.OpenAsync()` had not run, or the engine reported invalid state | test | 1 |
| `LOCATOR_NOT_FOUND` | No matching node within the deadline, or an agent action refers to a node that is no longer available | test | 1 |
Expand Down
2 changes: 1 addition & 1 deletion skills/e2e-dotnet/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trip. The installed tool prints the same text with `e2e guide <topic>`
| Running tests: `dotnet test` filters, the `e2e` tool (`e2e doctor` checks that `e2e explore` and `e2e mcp` can start; `--json` prints the `doctor-1` report for a host, `--check-model` calls each model once; `e2e cache ls|stats|clear` lists, sizes, or empties the replay cache), `report.json` for scripts, exit codes, CI, test filters (NUnit, xUnit v3, and TUnit, mobile and Windows adapters included: `E2ERunFixture.Filters` and `ChangedSince`, or `E2E_CHANGED_SINCE`; `run.changes`, `run.filters`, and `filtered` skips in `report.json`), `--last-failed` reruns (`E2ERunFixture.LastFailed` or `E2E_LAST_FAILED=1`; `run.carried` in `report.json`, `FinishedRun.LastRun` for reporters, folded into the GitHub comment) | `running` | [references/running.md](references/running.md) |
| Handling a failed run: the trace page, `report.json` for scripts, `E2ESession.Report()` for a session you run yourself, error codes and their fixes, a visible browser, replay misses, phase timings, the agent step table, every model call | `debugging` | [references/debugging.md](references/debugging.md) |
| Exploring an app toward a goal without a test file, with `e2e explore` or `Explore.ExploreAsync` | `explore` | [references/explore.md](references/explore.md) |
| Driving an app from plain code with no test framework (`Launch.LaunchAsync(engine, new LaunchOptions { App, Secrets, Timeout, ArtifactsDir, Cwd })`, `Host.NewSessionAsync`, `Host.Secret`, `Session.SaveStateAsync`, and `SessionState.ExportAsync`/`ImportAsync` with a 32-byte key you keep), or running isolated per-test sessions from your own runner: `E2EHost.OpenAsync`, `OpenHostOptions` (config value or file, target, `EngineFactory`), `host.OpenSessionAsync`, `E2ESession.CloseAsync` and the failures it returns, `Steps()` | `host` | [references/host.md](references/host.md) |
| Driving an app from plain code with no test framework (`Launch.LaunchAsync(engine, new LaunchOptions { App, Secrets, Headed, Timeout, ArtifactsDir, Cwd })`, `Host.NewSessionAsync`, `Host.Secret`, `Session.SaveStateAsync`, and `SessionState.ExportAsync`/`ImportAsync` with a 32-byte key you keep), or running isolated per-test sessions from your own runner: `E2EHost.OpenAsync`, `OpenHostOptions` (config value or file, target, `EngineFactory`), `host.OpenSessionAsync`, `E2ESession.CloseAsync` and the failures it returns, `Steps()` | `host` | [references/host.md](references/host.md) |
| Testing an iOS or Android app: `MobileEngine`, the `Device` fixture, picking a simulator (without `MobileOptions.Device`, `MobileEngine` skips booted devices another agent-device session holds, and `prepare` fails with `ENGINE_FAILURE` when every booted one is held, and with none booted agent-device boots a shut-down one: on iOS an iPhone over an iPad over an Apple TV, on Android a phone or tablet over a TV, then newest OS, then name order, and a reachable paired iPhone or iPad counts as booted; `prepare` logs a per-device timing line), video of the device screen, `Device.SetPermissionAsync` (the enums, or wire-name strings such as `"camera"` and `"grant"`; an unknown name or state is `INVALID_ARGUMENT` before any device command), `Device.UnstableRaw` (the test's agent-device session: name, device id and name, selection, and a raw `IDeviceClient` whose calls are not steps, replayed, or redacted, and that throws `NotSupportedException` for the `text-size` and `animations` settings, `apps.uninstall`, and `command.hardwareButton`; unstable; `INVALID_STATE` after the session is disposed; a custom agent tool gets the running attempt's from `MobileTools.UnstableDeviceSession(engines)`), a NativeScript `testID` or `accessibilityIdentifier` as the test id `GetByTestId` reads (an Android `accessibilityLabel` is put before the text), Limrun and BrowserStack hosted devices, a MAUI app through the DevFlow agent, known limits, `Locator.PressAsync("Enter")` tapping an unfocused field first, and the agent's `open_app` returning to the app under test when it names no app, a Compose Multiplatform field on iOS (for an empty (no value), editable, non-secure iOS field that reports no placeholder of its own, whose only child is a `StaticText` with no children, and whose label is a non-empty name, then `, `, then that child's text, that text is the field's `Placeholder`, the child is left out, and the name is the label before `, `; a non-empty `ContentDescription` stays the name, and that label is then the `Text`; any other field keeps its label and children), and `FillAsync` and `ClearAsync` refusing a node that is not an editable field with `UNSUPPORTED_CAPABILITY` (an iOS `other` that holds a value or only text is typed into), reading the field again before typing (a field the new capture no longer lists, an incomplete capture, or a changed input purpose or secure, disabled, or hidden state is a retryable `NODE_STALE` before anything is typed), looking at the screen again after the keyboard opens or closes (an unmoved control is acted on at once only when keyboard visibility is unchanged, else it waits out `TransitionMilliseconds`; a test's screen swipe waits out the remaining budget before it scrolls), and a `target_still_moving` refusal with `dispatched: no` being a retryable `NODE_STALE` | `mobile` | [references/mobile.md](references/mobile.md) |
| Testing a Windows desktop app: `WinAppEngine`, `WinAppTest`, the `Window` fixture, the `windows` target in `e2e explore` and `e2e mcp`, the interactive-desktop requirement, known limits | `windows` | [references/windows.md](references/windows.md) |
| Asked to bug bash or hunt for bugs: the bug-bash config, many `e2e explore` runs at once, proving each bug with a repro test | `bug-bash` | [references/bug-bash.md](references/bug-bash.md) |
Expand Down
2 changes: 1 addition & 1 deletion skills/e2e-dotnet/references/host.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ await session.Screen.GetByLabel("Password").FillAsync(shop.Secret("SHOP_PASSWORD

- A second `LaunchAsync` on an engine instance another host owns, and a second open session on a host, fail with `WORKER_PROTOCOL`. Parallel work is more hosts.
- A secret value is at least 6 characters, and is redacted from the errors a session throws and from `Screen.TreeAsync()`. `Host.Secret(name)` with another name is `SECRET_UNAVAILABLE`.
- `LaunchOptions.Timeout` bounds an action, a wait, a read, and `App.OpenAsync()` or `App.RestartAsync()` (30 seconds for the first three and 120 seconds for the last two without it). `session.SetDefaultTimeout(timeout)` moves all of them for the operations that start from then on; a zero or infinite span is `INVALID_ARGUMENT`. There is no session deadline. `ArtifactsDir` keeps screenshots and downloads (a relative path resolves from `Cwd`); without it they go to a temp directory deleted when the host closes.
- `LaunchOptions.Timeout` bounds an action, a wait, a read, and `App.OpenAsync()` or `App.RestartAsync()` (30 seconds for the first three and 120 seconds for the last two without it). `session.SetDefaultTimeout(timeout)` moves all of them for the operations that start from then on; a zero or infinite span is `INVALID_ARGUMENT`. There is no session deadline. `Headed` shows the browser window (a device ignores it). An operation on a closed session fails with `CANCELLED` and the message `the session is closed`. `ArtifactsDir` keeps screenshots and downloads (a relative path resolves from `Cwd`); without it they go to a temp directory deleted when the host closes.
- `await session.SaveStateAsync()` captures cookies and storage in memory. Pass it to `shop.NewSessionAsync(new NewSessionOptions { State = state })`. To keep it between runs, `state.ExportAsync(new SessionStateKeyOptions { Key = key })` with a 32-byte key you keep, and `SessionState.ImportAsync(bytes, options)`. A state restores only on the same engine, platform, and app (`SESSION_MISMATCH`; give two addresses of one app the same `LaunchApp.Identity`), a wrong key or changed byte is `SESSION_INVALID`, and an old one `SESSION_EXPIRED`.
- `LaunchApp.LinkBase` (an absolute URL or a scheme such as `shopapp://`, with no query or fragment) makes `session.App.OpenAsync("/orders/42")` open `shopapp://orders/42` in the pinned app of a device engine. An absolute link opens as given; `file:`, `data:`, `javascript:`, `view-source:`, `blob:`, and `filesystem:` are `POLICY_DENIED`; an engine without a link hook, or a bad value, is `INVALID_CONFIG` at launch.
- Not ported yet: closing on signals and `createAgent` (issues 1676 to 1678).
18 changes: 13 additions & 5 deletions src/E2E/Core/Launch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public sealed record LaunchOptions
/// </summary>
public IReadOnlyDictionary<string, string>? Secrets { get; init; }

/// <summary>Shows the browser window; default false. Devices ignore it. Upstream's <c>headed</c>.</summary>
public bool Headed { get; init; }

/// <summary>
/// Default timeout of one operation: an action, a wait, a read, and <c>App.OpenAsync</c> or <c>App.RestartAsync</c>. Without it an action, a wait,
/// or a read gets 30 seconds, and an app open or restart 120 seconds. A session changes it with <see cref="Session.SetDefaultTimeout"/>. An agent
Expand Down Expand Up @@ -113,7 +116,7 @@ internal Session(StandaloneAttempt attempt, StateIdentity identity, Action onClo

/// <summary>Captures the session's state (cookies, storage, app data) in memory. Persist it only with <see cref="SessionState.ExportAsync"/>. Upstream's <c>saveState</c>.</summary>
public Task<SessionState> SaveStateAsync(CancellationToken cancellationToken = default) =>
OpenSession.RedactOpening(async () =>
OpeningRedaction.RedactOpening(async () =>
{
var saved = await _session.CaptureStateAsync(cancellationToken).ConfigureAwait(false);
return SessionState.Captured(_identity, saved.State, saved.Secrets);
Expand Down Expand Up @@ -168,12 +171,14 @@ public sealed class Host : IAsyncDisposable
private readonly StateIdentity _identity;
private readonly TimeSpan? _timeout;
private readonly LaunchApp? _app;
private readonly bool _headed;
private readonly Lock _gate = new();
private readonly Lazy<Task> _closing;
private Session? _open;

internal Host(StandaloneHost host, IEngine engine, string target, string projectRoot, string output, bool ownsArtifacts, IReadOnlyDictionary<string, string> secrets, StateIdentity identity, TimeSpan? timeout, LaunchApp? app)
internal Host(StandaloneHost host, IEngine engine, string target, string projectRoot, string output, bool ownsArtifacts, IReadOnlyDictionary<string, string> secrets, StateIdentity identity, TimeSpan? timeout, LaunchApp? app, bool headed)
{
_headed = headed;
_app = app;
_host = host;
_engine = engine;
Expand Down Expand Up @@ -206,7 +211,7 @@ public Secret Secret(string name)

/// <summary>Opens a session. One at a time: the previous one must be closed.</summary>
public Task<Session> NewSessionAsync(NewSessionOptions? options = null, CancellationToken cancellationToken = default) =>
OpenSession.RedactOpening(async () =>
OpeningRedaction.RedactOpening(async () =>
{
if (_closing.IsValueCreated)
{
Expand Down Expand Up @@ -333,6 +338,8 @@ private async Task CloseOnceAsync()
TestTimeout = System.Threading.Timeout.InfiniteTimeSpan,
ActionTimeout = _timeout ?? E2EDefaults.ActionTimeout,
AssertionTimeout = _timeout ?? E2EDefaults.AssertionTimeout,
Headed = _headed,
Closed = () => new EngineException(EngineErrorCodes.Cancelled, "the session is closed"),
// No report stands between an operation's error and the program, so the error itself is classified and redacted.
RedactThrown = true,
RetainSteps = Launch.RetainedSteps,
Expand Down Expand Up @@ -381,7 +388,7 @@ public static async Task<Host> LaunchAsync(IEngine engine, LaunchOptions? option
Host? host = null;
try
{
return host = await OpenSession.RedactOpening(async () =>
return host = await OpeningRedaction.RedactOpening(async () =>
{
Claim(engine);
try
Expand All @@ -406,9 +413,10 @@ public static async Task<Host> LaunchAsync(IEngine engine, LaunchOptions? option
ProjectRoot = projectRoot,
Env = options.Env,
CancellationToken = cancellationToken,
Headed = options.Headed,
Notice = options.OnNotice is { } notice ? (_, message) => OpenSession.Notify(notice, message) : null,
}).ConfigureAwait(false);
return new Host(worker, engine, target, projectRoot, output, ownsArtifacts, secrets, identity, options.Timeout, app);
return new Host(worker, engine, target, projectRoot, output, ownsArtifacts, secrets, identity, options.Timeout, app, options.Headed);
}
catch
{
Expand Down
Loading
Loading