Appium连接手机之Remote

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

目录

1、remote

3、通用功能

4、安卓手机功能

5、IOS手机功能


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 UiAutomator2Espresso, 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 iOSAndroid, or FirefoxOS
platformVersion Mobile OS version e.g., 7.14.4
deviceName The kind of mobile device or emulator to use iPhone SimulatoriPad SimulatoriPhone Retina 4-inchAndroid EmulatorGalaxy 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_CACA
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 truefalse
noReset Don't reset app state before this session. See here for more details truefalse
fullReset Perform a complete reset. See here for more details truefalse
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) truefalse
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. truefalse

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值