appium (三)执行过程

 

appium界面运行过程:

1、启动一个http服务器:127.0.0.1:4723
2、根据测试代码setUp()进行初始化,在http服务器上建立一个session对象
3、开始调用adb,找到连接上的设备,设置设备id
4、等待设备准备好响应命令
5、开启logcat日志监控
6、将生成的apk属性信息文件strings.json存到了设备 /data/local/tmp目录下
7、读取apk安装情况
8、端口映射,发给appium httpserver的内容,经过httpserver后直接发给设备
 forward tcp:4724 tcp:4724
9、将AppiumBootstrap.jar包存到设备的 /data/local/tmp目录下
10、安装UnicodeIME-debug.apk到设备上
11、安装settings_apk-debug.apk到设备上
12、安装unlock_apk-debug.apk到设备上
13、 kill所有的uiautomator进程
14、运行bootstrap---uiautomator runtest ***.jar –c ……-e…..

15、在端口4724打开appium socket server 

16、加载json,唤醒客户端
17、提交command到appium 
18、启动设备,解锁屏幕,准备接收command
19、将响应结果返回给client
20、执行测试代码
21、关闭日志监控
22、关闭客户端链接
23、关闭Uiautomation
24、清理Android对象
25、清理appium session

> Launching Appium server with command: C:Program Files (x86)Appium ode.exe libservermain.js --address 127.0.0.1 --port 4723 --platform-name android --platform-version 21 --automation-name Appium --log-no-color

> info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"21","automationName":"Appium"}
> info: Console LogLevel: debug
以上是在PC端启动一个http服务:127.0.0.1:4723
> info: --> POST /wd/hub/session {"requiredCapabilities":{},"desiredCapabilities":{"platformVersion":"5.1.2","deviceName":"MI 3","platformName":"Android","appActivity":"com.moer.moerfinance.advertisement.AdvertisementActivity","appPackage":"com.moer.moerfinance"}}
> info: Client User-Agent string: Python-urllib/2.7
> info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
> info: [debug] Creating new appium session f5f2cd10-5cac-415b-9464-d54a15c8e693
根据setUp()进行初始化(desired_caps里面的参数设置信息),在http服务器上建立一个session对象
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.7.0_79
开启Android的appium服务,检查当前的java版本
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from C:Androidsdkplatform-toolsadb.exe
> warn: No app capability, can't parse package/activity
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device d643f50
开启adb,获取已经连接的设备,获取设备的id
> info: [debug] Setting device id to d643f50
设置设备的id
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 wait-for-device
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "echo 'ready'"
等待设备准备好响应命令,通过adb命令在设备上执行一个echo,验证设备是否准备好
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 18
> info: Device API level is: 18
> info: [debug] Extracting strings for language: default
> info: [debug] Apk doesn't exist locally
> info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
开启logcat日志监控
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "rm -rf /data/local/tmp/strings.json"
删除手机/data/local/tmp/strings.json文件,将生成的apk属性信息文件strings.json存放到/data/local/tmp/临时目录下
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Skipping install since we launched with a package instead of an app path
读取apk安装情况,判断是否需要安装应用,因为应用已经安装过,并没有提供应用的存放路径,所以跳过安装的步骤
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 forward tcp:4724 tcp:4724
端口映射,这个命令也是通过adb的命令实现的,具体是将发送给appium http server的命令经过端口映射直接发送给设备
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 push "C:\Program Files (x86)\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
将包AppiumBootstrap.jar存放到设备的/data/local/tmp/目录下
> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 install "C:Program Files (x86)Appium ode_modulesappiumuildsettings_apksettings_apk-debug.apk"
将settings_apk-debug.apk安装到手机设备上,这个应用是一个服务
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 install "C:Program Files (x86)Appium ode_modulesappiumuildunlock_apkunlock_apk-debug.apk"
将unlock_apk-debug.apk安装到手机设备,这个应用主要是用于解锁设备屏幕
> info: Starting App
> info: [debug] Attempting to kill all 'uiautomator' processes
将设备上的所有uiautomator进程都kill掉
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "ps 'uiautomator'"
> info: [debug] No matching processes found
查看设备上所有的uiautomator进程
> info: [debug] Running bootstrap
> info: [debug] spawning: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.moer.moerfinance -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
运行bootstrap---uiautomator runtest ***.jar –c ……-e…..
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
在端口4724打开appium socket server
> info: [debug] [BOOTSTRAP] [debug] Loading json...
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] Waking up device if it's not alive
加载json,唤醒客户端
> info: [debug] Pushing command to appium work queue: ["wake",{}]
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: wake
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
提交command到appium
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "dumpsys window"
> info: [debug] Screen already unlocked, continuing.
启动设备,解锁屏幕,准备接受命令
> info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":false,"status":0}
将执行响应结果返回给client
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 18
获取sdk的一些信息
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.moer.moerfinance/com.moer.moerfinance.advertisement.AdvertisementActivity"
> info: [debug] Waiting for pkg "com.moer.moerfinance" and activity "com.moer.moerfinance.advertisement.AdvertisementActivity" to be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "dumpsys window windows"
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "getprop ro.build.version.release"
> info: [debug] Device is at release version 4.3
> info: [debug] Device launched! Ready for commands
> info: [debug] Setting command timeout to the default of 60 secs
> info: [debug] Appium session started with sessionId f5f2cd10-5cac-415b-9464-d54a15c8e693
> info: <-- POST /wd/hub/session 303 6908.432 ms - 74 
> info: --> GET /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693 {}
> info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.3","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"5.1.2","deviceName":"MI 3","platformName":"Android","appActivity":"com.moer.moerfinance.advertisement.AdvertisementActivity","appPackage":"com.moer.moerfinance"},"deviceName":"d643f50","platformName":"Android","appActivity":"com.moer.moerfinance.advertisement.AdvertisementActivity","appPackage":"com.moer.moerfinance"},"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: <-- GET /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693 200 13.851 ms - 664 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.3","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformVersion":"5.1.2","deviceName":"MI 3","platformName":"Android","appActivity":"com.moer.moerfinance.advertisement.AdvertisementActivity","appPackage":"com.moer.moerfinance"},"deviceName":"d643f50","platformName":"Android","appActivity":"com.moer.moerfinance.advertisement.AdvertisementActivity","appPackage":"com.moer.moerfinance"},"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: --> POST /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693/appium/app/reset {"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: [debug] Resetting app mid-session
> info: [debug] Running device specific reset
> info: [debug] Running fast reset (stop and clear)
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "am force-stop com.moer.moerfinance"
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "pm clear com.moer.moerfinance"
> info: [debug] Waiting for pkg "com.moer.moerfinance" and activity "com.moer.moerfinance.advertisement.AdvertisementActivity" to not be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "dumpsys window windows"
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 18
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.moer.moerfinance/com.moer.moerfinance.advertisement.AdvertisementActivity"
> info: [debug] Waiting for pkg "com.moer.moerfinance" and activity "com.moer.moerfinance.advertisement.AdvertisementActivity" to be focused
> info: [debug] Getting focused package and activity
启动服务,准备接收执行测试用例
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "dumpsys window windows"
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: <-- POST /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693/appium/app/reset 200 2537.883 ms - 76 {"status":0,"value":null,"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: --> POST /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693/touch/perform {"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693","actions":[{"action":"press","options":{"y":800,"x":800}},{"action":"wait","options":{"ms":500}},{"action":"moveTo","options":{"y":800,"x":200}},{"action":"release","options":{}}]}
> info: [debug] Pushing command to appium work queue: ["swipe",{"startX":800,"startY":800,"endX":200,"endY":800,"steps":14}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"swipe","params":{"startX":800,"startY":800,"endX":200,"endY":800,"steps":14}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: swipe
> info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1920]
> info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1080,1920]
> info: [debug] [BOOTSTRAP] [debug] Swiping from [x=800.0, y=800.0] to [x=200.0, y=800.0] with steps: 14
执行测试用例结束
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
返回客户端执行的结果
> info: <-- POST /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693/touch/perform 200 275.518 ms - 76 {"status":0,"value":true,"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: --> DELETE /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693 {}
> info: Shutting down appium session
关闭会话服务
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: C:Androidsdkplatform-toolsadb.exe -s d643f50 shell "input keyevent 3"
回到设备HOME
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"OK, shutting down","status":0}
关闭日志监控
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 9.904
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] UiAutomator shut down normally
关闭UiAutomation
> info: [debug] Cleaning up android objects
清理Android对象
> info: [debug] Cleaning up appium session
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
> info: <-- DELETE /wd/hub/session/f5f2cd10-5cac-415b-9464-d54a15c8e693 200 704.079 ms - 76 {"status":0,"value":null,"sessionId":"f5f2cd10-5cac-415b-9464-d54a15c8e693"}
清理appium session
原文地址:https://www.cnblogs.com/jiuyigirl/p/7120808.html