# Windows驅動程序
---
Appium支持自動運行Windows PC桌面應用程序,該驅動程序依賴于微軟的項目[WinAppDriver](https://github.com/Microsoft/WinAppDriver)。WinAppDriver是一個與appium兼容的WebDriver服務器, 適用于Windows桌面應用程序,
通常縮寫為WAD。WAD通常與Appium捆綁在一起安裝,不需要單獨安裝。
Windows驅動程序支持測試通用Windows平臺(UWP)和經典Windows(Win32)應用程序。
除了WAD存儲庫,Appium也在[appium-windows-driver](https://github.com/appium/appium-windows-driver)存儲庫中進行開發。
## 需求和支持
(除了Appium的一般要求外)
* 裝有Windows 10或更高版本的Windows PC
* 支持進入管理員模式
## 使用
使用Windows驅動程序啟動回話的方法:
* 確保在[新的會話請求](https://github.com/JiangSine/appium/blob/master../drivers/windows.md#TODO)中包含platformName[功能](https://github.com/JiangSine/appium/blob/master../drivers/windows.md#TODO)且值為Windows
* 確保deviceName功能設置為WindowsPC
* 至少包括適當的應用程序功能(請參閱下文)
## 功能
Windows驅動程序支持許多標準的[Appium功能](https://github.com/JiangSine/appium/blob/master../writing-running-appium/caps.md)。請參閱下面的內容,了解如何將他們專門用于Windows驅動程序。
### 設置
確保打開[開發人員模式](https://docs.microsoft.com/en-us/windows/uwp/get-started/enable-your-device-for-development)即可進行Windows應用測試。
在運行Appium時,無論是通過Appium Desktop啟動還是命令行啟動,請確保以管理員身份進行操作。
### 為Windows驅動程序編寫測試腳本
您可以參照現有示例:
#### Java樣本
1. 在Java IDE(例如IntelliJ)中,將示例文件夾作為現有項目打開。例如:[CalculatorTest](https://github.com/Microsoft/WinAppDriver/tree/master/Samples/Java/CalculatorTest).
2. 在Java IDE中構建并運行測試。
#### C#示例
1. 在[CalculatorTest](https://github.com/Microsoft/WinAppDriver/tree/master/Samples/C%23/CalculatorTest)文件下拉出并打開CalculatorTest.sln
2. 在帶有測試解決方案的Visual Studio 2015中打開構建測試,選擇測試->運行->所有測試。
#### JavaScript/node示例
1. 使用selenium-webdriver
[Examples on selenium-appium](https://github.com/react-native-windows/selenium-appium/tree/master/example)
[selenium-webdriver-winappdriver-example](selenium-webdriver-winappdriver-example)
如果您想從頭開始編寫測試,則可以選擇Appium/Selenium支持的任何編程語言或工具來編寫測試腳本。 在下面的示例中,我們將使用Microsoft Visual Studio 2015在C#中編寫測試腳本。
#### 創建測試項目
1. 打開Microsoft Visual Studio 2015
2. 創建測試項目和解決方案。 選擇“新建項目”>“模板”>“ Visual C#”>“測試”>“單元測試項目”
3. 創建完成后,選擇“項目”>“管理NuGet程序包...”>瀏覽并搜索Appium.WebDriver
4. 為測試項目安裝Appium.WebDriver NuGet軟件包
5. 開始編寫測試(請參閱[示例]下的示例代碼)
#### 通用Windows平臺應用程序測試
要測試UWP應用,您可以使用任何Selenium支持的語言,只需在應用功能條目中指定被測試應用的ID。 以下是使用C#編寫的案例,針對Windows Alarms&Clock應用程序創建測試會話的示例:
```
// Launch the AlarmClock app
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", "Microsoft.WindowsAlarms_8wekyb3d8bbwe!App");
AlarmClockSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
// Control the AlarmClock app
AlarmClockSession.FindElementByAccessibilityId("AddAlarmButton").Click();
AlarmClockSession.FindElementByAccessibilityId("AlarmNameTextBox").Clear();
```
測試自己編寫的應用程序時,可以在生成的AppX\\vs.appxrecipe文件中找到應用程序ID,如下:
`RegisteredUserNmodeAppID` node. E.g. `c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App`
#### 經典Windows App測試
要測試經典Windows應用程序,可以使用任何Selenium支持的語言,并在應用程序功能條目中指定被測應用程序的完整可執行路徑。 以下是為Windows記事本應用程序創建測試會話的示例:
```
// Launch Notepad
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe");
NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
// Control the AlarmClock app
```
#### 開始會話
如上所述,請使用以下功能來確保獲得Windows App自動化會話:
`platformName:Windows deviceName:WindowsPC app:`用于測試的Windows應用程序的appID,或.exe文件的路徑
#### 檢查UI元素
默認情況下,Microsoft Visual Studio 2015包括Windows SDK,該SDK提供了很好的工具來檢查您正在測試的應用程序。 通過該工具,您可以使用Windows應用程序驅動程序查詢的每個UI元素/節點。 可以在Windows SDK文件夾(例如C:\\Program Files(x86)\\Windows Kits\\10\\bin\\x86)下找到inspect.exe工具。 該工具將顯示各種元素屬性。 下表顯示了應使用哪種Appium定位器策略來查找具有相應屬性的元素。
| 定位策略 | 匹配屬性 |
| :--- | :--- |
| accessibility id | AutomationId |
| class name | ClassName |
| name | Name |
- 關于TesterHome和MTSC
- 關于Appium
- 簡介
- Appium 客戶端
- 入門指南
- 已支持的平臺
- API 文檔
- Appium驅動
- XCUITest (iOS)
- XCUITest Real Devices (iOS)
- UIAutomation (iOS)
- UIAutomation Safari Launcher (iOS)
- UIAutomator (Android)
- UIAutomator2 (Android)
- Espresso (Android)
- Windows
- Mac
- Appium命令
- Status
- Execute Mobile Command
- Session
- Create
- End
- Get Session Capabilities
- Go Back
- Screenshot
- Source
- Timeouts
- Timeouts
- Implicit Wait
- Async Script
- Orientation
- Get Orientation
- Set Orientation
- Geolocation
- Get Geolocation
- Set Geolocation
- Logs
- Get Log Types
- Get Logs
- Events
- Log event
- Get events
- Settings
- Update Settings
- Get Device Settings
- Settings
- Update Settings
- Get Device Settings
- Execute Driver Script
- Device
- Activity
- Start Activity
- Current Activity
- Current Package
- App
- Install App
- Is App Installed
- Launch App
- Background App
- Close App
- Reset App
- Remove App
- Activate App
- Terminate App
- Get App State
- Get App Strings
- End Test Coverage
- Clipboard
- Get Clipboard
- Set Clipboard
- Emulator
- Power AC
- Power Capacity
- Files
- Push File
- Pull File
- Pull Folder
- Interactions
- Shake
- Lock
- Unlock
- Is Locked
- Rotate
- Keys
- Press keycode
- Long press keycode
- Hide Keyboard
- Is Keyboard Shown
- Network
- Toggle Airplane Mode
- Toggle Data
- Toggle WiFi
- Toggle Location Services
- Send SMS
- GSM Call
- GSM Signal
- GSM Voice
- Network Speed
- Performance Data
- Get Performance Data
- Performance Data Types
- Screen Recording
- Start Screen Recording
- Stop Screen Recording
- Simulator
- Perform Touch ID
- Toggle Touch ID Enrollment
- System
- Open Notifications
- System Bars
- System Time
- Display density
- Authentication
- Finger Print
- Element
- Find Element
- Find Elements
- Actions
- Click
- Send Keys
- Clear
- Attributes
- Text
- Name
- Attribute
- Selected
- Enabled
- Displayed
- Location
- Size
- Rect
- CSS Property
- Location in View
- Other
- Submit
- Active Element
- Equals Element
- Context
- Get Context
- Get All Contexts
- Set Context
- Interactions
- Mouse
- Move To
- Click
- Double Click
- Button Down
- Button Up
- Touch
- Single Tap
- Double Tap
- Move
- Touch Down
- Touch Up
- Long Press
- Scroll
- Flick
- Multi Touch Perform
- Touch Perform
- W3C Actions
- Web
- Window
- Set Window
- Close Window
- Get Handle
- Get Handles
- Get Title
- Get Window Size
- Set Window Size
- Get Window Position
- Set Window Position
- Maximize Window
- Navigation
- Go to URL
- Get URL
- Back
- Forward
- Refresh
- Storage
- Get All Cookies
- Set Cookie
- Delete Cookie
- Delete All Cookies
- Frame
- Switch to Frame
- Switch to Parent Frame
- Execute Async
- Execute
- 編寫 & 運行Appium腳本
- Running Tests
- Desired Capabilities
- The --default-capabilities flag
- Finding Elements
- Touch Actions
- CLI Arguments
- Server Security
- Web/Web Views
- Mobile Web Testing
- Automating Hybrid Apps
- Using ios-webkit-debug-proxy
- Using Chromedriver
- Image Comparison
- iOS
- Low-Level Insights on iOS Input Events
- XCUITest Mobile Gestures
- XCUITest Mobile App Management
- iOS Pasteboard Guide
- iOS Predicate Guide
- iOS Touch ID Guide
- iOS Install Certificate
- tvOS support
- Pushing/Pulling files
- Audio Capture
- Android
- Low-Level Insights on Android Input Events
- UiSelector Guide
- Espresso Datamatcher Guide
- Android Code Coverage Guide
- Activities Startup Troubleshooting Guide
- How To Execute Shell Commands On The Remote Device
- Android Device Screen Streaming
- How To Emulate IME Actions Generation
- How To Test Android App Bundle
- Other
- Reset Strategies
- Network Connection Guide
- Using Unicode with Appium
- Troubleshooting
- Tutorial
- Swipe Tutorial
- Screen
- Element
- Partial screen
- Simple
- Multiple scroll views
- Add scroll layout
- Tricks and Tips
- Screen
- Element
- Element search
- Fast
- Slow
- Guide
- 進階概念
- 定位圖像中的元素
- 使用定位元素的插件
- 遷移到 XCUITest
- 在 Appium 中使用 Selenium Grid
- Appium Logs Filtering
- 跨域 iframes
- 使用自定義 WDA 服務器
- 使用不同版本的 Xcode 運行
- The Event Timings API
- 并行測試的設置
- The Settings API
- Memory Collection
- 向Appium項目做貢獻
- 從源代碼運行 Appium
- 開發者概述
- 標準開發命令
- Appium 風格指南
- 如何編寫文檔
- Appium 包結構
- 鳴謝