目录
1、remote
appium连接手机是通过remote进行的,代码格式如下:
例:打开OPPO手机中自带的计算器
#coding=utf-8
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'device'
desired_caps['appPackage'] = 'com.coloros.calculator'
desired_caps['appActivity'] = 'com.android.calculator2.Calculator'
desired_caps['noReset'] = True
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
3、通用功能
Appium支持很多很多功能。功能也因驱动程序而异,尽管大多数驱动程序都关注一套标准。以下是一系列表格,概述了一般和特定驱动程序所需的各种功能。
General Capabilities
These Capabilities span multiple drivers.
| Capability | Description | Values |
|---|---|---|
automationName |
Which automation engine to use | Appium (default), or UiAutomator2, Espresso, or UiAutomator1 for Android, or XCUITest or Instruments 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 or xctrace with xcrun xctrace list devices (since Xcode 12). 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. 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). UiAutomator2 and XCUITest allow to start the session without app or appPackage. Incompatible with browserName. See here about .apks file. |
/abs/path/to/my.apk or http://myapp.com/app.ipa |
otherApps |
App or list of apps (as a JSON array) to install prior to running tests. Note that it will not work with automationName of Espresso and iOS real devices |
e.g., "/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 |
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 (XCUITest driver only) and Android. | e.g. fr |
locale |
Locale to set for iOS (XCUITest driver only) and Android. 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 |
clearSystemFiles |
Delete any generated files at the end of a session. Default to false. |
true, false |
Update settings
| Capability | Description | Values |
|---|---|---|
settings[settingsKey] |
Update Appium Settings on session creation. | e.g., 'settings[mjpegScalingFactor]': 10, 'settings[shouldUseCompactResponses]': true |
4、安卓手机功能
以下是针对安卓手机系统适用的参数项
Android
UIAutomator1
These Capabilities are available for UiAutomator1 driver. The driver is for Android 5 and lower.
| Capability | Description | Values |
|---|---|---|
appActivity |
Activity name for the Android activity you want to launch from your package. This often needs to be preceded by a . (e.g., .MainActivity instead of MainActivity). By default this capability is received from the package manifest (action: android.intent.action.MAIN , category: android.int |

本文介绍了如何使用Appium通过remote连接安卓和iOS手机进行自动化测试。内容涵盖连接OPPO手机的基本代码示例,以及Appium的通用功能,如设置更新。此外,还详细列举了针对安卓的UIAutomator1、UIAutomator2和Espresso驱动器的特定功能,以及iOS独有的XCUITest和UIAutomation驱动器的能力。
最低0.47元/天 解锁文章
4671

被折叠的 条评论
为什么被折叠?



