Appium原理解析

一、学习之前先回答几个问题:

what:Appium是一款开源框架,生态丰富,社区强大,一直在被开发者维护;支持灵活的跨平台测
试,可以在IOS、Android、 Windows、Mac设备上进行移动应用的自动化测试运行,并且能
够使用相同的API编写多个平台的测试脚本。那么,Appium底层是怎样驱动手机进行操作的?

why:了解其原理虽然是一个有点晦涩难懂的过程,但是会在以下几个方面对我们产生极大的帮助:

   1.应对面试:在大厂的面试过程中,面试官是非常喜欢询问一些原理性的知识,以测试候选人的研究能力。

   2.分析与解决问题能力:Appium 由于其架构复杂,所以在安装与使用过程中会存在一些问题,掌握原理可以更好的分析问题出 现的原因,以及完成对应的解决方案。

   3.二次开发与定制开发能力:了解原理与其设计之后,才可以根据 Appium 的设计进行插件的二次开发与定制。

   4.提升架构能力:每学习一个新的框架与其设计原理,都可以更好的帮助我们提升设计模式与架构设计能力。

when:刚开始入手即可开始了解

where:排查问题

who: 测试专家必备

how:分析日志

二、原理图:

三、Appium的设计主要分为三大模块:

1.Appium Client:将与Appium的各种交互封装为可被调用的API或工具,使用者可以通过Inspect或Java/Python/其他语言的Appium第三方库对Appium Server进行调用;

2.Appium Server:一个HTTP服务器,负责信息中转,接受到客户端的命令后,首先会解析命令,根据设备类型和平台,把命令(例如:ADB命令,自动化控制命令)转化为合适的形式,最后发送到移动终端执行。

3.End Device:执行自动化测试的移动设备

四、通讯过程分析

以Android为例,详细通讯过程如下图:

前提条件:

启动Appium Server,默认占用的端口是4723,主要作用是进行API请求的监听

Appium Client和Appium Server通信

客户端发送POST请求,要求创建driver会话,将声明的capabilities启动参数通过4723端口传递给Appium Server;

Appium Server基于capabilities中的automationName属性,重新定向到相应的驱动模块,如果automationName是uiautomator2,重定向到UIAutomator2 Driver,此时创建session会话并生成对应的sessionID。

Appium Server和End Device通信

首次通信安装3个apk

1.为了在android手机上运行应用程序,Appium需要有一定的权限来控制系统设置,所以会安装应用程序io.appium.settings,安装成功后,Appium Settings在后台运行;

2.由于使用的是UIAutomator2 Driver,所以要在Android手机上安装Driver相关的apk,即 appium-uiautomator2-server-xx.apk。

安装完成后,Appium Server的8200端口 和 Android设备端的6790端口建立映射,通过该映射的链路进行通讯。

3.appium-uiautomator2-server-debug-androidTest.apk,用于接收appium-uiautomator2-server-xx发送过来的自动化测试相关指令。

第二次及以后通信:

1.Appium Client发送操作指令给Appium Server

2.Appium Server通过appium-uiautomator2-driver发送JWP协议的请求给Android的appium-uiautomator2-server

3.appium-uiautomator2-server调用Android系统的Google UIAutomator2去执行自动化具体的操作

4.操作完成后返回结果对象AppiumResponse给appium-uiautomator2-driver,AppiumServer再返回给Client端,Client端得到最终执行操作的结果。

附上日志解析

# 电脑本地的环境检查
macdeMacBook-Pro:~ mac$ appium

[Appium] Welcome to Appium v2.2.3

[Appium] Attempting to load driver uiautomator2…

[Appium] Requiring driver at /Users/mac/.appium/node_modules/appium-uiautomator2-driver

# 启动4723服务,在电脑端

[Appium] Appium REST http interface listener started on http://0.0.0.0:4723

[Appium] You can provide the following URLs in your client code to connect to this server:

[Appium] http://127.0.0.1:4723/ (only accessible from the same host)

[Appium] http://192.168.0.100:4723/

# 发送HTTP请求,其中主要包含capabilities信息

[HTTP] → POST /session

[HTTP] {“capabilities”:{“firstMatch”:[{}],“alwaysMatch”:{“appium:appActivity”:“.launch.LaunchSplashActivity”,“appium:appPackage”:“com.tencent.wework”,“appium:automationName”:“UiAutomator2”,“appium:deviceName”:“emulator-5554”,“appium:newCommandTimeout”:“3600”,“appium:noReset”:true,“appium:platformVersion”:“6.0.1”,“platformName”:“ANDROID”}}}

# 创建Session

[AppiumDriver@84e2] Calling AppiumDriver.createSession() with args: [null,null,{“firstMatch”:[{}],“alwaysMatch”:{“appium:appActivity”:“.launch.LaunchSplashActivity”,“appium:appPackage”:“com.tencent.wework”,“appium:automationName”:“UiAutomator2”,“appium:deviceName”:“emulator-5554”,“appium:newCommandTimeout”:“3600”,“appium:noReset”:true,“appium:platformVersion”:“6.0.1”,“platformName”:“ANDROID”}}]

[AppiumDriver@84e2] Event ‘newSessionRequested’ logged at 1703670019455 (17:40:19 GMT+0800 (中国标准时间))

[Appium] Attempting to find matching driver for automationName ‘UiAutomator2’ and platformName ‘ANDROID’

[Appium] The ‘uiautomator2’ driver was installed and matched caps.

[Appium] Will require it at /Users/mac/.appium/node_modules/appium-uiautomator2-driver

[Appium] Requiring driver at /Users/mac/.appium/node_modules/appium-uiautomator2-driver

[AppiumDriver@84e2] Appium v2.2.3 creating new AndroidUiautomator2Driver (v2.35.0) session

[AppiumDriver@84e2] Checking BaseDriver versions for Appium and AndroidUiautomator2Driver

[AppiumDriver@84e2] Appium’s BaseDriver version is 9.4.3

[AppiumDriver@84e2] AndroidUiautomator2Driver’s BaseDriver version is 9.4.3

[AndroidUiautomator2Driver@d586] Creating session with W3C capabilities: {

[AndroidUiautomator2Driver@d586] “alwaysMatch”: {

[AndroidUiautomator2Driver@d586] “platformName”: “ANDROID”,

[AndroidUiautomator2Driver@d586] “appium:appActivity”: “.launch.LaunchSplashActivity”,

[AndroidUiautomator2Driver@d586] “appium:appPackage”: “com.tencent.wework”,

[AndroidUiautomator2Driver@d586] “appium:automationName”: “UiAutomator2”,

[AndroidUiautomator2Driver@d586] “appium:deviceName”: “emulator-5554”,

[AndroidUiautomator2Driver@d586] “appium:newCommandTimeout”: “3600”,

[AndroidUiautomator2Driver@d586] “appium:noReset”: true,

[AndroidUiautomator2Driver@d586] “appium:platformVersion”: “6.0.1”

[AndroidUiautomator2Driver@d586] },

[AndroidUiautomator2Driver@d586] “firstMatch”: [

[AndroidUiautomator2Driver@d586] {}

[AndroidUiautomator2Driver@d586] ]

[AndroidUiautomator2Driver@d586] }

[BaseDriver] Number capability passed in as string. Functionality may be compromised.

[AndroidUiautomator2Driver@d586] Capability ‘newCommandTimeout’ changed from string (‘3600’) to integer (3600). This may cause unexpected behavior

[AndroidUiautomator2Driver@d586 (3bb496c0)] Session created with session id: 3bb496c0-125f-4336-a999-dc73552bb1f0

[AndroidUiautomator2Driver@d586 (3bb496c0)] Starting ‘com.tencent.wework’ directly on the device

# 检查ADB 环境,以及使用ADB的过程

[ADB] Found 2 ‘build-tools’ folders under ‘/Users/mac/Library/Android/sdk’ (newest first):

[ADB] /Users/mac/Library/Android/sdk/build-tools/34.0.0

[ADB] /Users/mac/Library/Android/sdk/build-tools/27.0.3

[ADB] Using ‘adb’ from ‘/Users/mac/Library/Android/sdk/platform-tools/adb’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 start-server’

[AndroidDriver] Retrieving device list

[ADB] Trying to find connected Android devices

[ADB] Getting connected devices

[ADB] Connected devices: [{“udid”:“emulator-5554”,“state”:“device”}]

[AndroidDriver] Looking for a device with Android ‘6.0.1’

[ADB] Setting device id to emulator-5554

[ADB] Getting device platform version

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.release’

[ADB] Current device property ‘ro.build.version.release’: 6.0.1

[AndroidDriver] Using device: emulator-5554

[ADB] Using ‘adb’ from ‘/Users/mac/Library/Android/sdk/platform-tools/adb’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 start-server’

[ADB] Setting device id to emulator-5554

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk’

[ADB] Current device property ‘ro.build.version.sdk’: 23

[ADB] Device API level: 23

[AndroidDriver] No app sent in, not parsing package/activity

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 wait-for-device’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell echo ping’

# Appium 相关依赖的apk - io.appium.settings

[AndroidDriver] Pushing settings apk to device…

[ADB] Getting package info for ‘io.appium.settings’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings’

[ADB] App ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/io.appium.settings/apks/settings_apk-debug.apk’ is not installed

[ADB] Installing ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/io.appium.settings/apks/settings_apk-debug.apk’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 help’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 features’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ‘ls -t -1 /data/local/tmp/appium_cache 2>&1 || echo ERROR’’

[ADB] The current Android API does not support extended ls options. Defaulting to no-options call

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ‘ls /data/local/tmp/appium_cache 2>&1 || echo ERROR’’

[ADB] The count of applications in the cache: 6

[ADB] The application at ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/io.appium.settings/apks/settings_apk-debug.apk’ is already cached to ‘/data/local/tmp/appium_cache/7d68c635eb5a75702b971029667f8fe38c96b32c.apk’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell touch -am /data/local/tmp/appium_cache/7d68c635eb5a75702b971029667f8fe38c96b32c.apk’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm install -g /data/local/tmp/appium_cache/7d68c635eb5a75702b971029667f8fe38c96b32c.apk’

[ADB] The installation of ‘settings_apk-debug.apk’ took 708ms

[ADB] Install command stdout: pkg: /data/local/tmp/appium_cache/7d68c635eb5a75702b971029667f8fe38c96b32c.apk

[ADB] Success

[ADB] Getting IDs of all ‘io.appium.settings’ processes

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ‘pgrep --help; echo $?’’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f ([[:blank:]]|^)io.appium.settings([[:blank:]]|$)’

[AndroidDriver] Granting permissions SET_ANIMATION_SCALE,CHANGE_CONFIGURATION,ACCESS_FINE_LOCATION to ‘io.appium.settings’

[ADB] Granting permissions [“android.permission.SET_ANIMATION_SCALE”,“android.permission.CHANGE_CONFIGURATION”,“android.permission.ACCESS_FINE_LOCATION”] to ‘io.appium.settings’

[ADB] Got the following command chunks to execute: [[“pm”,“grant”,“io.appium.settings”,“android.permission.SET_ANIMATION_SCALE”,“;”,“pm”,“grant”,“io.appium.settings”,“android.permission.CHANGE_CONFIGURATION”,“;”,“pm”,“grant”,“io.appium.settings”,“android.permission.ACCESS_FINE_LOCATION”,“;”]]

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm grant io.appium.settings android.permission.SET_ANIMATION_SCALE ; pm grant io.appium.settings android.permission.CHANGE_CONFIGURATION ; pm grant io.appium.settings android.permission.ACCESS_FINE_LOCATION ;’

[ADB] Getting IDs of all ‘io.appium.settings’ processes

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f ([[:blank:]]|^)io.appium.settings([[:blank:]]|$)’

[ADB] Starting Appium Settings app

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER’

[ADB] Getting IDs of all ‘io.appium.settings’ processes

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f ([[:blank:]]|^)io.appium.settings([[:blank:]]|$)’

[Logcat] Starting logs capture with command: /Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 logcat -v threadtime

# 端口映射,从本地端口的 8200 转发到 移动端的6790端口

[AndroidUiautomator2Driver@d586 (3bb496c0)] Forwarding UiAutomator2 Server port 6790 to local port 8200

[ADB] Forwarding system: 8200 to device: 6790

# Appium 相关依赖的apk appium-uiautomator2-server-v5.12.17.apk 以及 appium-uiautomator2-server-debug-androidTest.apk

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward tcp:8200 tcp:6790’

[ADB] Checking app cert for /Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.17.apk

[ADB] Checking app cert for /Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk

[ADB] Using ‘apksigner.jar’ from ‘/Users/mac/Library/Android/sdk/build-tools/34.0.0/lib/apksigner.jar’

[ADB] Starting apksigner: /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java -Xmx1024M -Xss1m -jar /Users/mac/Library/Android/sdk/build-tools/34.0.0/lib/apksigner.jar verify --print-certs /Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk

[ADB] Starting apksigner: /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java -Xmx1024M -Xss1m -jar /Users/mac/Library/Android/sdk/build-tools/34.0.0/lib/apksigner.jar verify --print-certs /Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.17.apk

[ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US

[ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc

[ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81

[ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87

[ADB]

[ADB] sha256 hash did match for ‘appium-uiautomator2-server-debug-androidTest.apk’

[ADB] ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk’ is signed with the default certificate

[ADB] Getting install status for io.appium.uiautomator2.server.test

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm path io.appium.uiautomator2.server.test’

[ADB] ‘io.appium.uiautomator2.server.test’ is installed

[ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US

[ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc

[ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81

[ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87

[ADB]

[ADB] sha256 hash did match for ‘appium-uiautomator2-server-v5.12.17.apk’

[ADB] ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.17.apk’ is signed with the default certificate

[ADB] Getting package info for ‘io.appium.uiautomator2.server’

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server’

[ADB] The version name of the installed ‘io.appium.uiautomator2.server’ is greater or equal to the application version name (‘5.12.17’ >= ‘5.12.17’)

[AndroidUiautomator2Driver@d586 (3bb496c0)] Server packages status: [{“wasSigned”:true,“installState”:“sameVersionInstalled”,“appPath”:“/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.17.apk”,“appId”:“io.appium.uiautomator2.server”},{“wasSigned”:true,“installState”:“sameVersionInstalled”,“appPath”:“/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk”,“appId”:“io.appium.uiautomator2.server.test”}]

[AndroidUiautomator2Driver@d586 (3bb496c0)] Server packages are not going to be (re)installed

[AndroidUiautomator2Driver@d586 (3bb496c0)] Waiting up to 30000ms for services to be available

#列出含有单元测试 case 的应用

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm list instrumentation’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Instrumentation target ‘io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner’ is available

[ADB] Adding packages [“io.appium.settings”,“io.appium.uiautomator2.server”,“io.appium.uiautomator2.server.test”] to Doze whitelist

[ADB] Got the following command chunks to execute: [[“dumpsys”,“deviceidle”,“whitelist”,“+io.appium.settings”,“;”,“dumpsys”,“deviceidle”,“whitelist”,“+io.appium.uiautomator2.server”,“;”,“dumpsys”,“deviceidle”,“whitelist”,“+io.appium.uiautomator2.server.test”,“;”]]

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys deviceidle whitelist +io.appium.settings ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server ; dumpsys deviceidle whitelist +io.appium.uiautomator2.server.test ;’

[AndroidUiautomator2Driver@d586 (3bb496c0)] No app capability. Assuming it is already on the device

[AndroidUiautomator2Driver@d586 (3bb496c0)] Performing shallow cleanup of automation leftovers

[AndroidUiautomator2Driver@d586 (3bb496c0)] No obsolete sessions have been detected (socket hang up)

# 启动 UIAutomator2 server

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop io.appium.uiautomator2.server.test’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Starting UIAutomator2 server 5.12.17

[AndroidUiautomator2Driver@d586 (3bb496c0)] Using UIAutomator2 server from ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.17.apk’ and test from ‘/Users/mac/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Waiting up to 30000ms for UiAutomator2 to be online…

[ADB] Creating ADB subprocess with args: [“-P”,“5037”,“-s”,“emulator-5554”,“shell”,“am”,“instrument”,“-w”,“-e”,“disableAnalytics”,“true”,“io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner”]

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/status’ to command name ‘getStatus’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body

[AndroidUiautomator2Driver@d586 (3bb496c0)] socket hang up

[Instrumentation] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/status’ to command name ‘getStatus’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body

[AndroidUiautomator2Driver@d586 (3bb496c0)] socket hang up

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/status’ to command name ‘getStatus’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body

[AndroidUiautomator2Driver@d586 (3bb496c0)] Got response with status 200: {“sessionId”:“None”,“value”:{“message”:“UiAutomator2 Server is ready to accept commands”,“ready”:true}}

# 初始化

[AndroidUiautomator2Driver@d586 (3bb496c0)] The initialization of the instrumentation process took 2077ms

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/session’ to command name ‘createSession’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [POST /session] to [POST http://127.0.0.1:8200/session] with body: {“capabilities”:{“firstMatch”:[{“platformName”:“ANDROID”,“appActivity”:“.launch.LaunchSplashActivity”,“appPackage”:“com.tencent.wework”,“automationName”:“UiAutomator2”,“deviceName”:“emulator-5554”,“newCommandTimeout”:3600,“noReset”:true,“platformVersion”:“6.0.1”,“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“ANDROID”,“appActivity”:“.launch.LaunchSplashActivity”,“appPackage”:“com.tencent.wework”,“automationName”:“UiAutomator2”,“deviceName”:“emulator-5554”,“newCommandTimeout”:3600,“noReset”:true,“platformVersion”:“6.0.1”},“deviceUDID”:“emulator-5554”}],“alwaysMatch”:{}}}

[AndroidUiautomator2Driver@d586 (3bb496c0)] Got response with status 200: {“sessionId”:“affd4a01-da6f-433e-b4c1-d87648372186”,“value”:{“capabilities”:{“firstMatch”:[{“platformName”:“ANDROID”,“appActivity”:“.launch.LaunchSplashActivity”,“appPackage”:“com.tencent.wework”,“automationName”:“UiAutomator2”,“deviceName”:“emulator-5554”,“newCommandTimeout”:3600,“noReset”:true,“platformVersion”:“6.0.1”,“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“ANDROID”,“appActivity”:“.launch.LaunchSplashActivity”,“appPackage”:“com.tencent.wework”,“automationName”:“UiAutomator2”,“deviceName”:“emulator-5554”,“newCommandTimeout”:3600,“noReset”:true,“platformVersion”:“6.0.1”},“deviceUDID”:“emulator-5554”}],“alwaysMatch”:{}},“sessionId”:“affd4a01-da6f-433e-b4c1-d87648372186”}}

[AndroidUiautomator2Driver@d586 (3bb496c0)] Determined the downstream protocol as ‘W3C’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /appium/device/pixel_ratio] to [GET http://127.0.0.1:8200/session/affd4a01-da6f-433e-b4c1-d87648372186/appium/device/pixel_ratio] with no body

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/appium/device/system_bars’ to command name ‘getSystemBars’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /appium/device/system_bars] to [GET http://127.0.0.1:8200/session/affd4a01-da6f-433e-b4c1-d87648372186/appium/device/system_bars] with no body

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/window/current/size’ to command name ‘getWindowSize’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /window/current/size] to [GET http://127.0.0.1:8200/session/affd4a01-da6f-433e-b4c1-d87648372186/window/current/size] with no body

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [GET /appium/device/info] to [GET http://127.0.0.1:8200/session/affd4a01-da6f-433e-b4c1-d87648372186/appium/device/info] with no body

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys window’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Got response with status 200: {“sessionId”:“affd4a01-da6f-433e-b4c1-d87648372186”,“value”:2}

[AndroidUiautomator2Driver@d586 (3bb496c0)] Got response with status 200: {“sessionId”:“affd4a01-da6f-433e-b4c1-d87648372186”,“value”:{“statusBar”:48}}

[AndroidUiautomator2Driver@d586 (3bb496c0)] Got response with status 200: {“sessionId”:“affd4a01-da6f-433e-b4c1-d87648372186”,“value”:{“height”:1280,“width”:720}}

[AndroidDriver] Screen already unlocked, doing nothing

[AndroidUiautomator2Driver@d586 (3bb496c0)] Starting 'com.tencent.wework/.launch.LaunchSplashActivity and waiting for ‘com.tencent.wework/.launch.LaunchSplashActivity’

# 使用ADB启动被测apk

[ADB] Running ‘/Users/mac/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -W -n com.tencent.wework/.launch.LaunchSplashActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000’

[AppiumDriver@84e2] New AndroidUiautomator2Driver session created successfully, session 3bb496c0-125f-4336-a999-dc73552bb1f0 added to master session list

[AppiumDriver@84e2] Event ‘newSessionStarted’ logged at 1703670038613 (17:40:38 GMT+0800 (中国标准时间))

[AndroidUiautomator2Driver@d586 (3bb496c0)] Cached the protocol value ‘W3C’ for the new session 3bb496c0-125f-4336-a999-dc73552bb1f0

[AndroidUiautomator2Driver@d586 (3bb496c0)] Responding to client with driver.createSession() result: {“capabilities”:{“platformName”:“ANDROID”,“appActivity”:“.launch.LaunchSplashActivity”,“appPackage”:“com.tencent.wework”,“automationName”:“UiAutomator2”,“deviceName”:“emulator-5554”,“newCommandTimeout”:3600,“noReset”:true,“platformVersion”:“6.0.1”,“platform”:“LINUX”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“platformName”:“ANDROID”,“appActivity”:“.launch.LaunchSplashActivity”,“appPackage”:“com.tencent.wework”,“automationName”:“UiAutomator2”,“deviceName”:“emulator-5554”,“newCommandTimeout”:3600,“noReset”:true,“platformVersion”:“6.0.1”},“deviceUDID”:“emulator-5554”,“pixelRatio”:“2”,“statBarHeight”:48,“viewportRect”:{“left”:0,“top”:48,“width”:720,“height”:1232},“deviceApiLevel”:23,“deviceManufacturer”:“Netease”,“deviceModel”:“MuMu”,“deviceScreenSize”:“720x1280”,“deviceScreenDensity”:320}}

[HTTP] ← POST /session 200 19164 ms - 1001

[HTTP]

#查找元素

[HTTP] → POST /session/3bb496c0-125f-4336-a999-dc73552bb1f0/element

[HTTP] {“using”:“xpath”,“value”:“//*[@text=‘通讯录’]”}

[AndroidUiautomator2Driver@d586 (3bb496c0)] Calling AppiumDriver.findElement() with args: [“xpath”,“//*[@text=‘通讯录’]”,“3bb496c0-125f-4336-a999-dc73552bb1f0”]

[AndroidUiautomator2Driver@d586 (3bb496c0)] Valid locator strategies for this request: xpath, id, class name, accessibility id, css selector, -android uiautomator

[AndroidUiautomator2Driver@d586 (3bb496c0)] Waiting up to 3000 ms for condition

[AndroidUiautomator2Driver@d586 (3bb496c0)] Matched ‘/element’ to command name ‘findElement’

[AndroidUiautomator2Driver@d586 (3bb496c0)] Proxying [POST /element] to [POST http://127.0.0.1:8200/session/affd4a01-da6f-433e-b4c1-d87648372186/element] with body: {“strategy”:“xpath”,“selector”:“//*[@text=‘通讯录’]”,“context”:“”,“multiple”:false}