Desired Capabilities详解
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Desired Capabilities详解相关的知识,希望对你有一定的参考价值。
参考技术A Desired Capabilities在启动session的时候是必须提供的。Desired Capabilities本质上是key value的对象,它告诉appium server这样一些事情:
本次测试是启动浏览器还是启动移动设备?
是启动andorid还是启动ios?
启动android时,app的package是什么?
启动android时,app的activity是什么?
Appium的Desired Capabilities是扩展了webdriver的Desired Capabilities的,下面的一些通用配置是需要指定的:
automationName:使用哪种自动化引擎。appium(默认)还是Selendroid?
platformName:使用哪种移动平台。iOS, Android, orFirefoxOS?
deviceName:启动哪种设备,是真机还是模拟器?iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4, etc...
app:应用的绝对路径,注意一定是绝对路径。如果指定了appPackage和appActivity的话,这个属性是可以不设置的。另外这个属性和browserName属性是冲突的。
browserName:移动浏览器的名称。比如Safari' for iOS and 'Chrome', 'Chromium', or 'Browser' for Android;与app属性互斥。
udid:物理机的id。比如1ae203187fc012g。
下面这些属性是android平台特定的:
appActivity:待测试的app的Activity名字。比如MainActivity, .Settings。注意,原生app的话要在activity前加个"."。
appPackage:待测试的app的java package。比如com.example.android.myApp, com.android.settings。
本文主要讨论android平台的appium测试方法和技巧,因此在这里就不列出ios设备特定的属性了。
更多信息请参考 官方文档
在这里我们发现,我们经常要获取app的package和activity名字,那么有什么工具可以让我们方便的获取到这些信息呢?下一节讲回答这个问题。
Appium Desired Capabilities-General Capabilities
Desired Capabilities are keys and values encoded in a JSON object, sent by Appium clients to the server when a new automation sessionis requested.
They tell the Appium drivers all kinds of important things abouthow you want your test to work.
Each Appium client builds capabilities in a wayspecific to the client‘s language, but at the end of the day, they are sent over to Appium as JSON objects.
There are many, many Capabilities that Appium supports.Capabilities also differ by driver, though there are a standard set that mostdrivers pay attention to.
What follows are a series of tables outlining thevarious Desired Capabilities available in general and for specific drivers.
===========================================================
General Capabilities
These Capabilities span multiple drivers.
automationName Which automation engine to use Appium (default) or Selendroid or UiAutomator2 or Espresso for Android or XCUITest for iOS or YouiEngine for application built with You.i Engine |
||
platformName Which mobile OS platform to use iOS, Android, or FirefoxOS |
||
platformVersion Mobile OS version e.g., 7.1, 4.4 |
||
deviceName The kind of mobile device or emulator to use iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4, etc.... On iOS, this should be one of the valid devices returned by instruments with instruments -s devices. On Android this capability is currently ignored, though it remains required. |
||
app The absolute local path or remote http URL to a .ipa file (IOS), .app folder (IOS Simulator), .apk file (Android) or .apks file (Android App Bundle), or a .zip file containing one of these (for .app, the .app folder must be the root of the zip file). Appium will attempt to install this app binary on the appropriate device first. Note that this capability is not required for Android if you specify appPackage and appActivity capabilities (see below). Incompatible with browserName. See here about .apks file. /abs/path/to/my.apk or http://myapp.com/app.ipa |
||
browserName Name of mobile web browser to automate. Should be an empty string if automating an app instead. ‘Safari‘ for iOS and ‘Chrome‘, ‘Chromium‘, or ‘Browser‘ for Android |
||
newCommandTimeout How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session e.g. 60 |
||
language Language to set for iOS and Android. It is only available for simulator on iOS e.g. fr |
||
locale Locale to set for iOS and Android. It is only available for simulator on iOS. fr_CA format for iOS. CA format (country name abbreviation) for Android e.g. fr_CA, CA |
||
udid Unique device identifier of the connected physical device e.g. 1ae203187fc012g |
||
orientation (Sim/Emu-only) start in a certain orientation LANDSCAPE or PORTRAIT |
||
autoWebview Move directly into Webview context. Default false true, false |
||
noReset Don‘t reset app state before this session. See here for more details true, false |
||
fullReset Perform a complete reset. See here for more details true, false |
||
eventTimings Enable or disable the reporting of the timings for various Appium-internal events (e.g., the start and end of each command, etc.). Defaults to false. To enable, use true. The timings are then reported as events property on response to querying the current session. See the event timing docs for the the structure of this response. e.g., true |
||
enablePerformanceLogging (Web and webview only) Enable Chromedriver‘s (on Android) or Safari‘s (on iOS) performance logging (default false) true, false |
||
printPageSourceOnFindFailure When a find operation fails, print the current page source. Defaults to false. e.g., true |
以上是关于Desired Capabilities详解的主要内容,如果未能解决你的问题,请参考以下文章
Appium Desired Capabilities-General Capabilities
[Selenium+Java] Desired Capabilities in Selenium