指令 winapp ui 與 winui-ui-testing 技能讓你的 AI 代理自動檢查、互動並驗證應用程式的使用者介面——用自然語言描述它所見,讓你能在不先寫測試 harness 程式碼的情況下不斷迭代。
使用者介面檢查命令
winui-ui-testing 技能包含於 winui@awesome-copilot 外掛程式中。 如果你在 設定時就安裝了外掛,就不需要再額外安裝。
| Command | 其功能是什麼 |
|---|---|
winapp ui inspect |
拋棄執行中應用程式的無障礙樹 |
winapp ui screenshot |
擷取應用程式視窗的截圖 |
winapp ui click <selector> |
點擊按鈕或選擇物品 |
winapp ui invoke <selector> |
在控制項上呼叫預設動作 |
winapp ui search <text> |
透過名稱或 AutomationID 搜尋元素樹 |
winapp ui set-value <selector> <value> |
設定 TextBox 或 ComboBox 的值 |
請你的經紀人幫忙測試這個應用程式
- 執行應用程式:
dotnet run - 問你的代理人一個自然語言問題,例如:
看看正在執行中的應用程式,告訴我當表單為空時,「儲存」按鈕是否仍可點選。
- 客服人員會使用
winapp ui inspect並winapp ui screenshot檢查應用程式並回應。
這個工作流程讓你能在撰寫一行測試程式碼前,發現問題——像是鍵盤焦點缺失、控制鍵被停用、版面配置問題。
撰寫自動化測試
當你互動式地探索過應用程式後,請你的經紀人產生正式的測試。 請使用這個入門提示:
Write an xUnit UI test for my WinUI 3 app that:
1. Launches the app with dotnet run
2. Verifies the main window title is "My App"
3. Clicks the button with AutomationId "SaveButton"
4. Verifies a success message appears
Use the winapp ui commands for element interaction.
產生的測試以 winapp ui 指令作為互動層,因此它們不需要獨立的 UI 自動化框架來執行。
在你的 XAML 裡設定 AutomationIds
為了讓 winapp ui click 能可靠地鎖定元素,請在 XAML 中設定 AutomationProperties.AutomationId:
<Button AutomationProperties.AutomationId="SaveButton"
Content="Save" />
<TextBox AutomationProperties.AutomationId="TitleInput" />
問你的客服人員 :「在這個 XAML 裡為所有互動式控制項新增 AutomationID 屬性。」
在 CI 中執行測試
你可以在 GitHub Actions 工作流程中執行winapp ui指令。 測試需要圖形化會話;使用帶有 runs-on: windows-latest. 的 Windows 運行程式。
name: UI tests
on: [push, pull_request]
jobs:
ui-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Install winapp CLI
run: winget install --id Microsoft.WinAppCLI --silent --accept-package-agreements --accept-source-agreements --disable-interactivity
- name: Build
run: dotnet build
- name: Run UI tests
run: dotnet test --filter Category=UITest
附註
這些 winapp ui 指令與正在執行的程序的即時存取樹互動。 測試必須在測試設定期間啟動應用程式(或在 TestInitialize 步驟中啟動),並在清理階段將其關閉。
自動檢查無障礙
該 winapp ui inspect 指令會輸出完整的可及性樹——元素名稱、類型、狀態和 AutomationIds。 請你的經紀人檢視是否有無障礙漏洞:
Run "winapp ui inspect" on the running app and identify any issues:
- Controls without accessible names
- Missing keyboard focus order
- Buttons or links that aren't reachable by Tab
Report findings as a prioritized list, most critical first.
此提示作為執行正式稽核工具前的初步無障礙審查,效果良好。 完整的無障礙檢查清單,請參閱 Windows 應用程式的無障礙概覽。
相關內容
快速入門:使用 AI - WinUI 代理插件
- Windows應用程式的無障礙概述