[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M699M4W3GKSVVT9CRR1E3KSW":3,"skill-same:01M699M4W3GKSVVT9CRR1E3KSW":78},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":50,"linkOnly":51,"markdownContent":52,"markdownBody":53,"frontMatter":54,"refName":55,"commitSha":56,"skillDirectory":57,"forksCount":58,"repositoryHtmlUrl":59,"repositoryHomepageUrl":6,"ownerHtmlUrl":60,"ownerBlogUrl":61,"ownerDescription":62,"updatedAt":63,"install":64,"resources":77},"01M699M4W3GKSVVT9CRR1E3KSW","winui-ui-testing",null,"Write and run automated UI tests for Windows desktop apps (WinUI 3, WPF, WinForms, Win32) with the winapp ui harness: one batch script, assertions, input, file pickers, dialogs, screenshots, locally or in Windows Sandbox. Use when asked for UI tests or to verify a feature end to end.","microsoft\u002FwinappCli","microsoft","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6154722?v=4","01M698VYDXZ6JW5WH3CRV650R8","Microsoft","01M699J7Q2FM9V32CFV0Q8VPF9",1381,"MIT","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-ui-testing\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49],"testing","winui ui testing","winui","ui","ui testing","when","for","desktop apps","winforms","input","apps","end","feature","write","batch","harness","win32","run","windows","sandbox","screenshots","2026-11-10 10:12:30",false,"---\nname: winui-ui-testing\ndescription: \"Write and run automated UI tests for Windows desktop apps (WinUI 3, WPF, WinForms, Win32) with the winapp ui harness: one batch script, assertions, input, file pickers, dialogs, screenshots, locally or in Windows Sandbox. Use when asked for UI tests or to verify a feature end to end.\"\n---\n\n### Scope and execution boundary\n\n`winapp ui` uses Windows UI Automation (UIA), so the AutomationId-based workflow works with any Windows desktop framework, packaged or unpackaged. Skip WinUI-specific binding\u002Fdialog advice for other frameworks.\n\nWindows Sandbox keeps synthetic input off the user's desktop; target selection is in Step 1. Discover the installed contract with `winapp run --help`, `winapp target --help`, and `winapp ui \u003Cverb> --help`. Use `--on sandbox`, not `--sandbox` or a top-level `sandbox` command. Do not enable Windows features or launch an app without the task's permission.\n\n- Prerequisites and enablement: see `winui-setup`.\n- Project builds\u002Fpublishes execute on the **host**; deployment, app launch, and `ui --on sandbox` execute in the **guest**. Run the batch script below on the host, not inside `target exec` (which would double-route).\n- Real input and capture require an unlocked host and a connected, nonminimized Sandbox client. Tree inspection may work while input cannot; a readable tree is not an input-readiness check.\n- `winapp target snapshot sandbox --json` is a read-only readiness query: it neither starts nor reconnects a guest. Use it to diagnose readiness rather than probing the user's desktop.\n- The persistent guest is shared, not isolation between mutually untrusted workflows. Coordinate with other users; there is no supported `--unique-identity` option. Use separate machines for mutually untrusted work.\n- Guest `--debug-output` supports **packaged** apps only.\n\n### Approach and command discovery\n\nPrefer a single scripted batch over a long series of interactive calls. If you wrote the app, use its XAML\u002Fsource AutomationIds directly; otherwise inspect its current tree and read source for hidden\u002Flazy flyouts and dialogs. Either way, validate a real window\u002Ftree before passing an accessibility audit.\n\nCore verbs: `list-windows`, `inspect`, `search`, `get-property`, `get-value`, `wait-for`; `invoke`, `click`, `set-value`, `focus`, `scroll-into-view`; `send-keys`, `hover`, `drag`, `touch`, `pen`; `screenshot`, `record`. Use each verb's `--help` for selectors and options, rather than guessing from this short reference.\n\n### Step 1: Select a target, then keep the PID and target together\n\nPrefer `sandbox` when Windows Sandbox is available; otherwise tell the user and choose `local`. **If the user explicitly requested Windows Sandbox and it is unavailable, stop** and point them to the enablement steps in `winui-setup`. A stopped guest does not prove unavailability: `target snapshot` can report no running target while the feature is enabled. App build\u002Ftest failures are not Sandbox unavailability. The same policy applies to diagnostics: unpackaged apps can't use guest `--debug-output`, so diagnose them locally unless Sandbox was explicitly requested.\n\nPass the selected target to the template: it launches with `winapp run . --on sandbox --detach --json` for a guest, or omits `--on sandbox` for local execution. Reuse an already-running app only when its captured target matches the selected target and the guest has not been recreated. Never pass a guest PID to default-host `winapp ui`. If a target becomes unavailable after selection, report it and select again under the same policy; the script itself never retries in another target.\n\nThe run JSON includes **`ProcessId`**, **`ProcessScope`**, and **`UiTargetArgs`** (PascalCase). In Windows Sandbox, `UiTargetArgs` is **`--on sandbox -a \u003CguestPID>`**: preserve both parts, not just the number. For an explicitly requested **unpackaged** guest run, the launch result has no app PID: launch separately, find the intended app by process\u002Ftitle with target-wide `winapp ui list-windows --on sandbox --json`, then pass its PID with `-Target sandbox -AppPid \u003CPID> -AppScope sandbox`. Never use the containment PID. A fresh guest invalidates old PIDs\u002FHWNDs.\n\n### Step 2: Write the host-side batch\n\nCreate `ui-tests.ps1`, replace the sample AutomationIds\u002Fexpected values with the app's requirements, and add the relevant examples below **inside the outer `try`**, before its `finally`. The two small command helpers only route and check CLI calls; they do not implement a target manager. Use them for **every** added command so an earlier native failure cannot be hidden by a later success.\n\n```powershell\n# ui-tests.ps1\nparam(\n    [Parameter(Mandatory)][ValidateSet('sandbox', 'local')][string]$Target,\n    [int]$AppPid = 0,\n    [ValidateSet('sandbox', 'local')][string]$AppScope,\n    [ValidateNotNullOrEmpty()][string]$WorkflowId = [guid]::NewGuid().ToString('N'),\n    [string]$ArtifactDirectory = (Join-Path '.\\ui-test-artifacts' ([guid]::NewGuid().ToString('N')))\n)\n\n$ErrorActionPreference = 'Stop'\n$PSNativeCommandUseErrorActionPreference = $false\n$ScopeArgs = @(if ($Target -eq 'sandbox') { '--on'; 'sandbox' })\n$previousWorkflowId = $env:WINAPP_UI_WORKFLOW_ID\n$env:WINAPP_UI_WORKFLOW_ID = $WorkflowId\n$results = [Collections.Generic.List[object]]::new()\n$screenshots = [Collections.Generic.List[string]]::new()\n$uiStarted = $false\n\nfunction Invoke-WinAppChecked {\n    param([string[]]$Arguments)\n    $global:LASTEXITCODE = $null\n    $output = @(& winapp @Arguments)\n    $code = $global:LASTEXITCODE\n    if ($null -eq $code -or $code -ne 0) {\n        throw \"winapp $($Arguments -join ' ') failed (exit $code). $($output -join \"`n\")\"\n    }\n    $output\n}\n\nfunction Invoke-Ui {\n    param([string[]]$Arguments, [string]$Window)\n    $selector = if ($Window) { @('-w', $Window) } else { @('-a', \"$AppPid\") }\n    Invoke-WinAppChecked (@('ui') + $Arguments + $ScopeArgs + $selector)\n}\n\nfunction Test-UI {\n    param([string]$Name, [scriptblock]$Script)\n    try {\n        & $Script | Out-Null\n        $results.Add(@{ name = $Name; status = 'PASS' })\n    } catch {\n        $results.Add(@{ name = $Name; status = 'FAIL'; detail = \"$_\" })\n    }\n}\n\nfunction Save-Screenshot {\n    param([string]$Name)\n    $path = Join-Path $ArtifactDirectory $Name\n    if (Test-Path -LiteralPath $path) { throw \"Choose a new evidence path: $path\" }\n    Invoke-Ui @('screenshot', '--output', $path) -Window $hwnd | Out-Null\n    if (-not (Test-Path -LiteralPath $path -PathType Leaf) -or (Get-Item -LiteralPath $path).Length -eq 0) {\n        throw \"Screenshot was not delivered to the host: $path\"\n    }\n    $screenshots.Add($path)\n}\n\ntry {\n    $ArtifactDirectory = [IO.Path]::GetFullPath($ArtifactDirectory)\n    New-Item -ItemType Directory -Force -Path $ArtifactDirectory | Out-Null\n    if ($AppPid -lt 0) { throw 'AppPid must be positive, or zero to launch.' }\n    if ($AppPid -gt 0) {\n        if ($AppScope -ne $Target) {\n            throw 'Reusing a PID requires matching -AppScope and -Target from the same live target.'\n        }\n    } else {\n        $launch = Invoke-WinAppChecked (@('run', '.') + $ScopeArgs + @('--detach', '--json')) |\n            ConvertFrom-Json\n        if ($launch.Error -or -not $launch.ProcessId -or [int]$launch.ProcessId -le 0) {\n            throw \"No app ProcessId. For unpackaged guest runs, discover the app in that target and rerun with -AppPid and -AppScope. $($launch.Error)\"\n        }\n        $AppPid = [int]$launch.ProcessId\n        if ($Target -eq 'sandbox' -and\n            ($launch.ProcessScope -ne 'sandbox' -or $launch.UiTargetArgs -ne \"--on sandbox -a $AppPid\")) {\n            throw 'Launch response is missing the expected Sandbox ProcessScope \u002F UiTargetArgs pair.'\n        }\n        if ($Target -eq 'local' -and $launch.ProcessScope -and $launch.ProcessScope -ne 'local') {\n            throw 'Launch response belongs to a different target.'\n        }\n    }\n\n    $uiStarted = $true\n    $windows = @(Invoke-Ui @('list-windows', '--json') | ConvertFrom-Json)\n    $main = $windows | Where-Object { $_.hwnd -and $_.hwnd -ne '0' -and $_.title -ne 'PopupHost' } |\n        Select-Object -First 1\n    if (-not $main) { throw 'No app window found in the selected target; rediscover after a fresh guest.' }\n    $hwnd = [string]$main.hwnd\n\n    Test-UI 'Initial screenshot delivered' { Save-Screenshot '01-initial.png' }\n    Test-UI 'Home exists' { Invoke-Ui @('wait-for', 'NavHome', '-t', '3000') }\n    Test-UI 'Navigate to Settings' {\n        Invoke-Ui @('invoke', 'NavSettings')\n        Invoke-Ui @('wait-for', 'TxtUserName', '-t', '3000')\n    }\n    Test-UI 'Save username' {\n        Invoke-Ui @('set-value', 'TxtUserName', 'TestUser')\n        Invoke-Ui @('invoke', 'BtnSave')\n        Invoke-Ui @('wait-for', 'TxtUserName', '--value', 'TestUser', '-t', '2000')\n    }\n    Test-UI 'Default values' {\n        Invoke-Ui @('wait-for', 'CmbTheme', '--value', 'System default', '-t', '2000')\n        Invoke-Ui @('wait-for', 'TglLogging', '--value', 'Off', '-t', '2000')\n    }\n    Test-UI 'App controls have AutomationIds' {\n        $inspection = Invoke-Ui @('inspect', '--interactive', '--json') -Window $hwnd | ConvertFrom-Json\n        function Get-Elements($nodes) {\n            foreach ($node in $nodes) {\n                if ($null -ne $node) { $node; Get-Elements $node.children }\n            }\n        }\n        $allElements = @(Get-Elements @($inspection.windows | ForEach-Object { $_.elements }))\n        if (-not $allElements.Count) { throw 'Inspection returned no elements; not an accessibility PASS.' }\n        $appElements = @($allElements | Where-Object {\n            $_.type -match 'Button|TextBox|ComboBox|CheckBox|ToggleSwitch|TabItem|Edit' -and\n            $_.name -notmatch 'Minimize|Maximize|Close|System' -and\n            $_.className -notmatch 'PickerHost|#32770|CabinetWClass'\n        })\n        if (-not $appElements.Count) { throw 'No app controls were audited; adjust selectors rather than passing.' }\n        $missingId = @($appElements | Where-Object { -not $_.automationId })\n        if ($missingId.Count) {\n            throw \"Missing AutomationIds: $(($missingId | ForEach-Object { \"$($_.type) '$($_.name)'\" }) -join ', ')\"\n        }\n    }\n    Test-UI 'Final screenshot delivered' { Save-Screenshot '02-settings.png' }\n} catch {\n    $results.Add(@{ name = 'Target setup \u002F test execution'; status = 'FAIL'; detail = \"$_\" })\n} finally {\n    try {\n        if ($uiStarted) { Invoke-WinAppChecked (@('ui', 'yield') + $ScopeArgs) | Out-Null }\n    } catch {\n        $results.Add(@{ name = 'Release UI workflow'; status = 'FAIL'; detail = \"$_\" })\n    } finally {\n        $env:WINAPP_UI_WORKFLOW_ID = $previousWorkflowId\n    }\n}\n\n$failed = @($results | Where-Object { $_.status -eq 'FAIL' }).Count\n$report = [ordered]@{\n    target = $Target; appPid = $AppPid; workflowId = $WorkflowId\n    passed = $results.Count - $failed; failed = $failed\n    results = @($results.ToArray()); screenshots = @($screenshots.ToArray())\n}\n$report | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath '.\\test-results.json' -Encoding utf8\nWrite-Host \"Passed: $($report.passed) | Failed: $failed | Results: .\\test-results.json\"\nif ($failed) { exit 1 }\nexit 0\n```\n\nWithin a test, **throw**, not `exit`; the script fails on CLI errors, empty inspections, and undelivered evidence. Screenshots target the known main HWND so each lands at one exact host path; use `--capture-screen` when popups must be included.\n\n### Step 3: Run, read, and visually verify\n\n```powershell\n# Preferred when Windows Sandbox is available:\n.\\ui-tests.ps1 -Target sandbox\nif ($LASTEXITCODE -ne 0) { throw 'UI batch failed; read test-results.json.' }\n$report = Get-Content -LiteralPath '.\\test-results.json' -Raw | ConvertFrom-Json\n$report.screenshots\n```\n\nFor a captured, still-live guest PID, use `.\\ui-tests.ps1 -Target sandbox -AppPid 1234 -AppScope sandbox`. For a local run (see Step 1), use `.\\ui-tests.ps1 -Target local`, optionally with a local PID and `-AppScope local`. Never reuse a guest PID locally or switch targets to make failing tests pass.\n\nView **each host PNG** listed in `test-results.json` with the image-viewing tool. UIA PASS cannot detect clipping, overlap, incorrect theming, or content bleeding past its container. Fail visual review for unintended scrollbars, unintended ellipses, clipped hero\u002Fright-edge controls, overlapping rows, unbalanced whitespace, cramped\u002Fvast spacing, incorrect Light\u002FDark\u002FHigh Contrast, or missing focus\u002Fhover\u002Ferror states. Capture meaningful states immediately after their interactions, not just at the end.\n\nIf fixes are requested, batch-fix failures, rebuild\u002Frelaunch with the same target using the template (omit `-AppPid` to launch again), and capture the new PID. Maximum **two** fix-and-rerun cycles; then report remaining failures. Do not declare completion without the structured results **and** visual review.\n\n### Assertions and coverage\n\nWrite tests for every requested requirement. Use `wait-for --value` for TextBox\u002FNumberBox values, RichEditBox text, ComboBox selection, toggle\u002Fcheckbox `On`\u002F`Off`, and TextBlock\u002Flabel text. `--contains` matches a substring; `--gone` waits for disappearance. Use `-p IsEnabled --value True` only for a specific property. Invoke buttons\u002Fnav items, wait for page-specific elements, and test default\u002Ferror\u002Fempty states.\n\nThe following examples are additions to the template, not independent shells. `Invoke-Ui` always supplies the chosen scope plus `-a $AppPid`, or scope plus `-w $Window`. For raw reads, pass `--json` and parse it; plain stdout can include advisory messages. Use `scroll-into-view` before asserting a virtualized item below the fold.\n\n```powershell\nTest-UI 'Status and enabled state' {\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'saved', '--contains', '-t', '3000')\n    Invoke-Ui @('wait-for', 'BtnSave', '-p', 'IsEnabled', '--value', 'True', '-t', '3000')\n    $value = Invoke-Ui @('get-value', 'TxtUserName', '--json') | ConvertFrom-Json\n    if ($value.text -ne 'TestUser') { throw 'Wrong username.' }\n}\n```\n\n### File pickers, flyouts, and ContentDialogs\n\nPickers run in a separate `PickerHost` process. Discover their HWND in the **same target**; `-w` changes the window selector, never the target. Replace the filename with a file that exists **in the guest** for Sandbox testing.\n\n```powershell\nTest-UI 'Open file picker' {\n    Invoke-Ui @('invoke', 'BtnOpenFile')\n    Start-Sleep -Seconds 1\n    $allWindows = @(Invoke-WinAppChecked (@('ui', 'list-windows', '--json') + $ScopeArgs) | ConvertFrom-Json)\n    $pickers = @($allWindows | Where-Object { $_.hwnd -and [string]$_.ownerHwnd -eq $hwnd -and $_.title -match 'Open|Save' })\n    if ($pickers.Count -ne 1) { throw 'Expected one picker; inspect the selected target again.' }\n    $pickerHwnd = [string]$pickers[0].hwnd\n    Invoke-Ui @('inspect', '--interactive', '--json') -Window $pickerHwnd\n    Invoke-Ui @('set-value', 'FileNameControlHost', 'test.txt') -Window $pickerHwnd\n    Invoke-Ui @('invoke', 'Open') -Window $pickerHwnd\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'opened', '--contains', '-t', '3000')\n}\n\nTest-UI 'Copy context menu' {\n    Invoke-Ui @('click', 'LstItems', '--right')\n    Invoke-Ui @('wait-for', 'MnuCopy', '-t', '2000')\n    Invoke-Ui @('invoke', 'MnuCopy')\n    Invoke-Ui @('wait-for', 'StatusText', '--value', 'Copied', '-t', '2000')\n}\n\nTest-UI 'Confirm deletion' {\n    Invoke-Ui @('invoke', 'BtnDelete')\n    Invoke-Ui @('wait-for', 'Primary', '-t', '2000')\n    Invoke-Ui @('invoke', 'Primary')\n    Invoke-Ui @('wait-for', 'Primary', '--gone', '-t', '3000')\n}\n```\n\nFor Save\u002FCancel pickers, substitute the appropriate action and assertion. MenuBar headers and flyout items use `invoke` and `wait-for` similarly. ContentDialogs live in the app window; `Primary`, `Secondary`, and `Close` are common selectors, but inspect the actual open dialog because custom AutomationIds are not guaranteed.\n\n### Keyboard, hover, drag, touch, and pen\n\n`send-keys --via send-input` is required for accelerators and reliable per-character input in WinUI\u002FWPF text controls. `post-message` is HWND-targeted but does not produce per-character `KeyDown`. `--target` focuses first; `--verbatim` types literal key names. System shortcuts require the CLI's explicit permission flags; do not use them as a workaround for desktop-readiness errors.\n\n```powershell\nTest-UI 'Keyboard save' {\n    Invoke-Ui @('send-keys', 'hello world', '--target', 'TxtName', '--via', 'send-input')\n    Invoke-Ui @('send-keys', 'ctrl+s', '--via', 'send-input')\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'saved', '--contains', '-t', '2000')\n}\nTest-UI 'Tooltip' {\n    Invoke-Ui @('hover', 'BtnInfo')\n    Invoke-Ui @('wait-for', 'InfoTooltip', '-t', '2000')\n}\nTest-UI 'Reorder items' {\n    Invoke-Ui @('drag', 'ItemA', 'ItemB')\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'reordered', '--contains', '-t', '2000')\n}\nTest-UI 'Touch and ink input' {\n    Invoke-Ui @('touch', 'LstFeed', '-g', 'swipe', '--direction', 'up', '--distance', '400')\n    Invoke-Ui @('pen', 'InkCanvas', '--path', '50,50 120,80 200,60', '--pressure', '0.8')\n    Save-Screenshot '03-ink.png'\n    # Add the app-specific state assertion; successful injection alone is not functional proof.\n}\n```\n\nUse `winapp ui drag --help`, `winapp ui touch --help`, and `winapp ui pen --help` for coordinates, long-press\u002Fdwell, pinch\u002Fstretch, pressure\u002Ftilt\u002Feraser support. Read coordinates in the guest tree; host coordinates are not guest coordinates.\n\n### Recordings and workflow coordination\n\n```powershell\nTest-UI 'Video delivered' {\n    $video = Join-Path $ArtifactDirectory 'flow.mp4'\n    if (Test-Path -LiteralPath $video) { throw 'Choose a new video evidence path.' }\n    Invoke-Ui @('record', '--duration-sec', '6', '--fps', '30', '--output', $video)\n    if (-not (Test-Path -LiteralPath $video -PathType Leaf) -or (Get-Item -LiteralPath $video).Length -eq 0) {\n        throw \"Recording was not delivered to the host: $video\"\n    }\n}\n```\n\nSandbox screenshot\u002Frecord **`--output` paths are host paths**, automatically delivered when capture completes; do not pull them from guessed guest directories. Use fresh output paths and check the exit status and actual host files. `--capture-screen` can include popups outside the app window. For an interrupted recording, preserve `stopReason`, `partialOutput`, `recoveryHint`, and the reported partial\u002Frecovery paths; a nonempty partial file is not necessarily playable.\n\nWinApp CLI arbitrates desktop-changing commands automatically. Without a workflow ID, each command releases its turn immediately; with one, the four-second grace covers tight script bursts, not agent reasoning. Use the **same `WINAPP_UI_WORKFLOW_ID`** for cooperating commands, including concurrent recording and interaction; independent flows need distinct IDs. The template accepts `-WorkflowId` for this purpose, sets it in its own process, restores the previous value, and calls `winapp ui yield --on sandbox` in `finally`. Fresh shell tool calls do not inherit changes from an earlier shell: set the same ID on **every** cooperating invocation. A separate concurrent recording process must also check its exit code\u002Fdelivery, use the same scoped PID, and finish before the test runner yields. Do not start an independent-ID recording that blocks the interactions it is meant to capture. After a pause, inspect again and reopen menus\u002Fdialogs another workflow may have changed.\n\n### Guest persistence and arbitrary file transfer\n\nDo not inspect **host** `$env:LOCALAPPDATA` to prove **guest** persistence. Check the actual app data file in the selected target. Replace the sample package family\u002Fpath with the app's real storage location; unpackaged apps usually use an app-specific LocalAppData directory.\n\n```powershell\nTest-UI 'Username persisted in selected target' {\n    $readSettings = @'\n$ErrorActionPreference = 'Stop'\n$file = Join-Path $env:LOCALAPPDATA 'Packages\\YourPackageFamily\\LocalState\\settings.json'\nif (-not (Test-Path -LiteralPath $file -PathType Leaf)) { throw \"Missing settings: $file\" }\nGet-Content -LiteralPath $file -Raw\n'@\n    $json = if ($Target -eq 'sandbox') {\n        Invoke-WinAppChecked @('target', 'exec', 'sandbox', '--', 'powershell.exe', '-NoProfile', '-NonInteractive', '-Command', $readSettings)\n    } else {\n        & ([scriptblock]::Create($readSettings))\n    }\n    $settings = $json | ConvertFrom-Json\n    if ($settings.UserName -ne 'TestUser') { throw 'Saved username does not match.' }\n}\n```\n\nFor arbitrary setup\u002Fresults files, use `target exec` \u002F `push` \u002F `pull`, not host filesystem guesses. Transfer guest paths are **relative to snapshot `workRoot`**, normally `C:\\WinApp\\work`, not absolute guest paths. The following optional additions assume a host `setup.ps1` that creates `Results` under the guest work root:\n\n```powershell\nTest-UI 'Guest setup and result transfer' {\n    if ($Target -ne 'sandbox') { throw 'This transfer test requires Sandbox.' }\n    $snapshot = Invoke-WinAppChecked @('target', 'snapshot', 'sandbox', '--json') | ConvertFrom-Json\n    if (-not $snapshot.workRoot) { throw 'No live guest workRoot; fix readiness first.' }\n    Invoke-WinAppChecked @('target', 'push', 'sandbox', '.\\setup.ps1', 'Setup\\setup.ps1')\n    $guestSetup = $snapshot.workRoot.TrimEnd('\\') + '\\Setup\\setup.ps1'\n    Invoke-WinAppChecked @('target', 'exec', 'sandbox', '--', 'powershell.exe', '-NoProfile', '-File', $guestSetup)\n    Invoke-WinAppChecked @('target', 'pull', 'sandbox', 'Results', (Join-Path $ArtifactDirectory 'results'))\n}\n```\n\nKeep the guest alive while recovering failed delivery. Preserve evidence\u002Frecovery paths and app data needed for diagnosis before any **user-consented** shutdown; never stop all Sandboxes as routine cleanup.\n\n### Binding and selector gotchas\n\n- `set-value` does not commit default WinUI `x:Bind TwoWay` TextBox bindings until focus changes. Prefer `UpdateSourceTrigger=PropertyChanged` in the app; otherwise `invoke` Save or `focus` another control before checking persistence.\n- RichEditBox\u002FRichTextBox generally need `send-keys --via send-input`, not UIA `set-value`.\n- Use `$AppPid`, never PowerShell's read-only automatic `$Pid`.\n- A picker HWND needs `-w` **and the same target scope**. A fresh guest invalidates both HWNDs and PIDs; do not recycle either.\n","### Scope and execution boundary\n\n`winapp ui` uses Windows UI Automation (UIA), so the AutomationId-based workflow works with any Windows desktop framework, packaged or unpackaged. Skip WinUI-specific binding\u002Fdialog advice for other frameworks.\n\nWindows Sandbox keeps synthetic input off the user's desktop; target selection is in Step 1. Discover the installed contract with `winapp run --help`, `winapp target --help`, and `winapp ui \u003Cverb> --help`. Use `--on sandbox`, not `--sandbox` or a top-level `sandbox` command. Do not enable Windows features or launch an app without the task's permission.\n\n- Prerequisites and enablement: see `winui-setup`.\n- Project builds\u002Fpublishes execute on the **host**; deployment, app launch, and `ui --on sandbox` execute in the **guest**. Run the batch script below on the host, not inside `target exec` (which would double-route).\n- Real input and capture require an unlocked host and a connected, nonminimized Sandbox client. Tree inspection may work while input cannot; a readable tree is not an input-readiness check.\n- `winapp target snapshot sandbox --json` is a read-only readiness query: it neither starts nor reconnects a guest. Use it to diagnose readiness rather than probing the user's desktop.\n- The persistent guest is shared, not isolation between mutually untrusted workflows. Coordinate with other users; there is no supported `--unique-identity` option. Use separate machines for mutually untrusted work.\n- Guest `--debug-output` supports **packaged** apps only.\n\n### Approach and command discovery\n\nPrefer a single scripted batch over a long series of interactive calls. If you wrote the app, use its XAML\u002Fsource AutomationIds directly; otherwise inspect its current tree and read source for hidden\u002Flazy flyouts and dialogs. Either way, validate a real window\u002Ftree before passing an accessibility audit.\n\nCore verbs: `list-windows`, `inspect`, `search`, `get-property`, `get-value`, `wait-for`; `invoke`, `click`, `set-value`, `focus`, `scroll-into-view`; `send-keys`, `hover`, `drag`, `touch`, `pen`; `screenshot`, `record`. Use each verb's `--help` for selectors and options, rather than guessing from this short reference.\n\n### Step 1: Select a target, then keep the PID and target together\n\nPrefer `sandbox` when Windows Sandbox is available; otherwise tell the user and choose `local`. **If the user explicitly requested Windows Sandbox and it is unavailable, stop** and point them to the enablement steps in `winui-setup`. A stopped guest does not prove unavailability: `target snapshot` can report no running target while the feature is enabled. App build\u002Ftest failures are not Sandbox unavailability. The same policy applies to diagnostics: unpackaged apps can't use guest `--debug-output`, so diagnose them locally unless Sandbox was explicitly requested.\n\nPass the selected target to the template: it launches with `winapp run . --on sandbox --detach --json` for a guest, or omits `--on sandbox` for local execution. Reuse an already-running app only when its captured target matches the selected target and the guest has not been recreated. Never pass a guest PID to default-host `winapp ui`. If a target becomes unavailable after selection, report it and select again under the same policy; the script itself never retries in another target.\n\nThe run JSON includes **`ProcessId`**, **`ProcessScope`**, and **`UiTargetArgs`** (PascalCase). In Windows Sandbox, `UiTargetArgs` is **`--on sandbox -a \u003CguestPID>`**: preserve both parts, not just the number. For an explicitly requested **unpackaged** guest run, the launch result has no app PID: launch separately, find the intended app by process\u002Ftitle with target-wide `winapp ui list-windows --on sandbox --json`, then pass its PID with `-Target sandbox -AppPid \u003CPID> -AppScope sandbox`. Never use the containment PID. A fresh guest invalidates old PIDs\u002FHWNDs.\n\n### Step 2: Write the host-side batch\n\nCreate `ui-tests.ps1`, replace the sample AutomationIds\u002Fexpected values with the app's requirements, and add the relevant examples below **inside the outer `try`**, before its `finally`. The two small command helpers only route and check CLI calls; they do not implement a target manager. Use them for **every** added command so an earlier native failure cannot be hidden by a later success.\n\n```powershell\n# ui-tests.ps1\nparam(\n    [Parameter(Mandatory)][ValidateSet('sandbox', 'local')][string]$Target,\n    [int]$AppPid = 0,\n    [ValidateSet('sandbox', 'local')][string]$AppScope,\n    [ValidateNotNullOrEmpty()][string]$WorkflowId = [guid]::NewGuid().ToString('N'),\n    [string]$ArtifactDirectory = (Join-Path '.\\ui-test-artifacts' ([guid]::NewGuid().ToString('N')))\n)\n\n$ErrorActionPreference = 'Stop'\n$PSNativeCommandUseErrorActionPreference = $false\n$ScopeArgs = @(if ($Target -eq 'sandbox') { '--on'; 'sandbox' })\n$previousWorkflowId = $env:WINAPP_UI_WORKFLOW_ID\n$env:WINAPP_UI_WORKFLOW_ID = $WorkflowId\n$results = [Collections.Generic.List[object]]::new()\n$screenshots = [Collections.Generic.List[string]]::new()\n$uiStarted = $false\n\nfunction Invoke-WinAppChecked {\n    param([string[]]$Arguments)\n    $global:LASTEXITCODE = $null\n    $output = @(& winapp @Arguments)\n    $code = $global:LASTEXITCODE\n    if ($null -eq $code -or $code -ne 0) {\n        throw \"winapp $($Arguments -join ' ') failed (exit $code). $($output -join \"`n\")\"\n    }\n    $output\n}\n\nfunction Invoke-Ui {\n    param([string[]]$Arguments, [string]$Window)\n    $selector = if ($Window) { @('-w', $Window) } else { @('-a', \"$AppPid\") }\n    Invoke-WinAppChecked (@('ui') + $Arguments + $ScopeArgs + $selector)\n}\n\nfunction Test-UI {\n    param([string]$Name, [scriptblock]$Script)\n    try {\n        & $Script | Out-Null\n        $results.Add(@{ name = $Name; status = 'PASS' })\n    } catch {\n        $results.Add(@{ name = $Name; status = 'FAIL'; detail = \"$_\" })\n    }\n}\n\nfunction Save-Screenshot {\n    param([string]$Name)\n    $path = Join-Path $ArtifactDirectory $Name\n    if (Test-Path -LiteralPath $path) { throw \"Choose a new evidence path: $path\" }\n    Invoke-Ui @('screenshot', '--output', $path) -Window $hwnd | Out-Null\n    if (-not (Test-Path -LiteralPath $path -PathType Leaf) -or (Get-Item -LiteralPath $path).Length -eq 0) {\n        throw \"Screenshot was not delivered to the host: $path\"\n    }\n    $screenshots.Add($path)\n}\n\ntry {\n    $ArtifactDirectory = [IO.Path]::GetFullPath($ArtifactDirectory)\n    New-Item -ItemType Directory -Force -Path $ArtifactDirectory | Out-Null\n    if ($AppPid -lt 0) { throw 'AppPid must be positive, or zero to launch.' }\n    if ($AppPid -gt 0) {\n        if ($AppScope -ne $Target) {\n            throw 'Reusing a PID requires matching -AppScope and -Target from the same live target.'\n        }\n    } else {\n        $launch = Invoke-WinAppChecked (@('run', '.') + $ScopeArgs + @('--detach', '--json')) |\n            ConvertFrom-Json\n        if ($launch.Error -or -not $launch.ProcessId -or [int]$launch.ProcessId -le 0) {\n            throw \"No app ProcessId. For unpackaged guest runs, discover the app in that target and rerun with -AppPid and -AppScope. $($launch.Error)\"\n        }\n        $AppPid = [int]$launch.ProcessId\n        if ($Target -eq 'sandbox' -and\n            ($launch.ProcessScope -ne 'sandbox' -or $launch.UiTargetArgs -ne \"--on sandbox -a $AppPid\")) {\n            throw 'Launch response is missing the expected Sandbox ProcessScope \u002F UiTargetArgs pair.'\n        }\n        if ($Target -eq 'local' -and $launch.ProcessScope -and $launch.ProcessScope -ne 'local') {\n            throw 'Launch response belongs to a different target.'\n        }\n    }\n\n    $uiStarted = $true\n    $windows = @(Invoke-Ui @('list-windows', '--json') | ConvertFrom-Json)\n    $main = $windows | Where-Object { $_.hwnd -and $_.hwnd -ne '0' -and $_.title -ne 'PopupHost' } |\n        Select-Object -First 1\n    if (-not $main) { throw 'No app window found in the selected target; rediscover after a fresh guest.' }\n    $hwnd = [string]$main.hwnd\n\n    Test-UI 'Initial screenshot delivered' { Save-Screenshot '01-initial.png' }\n    Test-UI 'Home exists' { Invoke-Ui @('wait-for', 'NavHome', '-t', '3000') }\n    Test-UI 'Navigate to Settings' {\n        Invoke-Ui @('invoke', 'NavSettings')\n        Invoke-Ui @('wait-for', 'TxtUserName', '-t', '3000')\n    }\n    Test-UI 'Save username' {\n        Invoke-Ui @('set-value', 'TxtUserName', 'TestUser')\n        Invoke-Ui @('invoke', 'BtnSave')\n        Invoke-Ui @('wait-for', 'TxtUserName', '--value', 'TestUser', '-t', '2000')\n    }\n    Test-UI 'Default values' {\n        Invoke-Ui @('wait-for', 'CmbTheme', '--value', 'System default', '-t', '2000')\n        Invoke-Ui @('wait-for', 'TglLogging', '--value', 'Off', '-t', '2000')\n    }\n    Test-UI 'App controls have AutomationIds' {\n        $inspection = Invoke-Ui @('inspect', '--interactive', '--json') -Window $hwnd | ConvertFrom-Json\n        function Get-Elements($nodes) {\n            foreach ($node in $nodes) {\n                if ($null -ne $node) { $node; Get-Elements $node.children }\n            }\n        }\n        $allElements = @(Get-Elements @($inspection.windows | ForEach-Object { $_.elements }))\n        if (-not $allElements.Count) { throw 'Inspection returned no elements; not an accessibility PASS.' }\n        $appElements = @($allElements | Where-Object {\n            $_.type -match 'Button|TextBox|ComboBox|CheckBox|ToggleSwitch|TabItem|Edit' -and\n            $_.name -notmatch 'Minimize|Maximize|Close|System' -and\n            $_.className -notmatch 'PickerHost|#32770|CabinetWClass'\n        })\n        if (-not $appElements.Count) { throw 'No app controls were audited; adjust selectors rather than passing.' }\n        $missingId = @($appElements | Where-Object { -not $_.automationId })\n        if ($missingId.Count) {\n            throw \"Missing AutomationIds: $(($missingId | ForEach-Object { \"$($_.type) '$($_.name)'\" }) -join ', ')\"\n        }\n    }\n    Test-UI 'Final screenshot delivered' { Save-Screenshot '02-settings.png' }\n} catch {\n    $results.Add(@{ name = 'Target setup \u002F test execution'; status = 'FAIL'; detail = \"$_\" })\n} finally {\n    try {\n        if ($uiStarted) { Invoke-WinAppChecked (@('ui', 'yield') + $ScopeArgs) | Out-Null }\n    } catch {\n        $results.Add(@{ name = 'Release UI workflow'; status = 'FAIL'; detail = \"$_\" })\n    } finally {\n        $env:WINAPP_UI_WORKFLOW_ID = $previousWorkflowId\n    }\n}\n\n$failed = @($results | Where-Object { $_.status -eq 'FAIL' }).Count\n$report = [ordered]@{\n    target = $Target; appPid = $AppPid; workflowId = $WorkflowId\n    passed = $results.Count - $failed; failed = $failed\n    results = @($results.ToArray()); screenshots = @($screenshots.ToArray())\n}\n$report | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath '.\\test-results.json' -Encoding utf8\nWrite-Host \"Passed: $($report.passed) | Failed: $failed | Results: .\\test-results.json\"\nif ($failed) { exit 1 }\nexit 0\n```\n\nWithin a test, **throw**, not `exit`; the script fails on CLI errors, empty inspections, and undelivered evidence. Screenshots target the known main HWND so each lands at one exact host path; use `--capture-screen` when popups must be included.\n\n### Step 3: Run, read, and visually verify\n\n```powershell\n# Preferred when Windows Sandbox is available:\n.\\ui-tests.ps1 -Target sandbox\nif ($LASTEXITCODE -ne 0) { throw 'UI batch failed; read test-results.json.' }\n$report = Get-Content -LiteralPath '.\\test-results.json' -Raw | ConvertFrom-Json\n$report.screenshots\n```\n\nFor a captured, still-live guest PID, use `.\\ui-tests.ps1 -Target sandbox -AppPid 1234 -AppScope sandbox`. For a local run (see Step 1), use `.\\ui-tests.ps1 -Target local`, optionally with a local PID and `-AppScope local`. Never reuse a guest PID locally or switch targets to make failing tests pass.\n\nView **each host PNG** listed in `test-results.json` with the image-viewing tool. UIA PASS cannot detect clipping, overlap, incorrect theming, or content bleeding past its container. Fail visual review for unintended scrollbars, unintended ellipses, clipped hero\u002Fright-edge controls, overlapping rows, unbalanced whitespace, cramped\u002Fvast spacing, incorrect Light\u002FDark\u002FHigh Contrast, or missing focus\u002Fhover\u002Ferror states. Capture meaningful states immediately after their interactions, not just at the end.\n\nIf fixes are requested, batch-fix failures, rebuild\u002Frelaunch with the same target using the template (omit `-AppPid` to launch again), and capture the new PID. Maximum **two** fix-and-rerun cycles; then report remaining failures. Do not declare completion without the structured results **and** visual review.\n\n### Assertions and coverage\n\nWrite tests for every requested requirement. Use `wait-for --value` for TextBox\u002FNumberBox values, RichEditBox text, ComboBox selection, toggle\u002Fcheckbox `On`\u002F`Off`, and TextBlock\u002Flabel text. `--contains` matches a substring; `--gone` waits for disappearance. Use `-p IsEnabled --value True` only for a specific property. Invoke buttons\u002Fnav items, wait for page-specific elements, and test default\u002Ferror\u002Fempty states.\n\nThe following examples are additions to the template, not independent shells. `Invoke-Ui` always supplies the chosen scope plus `-a $AppPid`, or scope plus `-w $Window`. For raw reads, pass `--json` and parse it; plain stdout can include advisory messages. Use `scroll-into-view` before asserting a virtualized item below the fold.\n\n```powershell\nTest-UI 'Status and enabled state' {\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'saved', '--contains', '-t', '3000')\n    Invoke-Ui @('wait-for', 'BtnSave', '-p', 'IsEnabled', '--value', 'True', '-t', '3000')\n    $value = Invoke-Ui @('get-value', 'TxtUserName', '--json') | ConvertFrom-Json\n    if ($value.text -ne 'TestUser') { throw 'Wrong username.' }\n}\n```\n\n### File pickers, flyouts, and ContentDialogs\n\nPickers run in a separate `PickerHost` process. Discover their HWND in the **same target**; `-w` changes the window selector, never the target. Replace the filename with a file that exists **in the guest** for Sandbox testing.\n\n```powershell\nTest-UI 'Open file picker' {\n    Invoke-Ui @('invoke', 'BtnOpenFile')\n    Start-Sleep -Seconds 1\n    $allWindows = @(Invoke-WinAppChecked (@('ui', 'list-windows', '--json') + $ScopeArgs) | ConvertFrom-Json)\n    $pickers = @($allWindows | Where-Object { $_.hwnd -and [string]$_.ownerHwnd -eq $hwnd -and $_.title -match 'Open|Save' })\n    if ($pickers.Count -ne 1) { throw 'Expected one picker; inspect the selected target again.' }\n    $pickerHwnd = [string]$pickers[0].hwnd\n    Invoke-Ui @('inspect', '--interactive', '--json') -Window $pickerHwnd\n    Invoke-Ui @('set-value', 'FileNameControlHost', 'test.txt') -Window $pickerHwnd\n    Invoke-Ui @('invoke', 'Open') -Window $pickerHwnd\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'opened', '--contains', '-t', '3000')\n}\n\nTest-UI 'Copy context menu' {\n    Invoke-Ui @('click', 'LstItems', '--right')\n    Invoke-Ui @('wait-for', 'MnuCopy', '-t', '2000')\n    Invoke-Ui @('invoke', 'MnuCopy')\n    Invoke-Ui @('wait-for', 'StatusText', '--value', 'Copied', '-t', '2000')\n}\n\nTest-UI 'Confirm deletion' {\n    Invoke-Ui @('invoke', 'BtnDelete')\n    Invoke-Ui @('wait-for', 'Primary', '-t', '2000')\n    Invoke-Ui @('invoke', 'Primary')\n    Invoke-Ui @('wait-for', 'Primary', '--gone', '-t', '3000')\n}\n```\n\nFor Save\u002FCancel pickers, substitute the appropriate action and assertion. MenuBar headers and flyout items use `invoke` and `wait-for` similarly. ContentDialogs live in the app window; `Primary`, `Secondary`, and `Close` are common selectors, but inspect the actual open dialog because custom AutomationIds are not guaranteed.\n\n### Keyboard, hover, drag, touch, and pen\n\n`send-keys --via send-input` is required for accelerators and reliable per-character input in WinUI\u002FWPF text controls. `post-message` is HWND-targeted but does not produce per-character `KeyDown`. `--target` focuses first; `--verbatim` types literal key names. System shortcuts require the CLI's explicit permission flags; do not use them as a workaround for desktop-readiness errors.\n\n```powershell\nTest-UI 'Keyboard save' {\n    Invoke-Ui @('send-keys', 'hello world', '--target', 'TxtName', '--via', 'send-input')\n    Invoke-Ui @('send-keys', 'ctrl+s', '--via', 'send-input')\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'saved', '--contains', '-t', '2000')\n}\nTest-UI 'Tooltip' {\n    Invoke-Ui @('hover', 'BtnInfo')\n    Invoke-Ui @('wait-for', 'InfoTooltip', '-t', '2000')\n}\nTest-UI 'Reorder items' {\n    Invoke-Ui @('drag', 'ItemA', 'ItemB')\n    Invoke-Ui @('wait-for', 'StatusBar', '--value', 'reordered', '--contains', '-t', '2000')\n}\nTest-UI 'Touch and ink input' {\n    Invoke-Ui @('touch', 'LstFeed', '-g', 'swipe', '--direction', 'up', '--distance', '400')\n    Invoke-Ui @('pen', 'InkCanvas', '--path', '50,50 120,80 200,60', '--pressure', '0.8')\n    Save-Screenshot '03-ink.png'\n    # Add the app-specific state assertion; successful injection alone is not functional proof.\n}\n```\n\nUse `winapp ui drag --help`, `winapp ui touch --help`, and `winapp ui pen --help` for coordinates, long-press\u002Fdwell, pinch\u002Fstretch, pressure\u002Ftilt\u002Feraser support. Read coordinates in the guest tree; host coordinates are not guest coordinates.\n\n### Recordings and workflow coordination\n\n```powershell\nTest-UI 'Video delivered' {\n    $video = Join-Path $ArtifactDirectory 'flow.mp4'\n    if (Test-Path -LiteralPath $video) { throw 'Choose a new video evidence path.' }\n    Invoke-Ui @('record', '--duration-sec', '6', '--fps', '30', '--output', $video)\n    if (-not (Test-Path -LiteralPath $video -PathType Leaf) -or (Get-Item -LiteralPath $video).Length -eq 0) {\n        throw \"Recording was not delivered to the host: $video\"\n    }\n}\n```\n\nSandbox screenshot\u002Frecord **`--output` paths are host paths**, automatically delivered when capture completes; do not pull them from guessed guest directories. Use fresh output paths and check the exit status and actual host files. `--capture-screen` can include popups outside the app window. For an interrupted recording, preserve `stopReason`, `partialOutput`, `recoveryHint`, and the reported partial\u002Frecovery paths; a nonempty partial file is not necessarily playable.\n\nWinApp CLI arbitrates desktop-changing commands automatically. Without a workflow ID, each command releases its turn immediately; with one, the four-second grace covers tight script bursts, not agent reasoning. Use the **same `WINAPP_UI_WORKFLOW_ID`** for cooperating commands, including concurrent recording and interaction; independent flows need distinct IDs. The template accepts `-WorkflowId` for this purpose, sets it in its own process, restores the previous value, and calls `winapp ui yield --on sandbox` in `finally`. Fresh shell tool calls do not inherit changes from an earlier shell: set the same ID on **every** cooperating invocation. A separate concurrent recording process must also check its exit code\u002Fdelivery, use the same scoped PID, and finish before the test runner yields. Do not start an independent-ID recording that blocks the interactions it is meant to capture. After a pause, inspect again and reopen menus\u002Fdialogs another workflow may have changed.\n\n### Guest persistence and arbitrary file transfer\n\nDo not inspect **host** `$env:LOCALAPPDATA` to prove **guest** persistence. Check the actual app data file in the selected target. Replace the sample package family\u002Fpath with the app's real storage location; unpackaged apps usually use an app-specific LocalAppData directory.\n\n```powershell\nTest-UI 'Username persisted in selected target' {\n    $readSettings = @'\n$ErrorActionPreference = 'Stop'\n$file = Join-Path $env:LOCALAPPDATA 'Packages\\YourPackageFamily\\LocalState\\settings.json'\nif (-not (Test-Path -LiteralPath $file -PathType Leaf)) { throw \"Missing settings: $file\" }\nGet-Content -LiteralPath $file -Raw\n'@\n    $json = if ($Target -eq 'sandbox') {\n        Invoke-WinAppChecked @('target', 'exec', 'sandbox', '--', 'powershell.exe', '-NoProfile', '-NonInteractive', '-Command', $readSettings)\n    } else {\n        & ([scriptblock]::Create($readSettings))\n    }\n    $settings = $json | ConvertFrom-Json\n    if ($settings.UserName -ne 'TestUser') { throw 'Saved username does not match.' }\n}\n```\n\nFor arbitrary setup\u002Fresults files, use `target exec` \u002F `push` \u002F `pull`, not host filesystem guesses. Transfer guest paths are **relative to snapshot `workRoot`**, normally `C:\\WinApp\\work`, not absolute guest paths. The following optional additions assume a host `setup.ps1` that creates `Results` under the guest work root:\n\n```powershell\nTest-UI 'Guest setup and result transfer' {\n    if ($Target -ne 'sandbox') { throw 'This transfer test requires Sandbox.' }\n    $snapshot = Invoke-WinAppChecked @('target', 'snapshot', 'sandbox', '--json') | ConvertFrom-Json\n    if (-not $snapshot.workRoot) { throw 'No live guest workRoot; fix readiness first.' }\n    Invoke-WinAppChecked @('target', 'push', 'sandbox', '.\\setup.ps1', 'Setup\\setup.ps1')\n    $guestSetup = $snapshot.workRoot.TrimEnd('\\') + '\\Setup\\setup.ps1'\n    Invoke-WinAppChecked @('target', 'exec', 'sandbox', '--', 'powershell.exe', '-NoProfile', '-File', $guestSetup)\n    Invoke-WinAppChecked @('target', 'pull', 'sandbox', 'Results', (Join-Path $ArtifactDirectory 'results'))\n}\n```\n\nKeep the guest alive while recovering failed delivery. Preserve evidence\u002Frecovery paths and app data needed for diagnosis before any **user-consented** shutdown; never stop all Sandboxes as routine cleanup.\n\n### Binding and selector gotchas\n\n- `set-value` does not commit default WinUI `x:Bind TwoWay` TextBox bindings until focus changes. Prefer `UpdateSourceTrigger=PropertyChanged` in the app; otherwise `invoke` Save or `focus` another control before checking persistence.\n- RichEditBox\u002FRichTextBox generally need `send-keys --via send-input`, not UIA `set-value`.\n- Use `$AppPid`, never PowerShell's read-only automatic `$Pid`.\n- A picker HWND needs `-w` **and the same target scope**. A fresh guest invalidates both HWNDs and PIDs; do not recycle either.\n",{"name":5,"description":7},"main","1fe910277860e8dbb38bfbeef7e8bdb039d6ee41","plugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-ui-testing",96,"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli","https:\u002F\u002Fgithub.com\u002Fmicrosoft","https:\u002F\u002Fopensource.microsoft.com","Open source projects and samples from Microsoft","2026-11-14 07:14:37",{"source":8,"skillName":5,"commands":65,"prompt":75,"zipAvailable":76},[66,69,72],{"tool":67,"command":68},"npx","npx skills add microsoft\u002FwinappCli --skill winui-ui-testing",{"tool":70,"command":71},"bunx","bunx skills add microsoft\u002FwinappCli --skill winui-ui-testing",{"tool":73,"command":74},"pnpm","pnpm dlx skills add microsoft\u002FwinappCli --skill winui-ui-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-ui-testing\u002FSKILL.md",true,[],[79,102,127,148,163,192],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":50},"01M699M75MK9AADQV8PQQQ6NEV","winui-wpf-migration","Migrate or port a WPF app to WinUI 3: namespaces (System.Windows to Microsoft.UI.Xaml), control mapping (DataGrid, WrapPanel, TabControl), Dispatcher to DispatcherQueue, imaging, MVVM with CommunityToolkit.Mvvm, ThemeResource. Use when converting WPF code or fixing migration build errors.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-wpf-migration\u002FSKILL.md",[],[86,31,87,88,9,47,89,90,91,32,92,93,94,95,96,97,98,99,100,101,34],"winui wpf migration","wpf","migration","dispatcher","code","xaml","migrate","system","use","mvvm","app","mapping","port","imaging","errors","namespaces",{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":111,"publishedAt":50},"01M699M2KTEYJZBDW7JBHM94K0","winui-setup","Install and verify WinUI 3 prerequisites — .NET SDK 8.0.100+, WinApp CLI 0.7+, and Developer Mode; identify additional Native AOT and Windows Sandbox requirements. Use when the user asks to set up or repair the toolchain, or when another WinUI skill finds a missing or outdated prerequisite.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-setup\u002FSKILL.md",[108],{"categoryNo":109,"categoryName":110,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000030","开发工程师",[112,113,31,114,48,115,47,116,117,118,94,119,120,121,122,123,124,125,126,34],"winui setup","setup","cli","sdk","SET","verify","install","up","repair","requirements","missing","native","toolchain","winapp cli","mode",{"skillNo":128,"name":129,"nameZh":6,"description":130,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":131,"categories":132,"keywords":136,"publishedAt":50},"01M699KZWEZ84A4J3291E6R65B","winui-packaging","MSIX packaging, signing, and Microsoft Store publishing for WinUI 3 apps with WinApp CLI 0.7+: project packaging, Native AOT, certificates, self-contained deployment, CI\u002FCD. Use when releasing or publishing a WinUI app. Not for WPF, WinForms, or Electron apps that only reference the Windows App SDK.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-packaging\u002FSKILL.md",[133],{"categoryNo":134,"categoryName":135,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000011","运维与部署",[137,31,138,114,115,139,9,140,47,141,142,143,144,145,146,96,39,37,123,147,125,35,34],"winui packaging","packaging","electron","msix","windows app sdk","ci","certificates","only","self","project","CI\u002FCD",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":50},"01M699KXTHG9FHK4X3JSZ4SV8J","winui-dev-workflow","Create, build, run, and fix build errors in WinUI 3 apps (C# or C++) with WinApp CLI 0.7+: winapp new, winapp run, Native AOT, crash diagnosis. Use for a new WinUI app or a WinUI project that fails to build or crashes. Not for WPF, WinForms, or Electron apps that only reference the Windows App SDK.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-dev-workflow\u002FSKILL.md",[],[155,156,31,157,158,114,115,139,47,159,46,160,144,146,96,161,39,37,123,125,100,162],"workflow","winui dev workflow","dev","dev workflow","create","fix","diagnosis","new",{"skillNo":164,"name":165,"nameZh":6,"description":166,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":167,"categories":168,"keywords":179,"publishedAt":50},"01M699KV0Q6NE5EET5EDBH33NM","winui-design","Read before writing or changing WinUI 3 XAML: choosing controls, pages and navigation, layout, Fluent Design, theming, accessibility, x:Bind, real samples, and checking that APIs exist with winapp find-api. Not for WPF or WinForms UI, even if the app uses the Windows App SDK.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-design\u002FSKILL.md",[169,172,175,176],{"categoryNo":170,"categoryName":171,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":173,"categoryName":174,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},{"categoryNo":177,"categoryName":178,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000036","内容创作者",[180,181,31,182,115,183,184,47,141,87,91,32,185,186,187,188,189,96,37,190,35,191],"design","winui design","writing","accessibility","fluent","api","read","layout","pages","bind","controls","fluent design",{"skillNo":193,"name":194,"nameZh":6,"description":195,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":196,"categories":197,"keywords":202,"publishedAt":50},"01M699KR63WV521C7JT7FQMADN","winui-code-review","Review WinUI 3 code or changes for quality: MVVM, x:Bind correctness, accessibility, theming, security, performance, and WinUI analyzer findings. Use when asked to review or audit a WinUI app or its pending changes, or before committing. Catches issues the compiler and UI tests miss.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FwinappCli\u002Fblob\u002Fmain\u002Fplugins\u002Fwinui\u002Fagent-plugin\u002Fskills\u002Fwinui-code-review\u002FSKILL.md",[198,201],{"categoryNo":199,"categoryName":200,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000007","代码审查",{"categoryNo":109,"categoryName":110,"taxonomyType":26,"taxonomyTypeDesc":27},[203,204,205,90,31,206,207,183,208,209,210,94,95,211,189,96,212,213,35,214,215,34],"code review","review","winui code review","security","performance","issues","winui app","compiler","tests","theming","correctness","changes","pending"]