## Appium 介紹
Appium 是一個自動化開源工具,支持 iOS 、 Android 和 Windows 桌面平臺上的原生、移動 Web 和混合應用的自動化 。**「原生應用」**指那些用 iOS、 Android 或者 Windows SDKs 編寫的應用。**「移動 Web 應用」**是用移動端瀏覽器訪問的應用( Appium 支持 iOS 上的 Safari 、Chrome 和 Android 上的內置瀏覽器)。**「混合應用」**帶有一個「webview」的包裝器——用來和 Web 內容交互的原生控件。類似于 [Apache Cordova](https://cordova.apache.org) 或 [Phonegap](http://phonegap.com/) 項目,創建一個混合應用使得用 Web 技術開發然后打包進原生包裝器創建一個混合應用變得容易了。
重要的是,Appium 是跨平臺的:它允許你用同樣的 API 對多平臺(iOS、Android、Windows)寫測試。做到在 iOS、Android 和 Windows 測試套件之間復用代碼。
了解 Appium “支持”這些平臺意味著什么、有哪些自動化方式的詳細信息,請參見 [Appium 支持的平臺](../about-appium/platform-support.md)。
### Appium 的理念
Appium 旨在滿足移動端自動化需求的理念,概述為以下四個原則:
1. 你不應該為了自動化而重新編譯你的應用或以任何方式修改它。
2. 你不應該被限制在特定的語言或框架上來編寫運行測試。
3. 移動端自動化框架不應該在自動化接口方面重造輪子。
4. 移動端自動化框架應該開源,在精神、實踐以及名義上都該如此。
### Appium 的設計
那么 Appium 項目的架構是如何實現這些理念的呢?為了實現理念#1,我們使用了系統自帶的自動化框架。這樣,我們不需要把 Appium 特定的或者第三方的代碼編譯進你的應用,這意味著**你測試使用的應用與最終發布的應用并無二致**。我們使用以下系統自帶的自動化框架:
* iOS 9.3 及以上: 蘋果的 [XCUITest](https://developer.apple.com/reference/xctest)
* iOS 9.3 及以下: 蘋果的 [UIAutomation](https://web.archive.org/web/20160904214108/https://developer.apple.com/library/ios/documentation/DeveloperTools/Reference/UIAutomationRef/)
* Android 4.3+: 谷歌的 [UiAutomator / UiAutomator2](https://developer.android.com/training/testing/ui-automator)
* Windows: 微軟的 [WinAppDriver](http://github.com/microsoft/winappdriver)
為了實現理念#2,我們把這些系統本身提供的框架包裝進一套 API —— [WebDriver](http://docs.seleniumhq.org/projects/webdriver/) API 中。WebDriver(也叫「Selenium WebDriver」)規定了一個客戶端-服務器協議(稱為 [JSON Wire Protocol](https://w3c.github.io/webdriver/webdriver-spec.html)),按照這種客戶端-服務器架構,可以使用任何語言編寫的客戶端向服務器發送適當的 HTTP 請求。已經有為 [各個流行編程語言編寫的客戶端](http://appium.io/downloads) 。這也意味著你可以自由使用任何你想用的的測試運行器和測試框架;客戶端程序庫不過是一個簡單的 HTTP 客戶端,可以以任何你喜歡的方式混入你的代碼。換句話說,Appium & WebDriver 客戶端在技術上而言不是「測試框架」,而是「自動化程序庫」。你可以以任何你喜歡的方式管理你的測試環境!
我們以同樣的方式實現理念#3:WebDriver 已經成為 Web 瀏覽器自動化事實上的標準,并且是一個 [W3C 工作草案](https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html)。何必在移動端做完全不同的嘗試?我們通過附加額外的 API 方法 [擴展協議](https://github.com/SeleniumHQ/mobile-spec/blob/master/spec-draft.md),這些方法對移動自動化非常有用。
理念#4是明確已知的——你在閱讀正是因為 [Appium 是開源的](https://github.com/appium/appium)。
### Appium 的概念
**客戶端 / 服務器架構**<br/>
Appium 的核心一個是暴露 REST API 的 WEB 服務器。它接受來自客戶端的連接,監聽命令并在移動設備上執行,答復 HTTP 響應來描述執行結果。實際上客戶端 / 服務器架構給予了我們許多可能性:我們可以使用任何有 http 客戶端 API 的語言編寫我們的測試代碼,不過選一個 [Appium 客戶端程序庫](http://appium.io/downloads) 用起來更為容易。我們可以把服務器放在另一臺機器上,而不是執行測試的機器。我們可以編寫測試代碼,并依靠類似 [Sauce Labs](https://saucelabs.com/products/mobile-app-testing) 的云服務接收和解釋命令。
**會話(Session)**<br/>
自動化始終在一個會話的上下文中執行,這些客戶端程序庫以各自的方式發起與服務器的會話,但最終都會發給服務器一個 `POST /session` 請求,請求中包含一個被稱作「預期能力(Desired Capabilities)」的 JSON 對象。這時服務器就會開啟這個自動化會話,并返回一個用于發送后續命令的會話 ID。
**預期能力(Desired Capabilities)**<br/>
預期能力(Desired Capabilities)是一些發送給 Appium 服務器的鍵值對集合(比如 map 或 hash),它告訴服務器我們想要啟動什么類型的自動化會話。也有許多能力(Capabilities)可以修改服務器在自動化過程中行為。例如,我們可以將 `platformName` 能力設置為 `iOS`,以告訴 Appium 我們想要 iOS 會話,而不是 Android 或者 Windows 會話。或者我們也可以設置 `safariAllowPopups` 能力為 `true` ,確保我們在 Safari 自動化會話期間可以使用 JavaScript 打開新窗口。有關 Appium 能力的完整列表,請參閱 [能力文檔](../writing-running-appium/caps.md) 。
**Appium 服務器**<br/>
Appium 是一個用 Node.js 寫的服務器。可以從[源碼](https://github.com/appium/appium/blob/master../contributing-to-appium/appium-from-source.md)構建安裝或者從 [NPM](https://www.npmjs.com/package/appium) 直接安裝:
```
$ npm install -g appium
$ appium
```
Appium 的 `beta` 版本可以通過 NPM 使用 `npm install -g appium@beta` 指令進行安裝。它是開發版本,所以可能存在破壞性的變更。在安裝新版本請卸載 `appium@beta` (`npm uninstall -g appium@beta`)以獲得一組干凈的依賴。
**Appium 客戶端**<br/>
有一些客戶端程序庫(分別在 Java、Ruby、Python、PHP、JavaScript 和 C# 中實現),它們支持 Appium 對 WebDriver 協議的擴展。你需要用這些客戶端程序庫代替常規的 WebDriver 客戶端。你可以在[這里](../about-appium/appium-clients.md)瀏覽所有程序庫的列表。
**[Appium Desktop](https://github.com/appium/appium-desktop)**<br/>
這有一個 Appium 服務器的圖形界面封裝可以下載,它適用于任何平臺。它打包了 Appium 服務器運行需要的所有東西,所以你不需要為 Node 而煩惱。它們還提供一個 Inspector 使你可以查看應用程序的層級結構。這在寫測試時可以派上用場。
### 入門指南
恭喜!你現在有足夠的知識來使用 Appium 了。 為什么不前往 [入門指南](../about-appium/getting-started.md) 了解更多詳細的要求和指南呢?
---
EOF.
由 @黑水 翻譯,TesterHome 社區 id:sanlengjingvv</br>
@lihuazhang 校驗
翻譯:@[Pandorym](https://github.com/Pandorym)
Last english version: ef7a1b17124966dbb87442d7356614791fe5e9ce, Oct 8, 2018
- 關于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 包結構
- 鳴謝