## Appium 服務器初始化參數(Capability)
初始化參數(Capability)是JSON數據類型編碼的鍵和值,當一個新的自動化會話被請求時,Appium客戶端發送此參數到服務端。此參數傳遞到Appium drivers有關您想要的各種重要事項測試工作。每種客戶端語言都有特定的Appium客戶端構建參數,但最終,他們以JSON數據發送到Appium。
初始化參數(Capability)可以編寫在WebDriver測試中或者存放在Appium Server GUI中(Inspector會話)。
一些重要的參數聲明示例如下:
```json
{
"platformName": "iOS",
"platformVersion": "11.0",
"deviceName": "iPhone 7",
"automationName": "XCUITest",
"app": "/path/to/my.app"
}
```
以上初始化參數表示Appium開始自動化會話在ios 11的iPhone 7模擬器上,使用[XCUITestDriver](../drivers/ios-xcuitest.md),`/path/to/my.app`作為測試app。
Appium支持很多參數,引擎不同參數也不同,然而大多數引擎都有一套標準。以下表格,列出了通用初始化參數,也支持特定引擎。
### 通用功能
此參數支持多種驅動程序
|鍵|描述|值|
|----|-----------|-------|
|`automationName`| 自動化測試的引擎 |`Appium` (默認)或者 `UiAutomator2`, `Espresso`, 或者 `UiAutomator1`(Android), 或者 `XCUITest`(IOS), 或者`YouiEngine` (You.i Engine)|
|`platformName`| 使用的手機操作系統 |`iOS`, `Android`, 或者 `FirefoxOS`|
|`platformVersion`| 手機操作系統的版本 |例如 `7.1`, `4.4`|
|`deviceName`| 使用的手機或模擬器類型 |`iPhone Simulator`, `iPad Simulator`, `iPhone Retina 4-inch`, `Android Emulator`, `Galaxy S4`, 等等.... 在 iOS 上,使用 Instruments 的 `instruments -s devices` 命令可返回一個有效的設備的列表。在 Andorid 上雖然這個參數目前已被忽略,但仍然需要添加上該參數。|
|`app`| 本地絕對路徑_或_遠程 http URL 所指向的一個安裝包(`.ipa`(IOS),`.app`(IOS模擬器),`.apk`(安卓),`.apks`(安卓app打包),或 `.zip` 文件)。Appium 將其安裝到合適的設備上。請注意,如果您指定了 `appPackage` 和 `appActivity` 參數(見下文),Android 則不需要此參數了。`UiAutomator2`和`XCUITest`允許在沒有`app`或`appPackage`的情況下啟動會話。該參數也與 `browserName` 不兼容。見 [此文](../writing-running-appium/android/android-appbundle.md) 關于 `.apks` 文件。|`/abs/path/to/my.apk` 或 `http://myapp.com/app.ipa`|
|`otherApps`| 在運行測試之前要安裝的應用程序或應用程序列表(作為JSON排列)。請注意,`Espresso`的`automationName`和iOS真機不支持。|例如 `"/path/to/app.apk"`, `https://www.example.com/url/to/app.apk`, `["http://appium.github.io/appium/assets/TestApp9.4.app.zip", "/path/to/app-b.app"]`|
|`browserName`|做自動化時使用的瀏覽器名字。如果是一個應用則只需填寫個空的字符串。|'Safari' 對應 iOS,'Chrome', 'Chromium', 或 'Browser' 則對應 Android|
|`newCommandTimeout`|用于客戶端在退出或者結束 session 之前,Appium 等待客戶端發送一條新命令所花費的時間(秒為單位)。|例如 `60`|
|`language`| iOS (僅XCUITest driver )和 Android 為模擬器設置語言。 |例如 `fr`|
|`locale`| iOS (僅XCUITest driver )和 Android 為模擬器設置所在區域,fr_CA` 對應 iOS,`CA` 對應 Android(國家名稱縮寫)。|例如 `fr_CA`, `CA`|
|`udid`| 連接真機的唯一設備號|例如 `1ae203187fc012g`|
|`orientation`| (僅支持模擬器) 模擬器當前的方向|`豎屏` 或 `橫屏`|
|`autoWebview`| 直接轉換到 Webview 上下文(context)。默認值為 `false`|`true`, `false`|
|`noReset`|在當前 session 下不會重置應用的狀態。見[此文](../writing-running-appium/other/reset-strategies.md)|`true`, `false`|
|`fullReset`|執行一個完整的重置. 見 [此文](../writing-running-appium/other/reset-strategies.md)|`true`, `false`|
|`eventTimings`|啟用或禁用各種Appium-internal事件的時間報告 (例如 每個命令的開始和結束,等等)。 默認值為 `false`。啟用, 用 `true`。然后,在查詢當前會話的響應上,計時被報告為`events`屬性。 見響應結構[此文](../advanced-concepts/event-timings.md)|例如 `true`|
|`enablePerformanceLogging`| (僅Web和webview) 啟用Chromedriver(Android)或Safari(iOS)的性能日志 (默認值為 `false`)| `true`, `false`|
|`printPageSourceOnFindFailure`| 當查找操作失敗時,打印當前頁源文件。 默認值為 `false`|例如 `true`|
|`clearSystemFiles`| 在會話結束時刪除所有生成的文件。 默認值為 `false`| `true`, `false`|
- [更新設置](#更新設置)
|鍵|描述|值|
|----|-----------|-------|
|`settings[settingsKey]`| 在會話創建時更新 [更新設置](https://github.com/appium/appium/blob/master../advanced-concepts/settings.md). |例如 `'settings[mjpegScalingFactor]': 10`, `'settings[shouldUseCompactResponses]': true`|
### Android 獨有
這些參數只能在基于Android drivers上使用 (例如 [UiAutomator2](../drivers/android-uiautomator2.md))。
|鍵|描述|值|
|----|-----------|-------|
|`appActivity`|Activity 的名字是指從你的包中所要啟動的 Android acticity。他通常需要再前面添加`.` (例如 使用 `.MainActivity` 代替 `MainActivity`)。默認情況下,此參數是從軟件包manifest中接收的(action: android.intent.action.MAIN , category: android.intent.category.LAUNCHER)|`MainActivity`, `.Settings`|
|`appPackage`| 運行的 Android 應用的包名。默認情況下,此參數是從軟件包manifest中接收的。(@package屬性值)|`com.example.android.myApp`, `com.android.settings`|
|`appWaitActivity`| Activity name/names,逗號分隔,用于你要等待的Android Activity。 :默認情況下,此參數的值和`appActivity`相同. 如果你的參數中有`appActivity`和`appPackage`,必須設置activity以防和`appActivity`不同。你也可以使用通配符(`*`)。 |`SplashActivity`, `SplashActivity,OtherActivity`, `*`, `*.SplashActivity`|
|`appWaitPackage`| 用于等待啟動的 Android 應用的包。默認情況下,此功能的值與`appActivity`的值相同|`com.example.android.myApp`, `com.android.settings`|
|`appWaitDuration`| 用于等待 appWaitActivity 啟動的超時時間(以毫秒為單位)(默認值為 `20000`)| `30000`|
|`deviceReadyTimeout`| 用于等待模擬器或真機準備就緒的超時時間 |`5`|
|`allowTestPackages`| 允許安裝測試包(mainfest中`android:testOnly="true"`) 默認值為`false` |`true` 或 `false`|
|`androidCoverage`| 用于執行測試的 instrumentation 類。 傳送 `-w` 參數到如下命令 `adb shell am instrument -e coverage true -w `| `com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation`|
|`androidCoverageEndIntent`| 一個自己實現的廣播操作,用于將覆蓋率轉儲到文件系統中。傳送 `-a` 參數到如下命令 `adb shell am broadcast -a` | `com.example.pkg.END_EMMA`|
|`androidDeviceReadyTimeout`| 用于等待設備在啟動應用后準備就緒的超時時間。以秒為單位。 |例如 `30`|
|`androidInstallTimeout`| 用于等待在設備中安裝 apk 所花費的時間(以毫秒為單位)。默認值為 `90000` |例如 `90000`|
|`androidInstallPath`| 安裝前將在其中推送apk的設備上的目錄名。默認值為`/data/local/tmp` |例如 `/sdcard/Downloads/`|
|`adbPort`| 用來連接 ADB 服務器的端口(默認值為 `5037`)|`5037`|
|`systemPort` | `systemPort` 用于連接 [appium-uiautomator2-server](https://github.com/appium/appium-uiautomator2-server) 或 [appium-espresso-driver](https://github.com/appium/appium-espresso-driver). _appium-uiautomator2-server_通常情況默認值為 `8200` ,可 從`8200`到`8299`選擇一個端口。對于_appium-espresso-driver_,默認值為`8300`,端口地址可從`8300`到`8399`中選擇一個。當并行運行測試時,必須調整端口以避免沖突。 參見 [并行測試](https://github.com/appium/appium/blob/master../advanced-concepts/parallel-tests.md#parallel-android-tests) | 例如 `8201` |
|`remoteAdbHost`|可選的遠程ADB服務器主機|例如 192.168.0.101|
|`androidDeviceSocket`|開發工具的 socket 名稱。只有在被測應用是一個使用 Chromium 內核的瀏覽器時才需要。socket 會被瀏覽器打開,然后 Chromedriver 把它作為開發者工具來進行連接。|例如 `chrome_devtools_remote`|
|`avd`| 被啟動 avd 的名字|例如 `api19`|
|`avdLaunchTimeout`| 用于等待 avd 啟動并連接 ADB 的超時時間(以毫秒為單位),默認值為 `60000`。| `300000`|
|`avdReadyTimeout`| 用于等待 avd 完成啟動動畫的超時時間(以毫秒為單位),默認值為 `120000`。| `300000`|
|`avdArgs`| 啟動 avd 時使用的額外參數|例如 `-netfast`|
|`useKeystore`| 使用自定義的 keystore 給 apk 簽名,默認值為 `false`|`true`或`false`|
|`keystorePath`| 自定義 keystore 的路徑, 默認路徑為 ~/.android/debug.keystore|例如 `/path/to.keystore`|
|`keystorePassword`| 自定義 keystore 的密碼|例如 `foo`|
|`keyAlias`| key 的別名|例如 `androiddebugkey`|
|`keyPassword`| key 的密碼 |例如 `foo`|
|`chromedriverExecutable`| webdriver 可執行文件的絕對路徑(如果 Chromium 內嵌一個自己提供的 webdriver,則應使用他去替換掉 Appium 自帶的 chromedriver)|`/abs/path/to/webdriver`|
|`chromedriverArgs`| 當由Appium運行時,要傳遞給chromedriver二進制文件的參數數組。默認情況下,除了Appium內部使用的以外,不會添加CLI參數 (例如 `--url-base`, `--port`, `--adb-port`, and `--log-path`. | 例如 `["--disable-gpu", "--disable-web-security"]` |
|`chromedriverExecutableDir`|用于查找Chromedriver可執行文件的目錄的絕對路徑,用于自動發現兼容的Chromedriver。忽略 `chromedriverUseSystemExecutable` 為 `true` |`/abs/path/to/chromedriver/directory`|
|`chromedriverChromeMappingFile` | 將Chromedriver版本映射到它所支持的最小Chrome的文件的絕對路徑。忽略`chromedriverUseSystemExecutable` 為`true`|`/abs/path/to/mapping.json`|
|`chromedriverUseSystemExecutable`| 當 `true`時, 繞過自動Chromedriver配置,使用隨Appium下載的版本。 忽略 `chromedriverExecutable` 已設置。 默認值為 `false` |例如 `true`|
|`autoWebviewTimeout`| 用于等待 Webview 上下文(context)激活的時間(以毫秒為單位)。默認值為 `2000`| 例如 `4`|
|`chromedriverPort`|數字端口啟動Chromedriver。請注意,不建議使用此功能,因為在有多個webview的情況下,它會導致未定義的行為。默認情況下,Appium會找到一個空閑端口。|例如`8000`|
|`chromedriverPorts`| Appium用于與Chromedrivers通信的有效端口列表。這個功能支持多種webview場景。此參數的形式是一個數值端口數組,數組項本身可以是長度為2的數組,其中第一個元素是包含范圍的開始,第二個元素是結束。默認情況下,Appium將使用任何空閑端口。|例如 `[8000, [9000, 9005]]`|
|`ensureWebviewsHavePages`| Appium是否應該增強它的頁面webview檢測,以保證任何webview上下文顯示在上下文列表有活動的頁面。 這可以防止在Chromedriver無法找到任何頁面的情況下選擇上下文時發生的錯誤。 默認值為 `false`|例如 `true`|
|`webviewDevtoolsPort`| 為了支持`ensureWebviewsHavePages`特性,有必要打開一個TCP端口來與被測試設備上的webview通信。這個參數允許覆蓋默認端口`9222`,以防多個會話同時運行(以避免端口沖突),或者默認端口不適合您的系統|例如 `9543`|
| `enableWebviewDetailsCollection` | 自Appium1.18.0+起啟用通過`/json/version`CDP(Chrome開發者協議)端點收集詳細的WebView信息。這有助于正確匹配支持給定WebView的Chromedriver版本。如果沒有啟用此標志,Appium會嘗試根據相應已安裝軟件包的版本來猜測WebView的版本。(自定義web視圖[失敗詳見](https://github.com/appium/appium/issues/13918)) 默認值為 `false` | `true` 或 `false` |
|`dontStopAppOnReset`| 在使用adb啟動應用程序之前,不要停止被測應用程序的進程。 如果被測試的應用程序是由另一個錨定應用程序創建的,則將其設置為false,則在使用adb啟動測試應用程序的過程中,錨定應用程序的過程仍然可以運行。換句話說,當`dontStopAppOnReset`設置為`true`時,在`adb shell am start`調用中將不包括`-S`標志。省略此參數或將其設置為`false`時,包含`-S`標志。默認值為 `false`| `true` 或 `false`|
|`unicodeKeyboard`| 使用 Unicode 輸入法。 默認值為 `false`| `true`或`false`|
|`resetKeyboard`| 在設定了 `unicodeKeyboard` 關鍵字的 Unicode 測試結束后,重置輸入法到原有狀態。如果單獨使用,將會被忽略。默認值為 `false` | `true`或`false`|
|`noSign`| 跳過檢查和對應用進行 debug 簽名的步驟。僅適用于 UiAutomator。 默認值為 `false`| `true`或`false`|
|`ignoreUnimportantViews`| 調用 uiautomator 的函數 `setCompressedLayoutHierarchy()`。由于 Accessibility 命令在忽略部分元素的情況下執行速度會加快,這個關鍵字能加快測試執行的速度。被忽略的元素將不能夠被找到,因此這個關鍵字同時也被實現成可以隨時改變的 *設置 ( settings )*。 默認值為 `false` | `true` 或 `false` |
|`disableAndroidWatchers`| 禁用 android 監視器(watchers)。監視器用于見識應用程序的無響應狀態(anr)和崩潰(crash),禁用會降低 Android 設備或模擬器的 CPU 使用率。該 capability 僅在使用 UiAutomator 時有效。默認設置為 `false`。 | `true` 或 `false`|
|`chromeOptions`| 允許對 ChromeDriver 傳 chromeOptions 的參數。了解更多信息請查閱 [chromeOptions](https://sites.google.com/a/chromium.org/chromedriver/capabilities)| `chromeOptions: {args: ['--disable-popup-blocking']}` |
|`recreateChromeDriverSessions`| 當移除非 ChromeDriver webview時,終止掉 ChromeDriver 的 session。默認設置為 `false` | `true`或`false`|
|`nativeWebScreenshot`| 在 web 的上下文(context),使用原生(native)的方法去截圖,而不是用過代理的 ChromeDriver。默認值為 `false` | `true`或`false`|
|`androidScreenshotPath`| 在設備中截圖被保存的目錄名。默認值為 `/data/local/tmp` |例如 `/sdcard/screenshots/`|
|`autoGrantPermissions`|讓Appium自動確定您的應用需要哪些權限,并在安裝時將其授予應用。默認設置為 `false`。如果`noReset`參數為`true`,此參數無效。|`true`或`false`|
|`networkSpeed`|模擬設置網絡速度。指定最大的網絡上傳和下載速度。 默認值為 `full`| `['full', 'gsm', 'edge', 'hscsd', 'gprs', 'umts', 'hsdpa', 'lte', 'evdo']` 詳見 [-netspeed選項](https://developer.android.com/studio/run/emulator-commandline.html)|
|`gpsEnabled`|在開始會話之前,為模擬器切換gps位置提供程序。 默認情況下,仿真器將根據配置方式啟用或不啟用此選項。|`true` 或 `false`|
|`isHeadless`|設置此參數為`true`, 當不需要顯示設備顯示時,無頭運行仿真器。 默認值為 `false` 。 `_isHeadless_ `也支持 iOS, 參見 XCUITest-specific 參數. |例如 `true`|
|`adbExecTimeout`| 用于等待adb命令執行的超時(毫秒)。默認值為 `20000` |例如 `50000`|
|`localeScript`| 設置地區 [見此文](https://developer.android.com/reference/java/util/Locale) | 例如 ` "Cyrl"` (Cyrillic)|
|`skipDeviceInitialization`| 跳過設備初始化,其中包括i.a.:設置app的安裝運行或權限設置。當設備已經被用于自動化并且為下一個自動化做好了準備時,可以用來提高啟動性能。 默認值為 `false` | `true` 或 `false`|
|`chromedriverDisableBuildCheck`| 為Chrome webview測試設置chromedriver標志`--disable-build-check`。 | `true` 或 `false` |
|`skipUnlock`|在會話創建期間跳過解鎖。 默認值為`false` | `true` 或 `false` |
|`unlockType`|使用特定的鎖定模式解鎖目標設備,而不僅僅是使用助手應用程序喚醒設備。 和 `unlockKey` 參數一起使用. 默認值為 undefined. `fingerprint` 僅支持Android 6.0+ 和 模擬器。 詳見 [解鎖](https://github.com/appium/appium-android-driver/blob/master/docs/UNLOCK.md) 。| `['pin', 'password', 'pattern', 'fingerprint']` |
|`unlockKey`|使用`unlockType`解鎖。 |例如 '1111'|
|`autoLaunch`| 自動初始化被測應用。 如果這是`false`,則Appium不會安裝/啟動被測應用程序。 默認值為 `true` | `true` 或 `false` |
|`skipLogcatCapture`|跳過開始捕獲logcat。它可以提高網絡等性能。與日志相關的命令不起作用。默認值為 `false`. |`true` 或 `false`|
|`uninstallOtherPackages`| 安裝apks之前,軟件包列表或`*` 卸載軟件包。 `'*'` 會卸載所有第三方軟件包,但Appium需要測試的軟件包除外,例如 `io.appium.settings` 或者`io.appium.uiautomator2.server` ,因為Appium已經包含管理它們的邏輯。 | 例如 `"io.appium.example"`, `["io.appium.example1", "io.appium.example2"]`, `'*'` |
|`disableWindowAnimation`|如果值為`true`,則設置設備動畫縮放為0。在會話完成后,Appium將動畫縮放恢復到它的原始值。默認值為 `false` | `true`, `false` |
|`remoteAppsCacheLimit`| 設置遠程高速緩存的apk的最大數量(默認為10),這些數量將被推送到被測設備的本地存儲。 當使用同一組apk時,通過遠程緩存apk可以避免每次需要重新安裝apk都將其推送到遠程文件系統時,可以加快順序測試用例的執行速度。 將此功能設置為`0`以禁用緩存。| 例如 `0`, `5`, `20` |
|`buildToolsVersion`| 將Android`build-tools`版本指定為不同于默認版本的版本(默認版本是使用最新版本)。如果您的環境使用alpha/beta構建工具,則使用非默認版本會很有幫助。 | 例如 `'28.0.3'` |
|`androidNaturalOrientation`| 允許在橫向設備上正確處理方向。設置為`true`來改變豎屏和橫屏的含義。默認值為 `false` | `true`, `false` |
|`enforceAppInstall`| 默認情況下,如果被測設備上已經存在此應用程序的更新或相同版本,則跳過該應用程序的安裝。將此選項設置為`true`,將強制Appium始終獨立于構建當前版本安裝當前應用程序。默認值為`false`. | `true` , `false` |
|`ignoreHiddenApiPolicyError`| 自Appium 1.18.0+,忽略`Security exception: Permission denial`警告,并允許繼續進行會話創建過程。 這個錯誤發生在Appium試圖放松的時候 [隱藏的API](https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces#how_can_i_enable_access_to_non-sdk_interfaces), 盡管有些設備有定制的固件拒絕這樣的請求。 默認值為 `false`. | `true`, `false` |
|`mockLocationApp`| 自Appium1.18.0+,設置應用程序的程序包標識符,用作系統模擬位置。此功能對模擬器沒有影響。如果該參數設置為`null`或空字符串,則Appium將跳過模擬的位置提供程序設置過程。 默認 Appium 設置包標識符 (`io.appium.settings`)。 | 例如 `null`, `io.appium.settings`, `example.your.app` |
|`logcatFormat`| 自Appium 1.18.0,設置logcat消息的輸出格式 。 支持的格式見 [此文](https://github.com/appium/appium-adb/blob/master/lib/logcat.js). 詳見更多[logcat#outputFormat](https://developer.android.com/studio/command-line/logcat#outputFormat)。默認值為`threadtime`. | 例如 `process`|
|`logcatFilterSpecs`| 自Appium 1.18.0,為logcat消息設置輸出過濾規則。詳見更多[logcat#filteringOutput](https://developer.android.com/studio/command-line/logcat#filteringOutput)。 [使用Logcat編寫和查看日志](https://developer.android.com/studio/debug/am-logcat) | 例如 `['*:W', 'MyActivity:D']` (`MyActivity` is a tag)|
#### UIAutomator (1 & 2)
這些參數在UIA 1 and 2中使用
|鍵|描述|值|
|----|-----------|-------|
|`intentAction`| 用于啟動 activity 的 intent action。(默認值為 `android.intent.action.MAIN`)| 例如 `android.intent.action.MAIN`, `android.intent.action.VIEW`|
|`intentCategory`| 用于啟動 activity 的 intent category。(默認值為 `android.intent.category.LAUNCHER`)| 例如 `android.intent.category.LAUNCHER`, `android.intent.category.APP_CONTACTS` |
|`intentFlags`| 用于啟動 activity 的標識(flags)。(默認值為 `0x10200000`)| 例如 `0x10200000` |
|`optionalIntentArguments`| 用于啟動 activity 的額外 intent 參數。請查看 [Intent 參數](http://developer.android.com/reference/android/content/Intent.html) | 例如 `--esn <EXTRA_KEY>`, `--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>`, 等等。|
#### UIAutomator2 獨有
這些參數僅在[UiAutomator2 Driver](../drivers/android-uiautomator2.md)上可用
|鍵|描述|值|
|----|-----------|-------|
|`appWaitForLaunch`| 嘗試在會話創建中不帶[-W](https://developer.android.com/studio/command-line/adb#am)選項的啟動被測應用 。當由于`shell am start` 不響應而導致會話無法進行時,這可能會有所幫助。默認值為 `true`. | `false` 或 `true` |
|`disableSuppressAccessibilityService`| 設置 [FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES](https://developer.android.com/reference/android/app/UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES)允許現有的可訪問性服務繼續運行,并為Appium啟動一個新服務。它有助于測試具有可訪問性功能(例如話語提示)的被測應用。 如果未提供任何內容,則Appium將不會指定該標志。 該標志要求使用Android API Level 24+。| `false` 或 `true` |
|`mjpegServerPort`| 如果指定,這是本地端口,將綁定到`appium-uiautomator2-server`的MJPEG屏幕截圖流。 可以與 `mjpegScreenshotUrl`一起使用。 `Integer` 默認值為 `null`。| 任何 `Integer`, 建議: `9200` -> `9299` 以和 w/ `serverPort` 范圍的一致性 |
|`skipServerInstallation`| 跳過uiAutomator2服務器的安裝,并從設備使用uiAutomator2服務器。 當設備上已安裝正確版本的uiAutomator2服務器時,可用于提高啟動性能。 默認值為 `false`. | `false` 或 `true` |
|`uiautomator2ServerInstallTimeout`| 等待uiAutomator2服務器安裝的超時時間(以毫秒為單位)。 默認值為 `20000` |例如 `20000`|
|`uiautomator2ServerLaunchTimeout`| 等待uiAutomator2服務器啟動的超時時間(以毫秒為單位)。 默認值為 `20000` |例如 `20000`|
|`userProfile`| 如果提供了值,則將用戶配置文件強制為給定參數。 它應該是一個整數。 | 例如 `11` |
#### Espresso 獨有
這些參數僅在[Espresso Driver](../drivers/android-espresso.md)上可用
|鍵|描述|值|
|----|-----------|-------|
|`espressoServerLaunchTimeout`|等待Espresso服務器啟動的超時時間(以毫秒為單位)。默認值為 `30000` |例如 `50000`|
|`espressoBuildConfig`|Espresso服務器構建配置JSON的路徑。(見下文)|例如 `/projects/myapp-tests/buildconfig.json`|
|`showGradleLog`|是否將Espresso服務器的Gradle構建日志通過管道傳輸到Appium日志。默認值為 `false`|例如 `true`|
|`skipServerInstallation`|跳過Espresso服務器構建和APK安裝。此選項可能會破壞特定Appium版本的正確Espresso服務器設置,但是當設備上已經安裝了正確的Espresso服務器和正確的被測試應用程序時,它可以提高啟動性能。 如果Espresso服務器或被測應用程序需要更新,請確保不要啟用此選項。 默認值為 `false` | `true` 或 `false`|
|`intentOptions`|Intent options 將用于啟動被測應用程序。 例如JSON格式的 `action`, `categories` and `component`。 參見例子[#538](https://github.com/appium/appium-espresso-driver/issues/538)。 |例如 `{"action": "android.intent.action.MAIN", "categories": "android.intent.category.LAUNCHER", "component": "com.appium/.launcher.MainActivity"` |
|`disableSuppressAccessibilityService`| 設置[FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES](https://developer.android.com/reference/android/app/UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES) 允許現有的可訪問性服務繼續運行,并為Appium啟動一個新服務。它有助于測試具有可訪問性功能(例如話語提示)的被測應用。 如果未提供任何內容,則Appium將不會指定該標志。該標志要求使用Android API Level 24+。 | `true`, `false` |
|`appLocale`| 自 Appium 1.18.0,設置 [地點](https://developer.android.com/reference/java/util/Locale) 為[目的上下文](https://developer.android.com/reference/androidx/test/core/app/ApplicationProvider#getApplicationContext()) 。 `language`, `country` 和 `variant` 和locale類用法相同。 `language` 是強制的。 詳見 [locale](https://developer.android.com/reference/java/util/Locale)。設置`appLocale`僅會影響被測應用程序的語言環境,而不會影響其他系統視圖,例如狀態欄。 如果您想更改整個系統的語言環境,請設置 `language`, `locale` 且/或 `localeScript` 參數 | 例如 `{"language": "ja", "country": "JP"}` |
##### Espresso服務器構建配置JSON
通過使用`espressoBuildConfig`所需的參數傳遞這個配置文件,可以調整Espresso服務器的構建過程。它在默認的Espresso服務器設置與您的測試應用程序不兼容的情況下非常有用。
這種情況的一個例子是由于 `Resource <name> is not a Drawable` 錯誤。 (見 https://github.com/appium/appium-espresso-driver/issues/449)。
配置例子:
```json
{
"toolsVersions": {
"gradle": "5.1.1",
"androidGradlePlugin": "3.4.2",
"compileSdk": 28,
"buildTools": "28.0.3",
"minSdk": 18,
"targetSdk": 28,
"kotlin": "1.3.31"
},
"additionalAppDependencies": [
"com.google.android.material:material:1.0.0"
]
}
```
***Version settings***
`toolsVersion` 指定在Espresso服務器構建過程中使用的各種工具和SDK的版本。 默認版本是用于在沒有構建配置JSON的情況下構建Espresso driver的版本。
在`toolsVersion`下枚舉的模塊版本僅用于構建服務器APK。它們不會影響被測應用程序的清單或Espresso服務器清單(仍從被測應用程序的清單生成)。
|鍵|描述|值|
|----|-----------|-------|
|`gradle`|Gradle版本|例如`5.1.1`|
|`androidGradlePlugin`|Android Gradle Plugin 版本|例如 `3.4.2`|
|`buildTools`|編譯Espresso服務器的Android SDK構建工具版本(對應于Gradle構建文件中的`buildToolsVersion`)|例如 `28.0.3`|
|`compileSdk`|用于編譯Espresso服務器的Android API級別 (對應于Gradle構建文件中的`compileSdkVersion`)|例如 `28`|
|`minSdk`|運行測試下的應用程序所需的最低Android API級別,影響用于構建Espresso服務器的兼容性庫。(對應于Gradle構建文件中的`minSdk`)|例如 `18`|
|`targetSdk`|用于測試應用程序的Android API級別(對應于Gradle構建文件中的`targetSdk`)|例如 `28`|
|`kotlin`|Kotlin編譯器和官方庫的版本|例如 `1.3.311`|
***Application dependencies***
`additionalAppDependencies` 數組指定構建工具在構建Espresso服務器時應了解的被測應用程序的其他依賴性。例如 `[ "com.google.android.material:material:1.0.0" ]`.
屬于此數組的項目在Espresso服務器的Gradle構建文件中轉換為`implementation`行。
### iOS 獨有
這些參數在[XCUITest Driver](../drivers/ios-xcuitest.md)和廢棄的[UIAutomation Driver](../drivers/ios-uiautomation.md)上可用。
|鍵|描述|值|
|----|-----------|-------|
|`calendarFormat`| (僅支持模擬器) 為iOS的模擬器設置日歷格式|例如 `gregorian`|
|`bundleId`| 被測應用的 bundle ID 。用于在真實設備中啟動測試,也用于使用其他需要 bundle ID 的關鍵字啟動測試。在使用 bundle ID 在真實設備上執行測試時,你可以不提供 `app` 關鍵字,但你必須提供 `udid` 。|例如 `io.appium.TestApp`|
|`udid`|連接的真實設備的唯一設備編號 (Unique device identifier) |例如 `1ae203187fc012g`|
|`launchTimeout`| 以毫秒為單位,在 Appium 運行失敗之前設置一個等待 instruments 的時間 |例如 `20000`|
|`locationServicesEnabled`| (僅支持模擬器)強制打開或關閉定位服務。默認值是保持當前模擬器的設定.|`true`或`false`|
|`locationServicesAuthorized`| (僅支持模擬器)通過修改 plist 文件設定是否允許應用使用定位服務,從而避免定位服務的警告出現。默認值是保持當前模擬器的設定。請注意在使用這個關鍵字時,你同時需要使用 `bundleId` 關鍵字來發送你的應用的 bundle ID。|`true`或`false`|
|`autoAcceptAlerts`| 當警告彈出的時候,都會自動去點接受。包括隱私訪問權限的警告(例如 定位,聯系人,照片)。默認值為 false。|`true`或`false`|
|`autoDismissAlerts`|當警告彈出的時候,都會自動去點取消。包括隱私訪問權限的警告(例如 定位,聯系人,照片)。默認值為 false。|`true`或`false`|
|`nativeInstrumentsLib`| 使用原生 intruments 庫(即關閉 instruments-without-delay)。|`true`或`false`|
|`nativeWebTap`| 在Safari中允許"真實的",非基于 javascript 的 web 點擊 (tap) 。 默認值:`false`。注意:取決于 viewport 大小/比例, 點擊操作不一定能精確地點中對應的元素。|`true`或`false`|
|`safariInitialUrl`|初始化 safari 的時使用的地址。默認是一個本地的歡迎頁面 | 例如 `https://www.github.com` |
|`safariAllowPopups`|(僅支持模擬器)允許 javascript 在 Safari 中創建新窗口。默認保持模擬器當前設置。|`true`或`false`|
|`safariIgnoreFraudWarning`| (僅支持模擬器)阻止 Safari 顯示此網站可能存在風險的警告。默認保持瀏覽器當前設置。|`true`或`false`|
|`safariOpenLinksInBackground`| (僅支持模擬器)Safari 是否允許鏈接在新窗口打開。默認保持瀏覽器當前設置。|`true`或`false`|
|`keepKeyChains`| (僅支持模擬器)當 Appium 會話開始/結束時是否保留存放密碼存放記錄 (keychains) 庫(Library)/鑰匙串(Keychains))|`true`或`false`|
|`localizableStringsDir`| 從哪里查找本地化字符串。默認值為 `en.lproj`|`en.lproj`|
|`processArguments`| 通過 instruments 傳遞到 AUT 的參數|例如 `-myflag`|
|`interKeyDelay`| 以毫秒為單位,按下每一個按鍵之間的延遲時間|例如 `100`|
|`showIOSLog`| 是否在 Appium 的日志中顯示設備的日志。默認值為 `false`|`true`或`false`|
|`sendKeyStrategy`| 輸入文字到文字框的策略。模擬器默認值:`oneByOne`(一個接著一個)。真實設備默認值:`grouped` (分組輸入)|`oneByOne`, `grouped`或`setValue`|
|`screenshotWaitTimeout`| 以秒為單位,生成屏幕截圖的最長等待時間。默認值為:10 |例如 `5`|
|`waitForAppScript`| 用于判斷 "應用是否被啟動” 的 iOS 自動化腳本代碼。默認情況下系統等待直到頁面內容非空。結果必須是布爾類型。 |例如 `true;`, `target.elements().length > 0;`, `$.delay(5000); true;` |
|`webviewConnectRetries`| 用于獲取 webview 失敗時,發送連接信息到遠程調試器的次數。默認次數為: `8` |例如 `12`|
|`appName`| 被測應用的名字。 用于支持 iOS 9 以上系統的應用的自動化。 |例如 `UICatalog`|
|`customSSLCert`|(僅支持模擬器) 給模擬器添加一個 SSL 證書。 | 例如 <br/>`-----BEGIN CERTIFICATE-----MIIFWjCCBEKg...`<br/>`-----END CERTIFICATE-----`|
|`webkitResponseTimeout`| (僅支持真機) 設置等待Safari會話中WebKit響應的時間(以毫秒為單位)。 默認值為 `5000`|例如 `10000`|
|`remoteDebugProxy`| (僅支持模擬器,且 <= 11.2) 如果已設置,則Appium 通過本地端口的代理(僅支持模擬器,且 <= 11.2)或者unix套接字上的代理(僅支持模擬器,且 >= 11.3)發送和接收遠程調試消息。而不是直接與iOS遠程調試器通信。|例如 `12000` 或 `"/tmp/my.proxy.socket"`|
|`enableAsyncExecuteFromHttps`| 允許模擬器使用HTTPS在頁面上執行異步JavaScript的功能。默認值為 `false` | `true` 或 `false` |
|`skipLogCapture`|跳過以開始捕獲日志,例如崩潰,系統,safari控制臺和safari網絡。它可能會改善網絡性能。與日志相關的命令將不起作用。默認值為 `false`. |`true` 或 `false`|
|`webkitDebugProxyPort`| (僅支持真機) 使用真機測試,連接`ios-webkit-debug-proxy`的端口。 默認值為 `27753`.|`12021`|
|`fullContextList` | 返回有關[獲取可用上下文](../commands/context/get-contexts.md)命令的上下文詳細信息。如果啟用了此功能,則返回的上下文列表中的每個項目還將另外包含WebView標題,完整URL和捆綁包標識符。 默認值為 `false`. | `true` 或 `false` |
### 使用 XCUITest(iOS 獨有)
[XCUITest Driver repo](https://github.com/appium/appium-xcuitest-driver#desired-capabilities)
### MacDriver 獨有
[Appium Mac Driver repo](https://github.com/appium/appium-mac-driver#desired-capabilities)
### You.i 引擎獨有
[You.i Engine driver](https://github.com/YOU-i-Labs/appium-youiengine-driver#desired-capabilities)
### WinAppDriver 獨有
[Appium Windows Driver repo](https://github.com/appium/appium-windows-driver#windowsdriver-specific-capabilities)
- 關于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 包結構
- 鳴謝