Invoke-ConsoleHeadless
Runs a script (usually an app) on a headless terminal with scripted input and returns the screens it drew.
Syntax
Invoke-ConsoleHeadless
[-ArgumentList <Object[]>]
[-Height <Int32>]
[-InputScript <String>]
[-ScriptBlock] <ScriptBlock>
[-Width <Int32>]
[<CommonParameters>]#All Parameter SetsDescription
The script runs in this session against a headless terminal of the given size, so apps, prompts, menus and dashboards draw there exactly as in a console window. The input is queued first in the recorder's grammar: key names (Down, Enter, Ctrl+K), quoted text, paste:, resize:WxH, wait:ms and the mouse at zero-based cells (click:x,y, dclick:, rclick:, move:, wheel:x,y,n, drag:x1,y1,x2,y2). Input ends after it, so an app that reads past the last key finishes. The result has the final screen's Text and Cells, every distinct screen in Frames and the script's Output, so a Pester test can assert on what the user would have seen. To watch an app in a browser or drive it from an agent, set CONSOLEMONSTER_HEADLESS and CONSOLEMONSTER_DEBUG_SOCKET before starting it; the browser host itself is a C# API.
Examples
Example 1
$result = Invoke-ConsoleHeadless -Width 56 -Height 10 -InputScript 'Down click:4,5 Escape' {
Show-ConsoleApp -Content {
New-ConsoleSelect -Key Server -Choices WEB01, SQL01, FS01
New-ConsoleBinding -Content { param($State) "Picked $($State.Server)" }
}
}
$result.Text | Should -Match 'Picked FS01'Drive a list with a key and a click, then check the screen.
Example 2
Invoke-ConsoleHeadless -Width 60 -Height 12 -InputScript 'Enter' {
Read-ConsoleSelect -Title 'Server' -Choices web01, web02
}Run a selection against scripted terminal input
Parameters
- -ArgumentList Object[]
- Arguments passed to the script block.
- -Height Int32
- Terminal height in cells (default 30).
- -InputScript String
- The keys, text and mouse actions to send, in the recorder's input grammar.
- -ScriptBlock ScriptBlock
- The script to run, usually one that calls Show-ConsoleApp or a prompt.
- -Width Int32
- Terminal width in cells (default 0: terminal width, falling back to 100).
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.
Outputs
ConsoleMonster.PowerShell.ConsoleHeadlessResult: What a script drew on a headless terminal: the final screen, every distinct screen, and the script's output.