Skip to content

Hex1bTerminalAutomator

Namespace: Hex1b.Automation

Assembly: Hex1b.dll

Provides an imperative, async API for automating terminal interactions in tests. Each method executes immediately and records its result in a step history, providing rich diagnostic context when failures occur.

csharp
public sealed class Hex1bTerminalAutomator

Inheritance

ObjectHex1bTerminalAutomator

Constructors

Hex1bTerminalAutomator(Hex1bTerminal, Hex1bTerminalInputSequenceOptions, TimeSpan)

Creates a new automator for the specified terminal with custom options.

Parameters:

  • terminal (Hex1bTerminal): The terminal to automate.
  • options (Hex1bTerminalInputSequenceOptions): Options for controlling poll intervals, typing speed, and time provider.
  • defaultTimeout (TimeSpan): Default timeout for WaitUntil*Async methods when no explicit timeout is provided.
csharp
public Hex1bTerminalAutomator(Hex1bTerminal terminal, Hex1bTerminalInputSequenceOptions options, TimeSpan defaultTimeout)

Hex1bTerminalAutomator(Hex1bTerminal, TimeSpan)

Creates a new automator for the specified terminal.

Parameters:

  • terminal (Hex1bTerminal): The terminal to automate.
  • defaultTimeout (TimeSpan): Default timeout for WaitUntil*Async methods when no explicit timeout is provided.
csharp
public Hex1bTerminalAutomator(Hex1bTerminal terminal, TimeSpan defaultTimeout)

Properties

CompletedSteps

Gets the list of all steps that have completed successfully.

Returns: IReadOnlyList<AutomationStepRecord>

csharp
public IReadOnlyList<AutomationStepRecord> CompletedSteps { get; }

Methods

Alt()

Adds Alt modifier to the next key or mouse action.

Returns: Hex1bTerminalAutomator

csharp
public Hex1bTerminalAutomator Alt()

BackspaceAsync(CancellationToken, string?, int)

Sends Backspace key.

Parameters:

Returns: Task

csharp
public Task BackspaceAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

ClickAtAsync(int, int, MouseButton, CancellationToken, string?, int)

Performs a click at the specified position.

Parameters:

Returns: Task

csharp
public Task ClickAtAsync(int x, int y, MouseButton button = MouseButton.Left, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

CreateSnapshot()

Creates a snapshot of the current terminal state.

Returns: Hex1bTerminalSnapshot

csharp
public Hex1bTerminalSnapshot CreateSnapshot()

Ctrl()

Adds Ctrl modifier to the next key or mouse action.

Returns: Hex1bTerminalAutomator

csharp
public Hex1bTerminalAutomator Ctrl()

DeleteAsync(CancellationToken, string?, int)

Sends Delete key.

Parameters:

Returns: Task

csharp
public Task DeleteAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

DoubleClickAtAsync(int, int, MouseButton, CancellationToken, string?, int)

Performs a double-click at the specified position.

Parameters:

Returns: Task

csharp
public Task DoubleClickAtAsync(int x, int y, MouseButton button = MouseButton.Left, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

DownAsync(CancellationToken, string?, int)

Sends Down arrow key.

Parameters:

Returns: Task

csharp
public Task DownAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

DragAsync(int, int, int, int, MouseButton, CancellationToken, string?, int)

Performs a drag from one position to another.

Parameters:

Returns: Task

csharp
public Task DragAsync(int fromX, int fromY, int toX, int toY, MouseButton button = MouseButton.Left, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

EndAsync(CancellationToken, string?, int)

Sends End key.

Parameters:

Returns: Task

csharp
public Task EndAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

EnterAsync(CancellationToken, string?, int)

Sends Enter key.

Parameters:

Returns: Task

csharp
public Task EnterAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

EscapeAsync(CancellationToken, string?, int)

Sends Escape key.

Parameters:

Returns: Task

csharp
public Task EscapeAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

HomeAsync(CancellationToken, string?, int)

Sends Home key.

Parameters:

Returns: Task

csharp
public Task HomeAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

KeyAsync(Hex1bKey, CancellationToken, string?, int)

Sends a key press event.

Parameters:

Returns: Task

csharp
public Task KeyAsync(Hex1bKey key, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

KeyAsync(Hex1bKey, Hex1bModifiers, CancellationToken, string?, int)

Sends a key press event with explicit modifiers.

Parameters:

Returns: Task

csharp
public Task KeyAsync(Hex1bKey key, Hex1bModifiers modifiers, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

LeftAsync(CancellationToken, string?, int)

Sends Left arrow key.

Parameters:

Returns: Task

csharp
public Task LeftAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

MouseMoveToAsync(int, int, CancellationToken, string?, int)

Moves the mouse to an absolute position.

Parameters:

Returns: Task

csharp
public Task MouseMoveToAsync(int x, int y, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

PageDownAsync(CancellationToken, string?, int)

Sends Page Down key.

Parameters:

Returns: Task

csharp
public Task PageDownAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

PageUpAsync(CancellationToken, string?, int)

Sends Page Up key.

Parameters:

Returns: Task

csharp
public Task PageUpAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

RightAsync(CancellationToken, string?, int)

Sends Right arrow key.

Parameters:

Returns: Task

csharp
public Task RightAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

ScrollDownAsync(int, CancellationToken, string?, int)

Scrolls down at the current mouse position.

Parameters:

Returns: Task

csharp
public Task ScrollDownAsync(int ticks = 1, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

ScrollUpAsync(int, CancellationToken, string?, int)

Scrolls up at the current mouse position.

Parameters:

Returns: Task

csharp
public Task ScrollUpAsync(int ticks = 1, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

SequenceAsync(Action<Hex1bTerminalInputSequenceBuilder>, string?, CancellationToken, string?, int)

Builds and runs an input sequence inline. The sequence is tracked as a single step in the automator's history.

Parameters:

Returns: Task

csharp
public Task SequenceAsync(Action<Hex1bTerminalInputSequenceBuilder> configure, string? description = null, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

SequenceAsync(Hex1bTerminalInputSequence, string?, CancellationToken, string?, int)

Runs a pre-built input sequence. The sequence is tracked as a single step in the automator's history.

Parameters:

  • sequence (Hex1bTerminalInputSequence): The pre-built sequence to run.
  • description (String): Description for error messages and step history.
  • ct (CancellationToken): Cancellation token.
  • callerFilePath (String): Auto-captured caller file path. Do not pass explicitly.
  • callerLineNumber (Int32): Auto-captured caller line number. Do not pass explicitly.

Returns: Task

csharp
public Task SequenceAsync(Hex1bTerminalInputSequence sequence, string? description = null, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

Shift()

Adds Shift modifier to the next key or mouse action.

Returns: Hex1bTerminalAutomator

csharp
public Hex1bTerminalAutomator Shift()

SlowTypeAsync(string, TimeSpan?, CancellationToken, string?, int)

Types text slowly with a delay between keystrokes.

Parameters:

Returns: Task

csharp
public Task SlowTypeAsync(string text, TimeSpan? delay = null, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

SpaceAsync(CancellationToken, string?, int)

Sends Space key.

Parameters:

Returns: Task

csharp
public Task SpaceAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

TabAsync(CancellationToken, string?, int)

Sends Tab key.

Parameters:

Returns: Task

csharp
public Task TabAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

TypeAsync(string, CancellationToken, string?, int)

Types text quickly (no delay between keystrokes).

Parameters:

Returns: Task

csharp
public Task TypeAsync(string text, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

UpAsync(CancellationToken, string?, int)

Sends Up arrow key.

Parameters:

Returns: Task

csharp
public Task UpAsync(CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

WaitAsync(int, CancellationToken, string?, int)

Pauses for the specified number of milliseconds.

Parameters:

Returns: Task

csharp
public Task WaitAsync(int milliseconds, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

WaitAsync(TimeSpan, CancellationToken, string?, int)

Pauses for the specified duration.

Parameters:

Returns: Task

csharp
public Task WaitAsync(TimeSpan duration, CancellationToken ct = default, string? callerFilePath = null, int callerLineNumber = 0)

WaitUntilAlternateScreenAsync(TimeSpan?, string?, int)

Waits until the terminal enters alternate screen mode.

Parameters:

  • timeout (Nullable<TimeSpan>): Maximum time to wait. If null, uses the default timeout.
  • callerFilePath (String): Auto-captured caller file path. Do not pass explicitly.
  • callerLineNumber (Int32): Auto-captured caller line number. Do not pass explicitly.

Returns: Task

csharp
public Task WaitUntilAlternateScreenAsync(TimeSpan? timeout = null, string? callerFilePath = null, int callerLineNumber = 0)

WaitUntilAsync(Func<Hex1bTerminalSnapshot, bool>, TimeSpan?, string?, string?, string?, int)

Waits until a condition is met on the terminal.

Parameters:

  • predicate (Func<Hex1bTerminalSnapshot, Boolean>): The condition to wait for. Receives a snapshot of the terminal state.
  • timeout (Nullable<TimeSpan>): Maximum time to wait. If null, uses the default timeout.
  • description (String): Description for error messages. If not provided, the predicate expression is used.
  • predicateExpression (String): Auto-captured predicate source text. Do not pass explicitly.
  • callerFilePath (String): Auto-captured caller file path. Do not pass explicitly.
  • callerLineNumber (Int32): Auto-captured caller line number. Do not pass explicitly.

Returns: Task

csharp
public Task WaitUntilAsync(Func<Hex1bTerminalSnapshot, bool> predicate, TimeSpan? timeout = null, string? description = null, string? predicateExpression = null, string? callerFilePath = null, int callerLineNumber = 0)

WaitUntilNoTextAsync(string, TimeSpan?, string?, int)

Waits until the terminal no longer contains the specified text.

Parameters:

  • text (String): The text to wait to disappear.
  • timeout (Nullable<TimeSpan>): Maximum time to wait. If null, uses the default timeout.
  • callerFilePath (String): Auto-captured caller file path. Do not pass explicitly.
  • callerLineNumber (Int32): Auto-captured caller line number. Do not pass explicitly.

Returns: Task

csharp
public Task WaitUntilNoTextAsync(string text, TimeSpan? timeout = null, string? callerFilePath = null, int callerLineNumber = 0)

WaitUntilTextAsync(string, TimeSpan?, string?, int)

Waits until the terminal contains the specified text.

Parameters:

  • text (String): The text to wait for.
  • timeout (Nullable<TimeSpan>): Maximum time to wait. If null, uses the default timeout.
  • callerFilePath (String): Auto-captured caller file path. Do not pass explicitly.
  • callerLineNumber (Int32): Auto-captured caller line number. Do not pass explicitly.

Returns: Task

csharp
public Task WaitUntilTextAsync(string text, TimeSpan? timeout = null, string? callerFilePath = null, int callerLineNumber = 0)

Remarks

The automator layers on top of — each method builds its own input sequence under the covers and runs it via . The flow is always: automator method → sequencer → steps.

When a step fails (e.g., a times out), the automator wraps the exception in which includes the full step history, terminal snapshot, and source location for debugging.

Examples

csharp
var auto = new Hex1bTerminalAutomator(terminal, defaultTimeout: TimeSpan.FromSeconds(5));
await auto.WaitUntilTextAsync("File");
await auto.EnterAsync();
await auto.WaitUntilTextAsync("New");
await auto.DownAsync();
await auto.WaitUntilAsync(s => IsSelected(s, "Open"), description: "Open to be selected");
await auto.EnterAsync();

Released under the MIT License.