从Appium运行了解其运行原理

1、简介

        appium是c/s模式的,基于webdriver协议添加对移动设备自动化api扩展而成的,所以具有和webdriver一样的特性,比如多语言支持,webdriver是基于http协议的,第一连接会建立一个session会话,并通过post发送一个json告知服务端相关测试信息.对于Android来说,4.2以后是基于uiautomator框架实现查找注入事件的,4.2以前则是instrumentation框架的,并封装成,个叫Selendroid这玩意提供服务,客户端只需要发送http请求实现通讯,意味着客户端就是多语言支持。appium服务端是node.js写的,所以你安装的时候无论哪个平台都是先装node。

2、工作原理

2.1 Android

在Android端,appium基于WebDriver协议,利用Bootstrap.jar,最后通过调?用UiAutomator的命令,实现App的自动化测试。UiAutomator测试框架是Android SDK自带的App UI自动化测试Java库。另外由于UiAutomator对H5的支持有限,appium引入了chromedriver以及safaridriver等来实现基于H5的自动化。

appium 在android端工作流
  1. client端也就是我们 test script是我们的webdriver测试脚本。

  2. 中间是起的Appium的服务,Appium在服务端起了一个Server(4723端口),跟selenium Webdriver测试框架类似, Appium?持标准的WebDriver JSONWireProtocol。在这里提供它提供了一套REST的接口,Appium Server接收web driver client标准rest请求,解析请求内容,调?用对应的框架响应操作。

  3. appium server会把请求转发给中间件Bootstrap.jar ,它是用java写的,安装在手机上.Bootstrap监听4724端口并接收appium 的命令,最终通过调?用UiAutomator的命令来实现。

  4. 最后Bootstrap将执行的结果返回给appium server。

  5. appium server再将结果返回给 appium client。

2.2 ios

在IOS端,appium同样使?WebDriver的一套协议。

与Android端测试框架不同的是,appium ios封装了apple的 Instruments框架,主要用了Instrument里的UI Automation(Apple的?自动化测试框架),然后在设备中注?入bootstrap.js进?行监听。

appium 在ios端工作流
  1. client端 依然是 test script是我们的webdriver测试脚本。

  2. 中间是起的Appium的服务,Appium在服务端起了一个Server(4723端口),跟selenium Webdriver测试框架类似, Appium?持标准的WebDriver JSONWireProtocol。在这里提供它提供了一套REST的接口,Appium Server接收web driver client标准rest请求,解析请求内容,调?用对应的框架响应操作。

  3. appium server调用instruments.js 启动?一个socket server,同时分出一个?子进程运?instruments.app,将bootstrap.js(一个UIAutomation脚本)注?入到device?于和外界进行交互

  4. 最后Bootstrap.js将执行的结果返回给appium server

  5. appium server再将结果返回给 appium client。

所以我们可以看到android与ios区别在于appium 将请求转发到bootstrap.js或者bootstrap.jar.然后由bootstrap 驱动UIAutomation和UiAutomator去devices上完成具体的动作。

3、查看启动日志分析

Appium运行原理
appium可以理解为一个c/s架构软件,在pc端安装的appium server端,通过appium client发送操作命令到app端
;在启动时,appium会将bootstrap推送到app上,通过并在app端建立端口为4724的socket端口,接受来自Appium的
json命令,通过UIautomaticer操控app上的控件。

#关闭Appium server
> Killed Node Server.
> Appium server process ended
#启动appium server 端口号4723
> Launching Appium server with command: C:Program Files (x86)Appiumnode.exe libservermain.js –address 127.0.0.1 –port 4723 –platform-name Android –platform-version 23 –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
#Appium server的基本信息
> info: [debug] Non-default server args: {“address”:”127.0.0.1″,”logNoColors”:true,”platformName”:”Android”,”platformVersion”:”23″,”automationName”:”Appium”}
#控制台日志信息
> info: Console LogLevel: debug
#发送“期望能力”nbsp; 设备信息
> info: –> POST /wd/hub/session {“capabilities”:{“desiredCapabilities”:{“app”:”D:\workspace3\AppiumTest\src\apps\niuguwang-68.apk”,”appPackage”:”com.niuguwang.stock”,”noReset”:”True”,”noSign”:”True”,”platformVersion”:”5.1.1″,”unicodeKeyboard”:”True”,”platformName”:”Android”,”deviceName”:null,”resetKeyboard”:”True”},”requiredCapabilities”:null},”desiredCapabilities”:{“app”:”D:\workspace3\AppiumTest\src\apps\niuguwang-68.apk”,”appPackage”:”com.niuguwang.stock”,”noReset”:”True”,”noSign”:”True”,”platformVersion”:”5.1.1″,”unicodeKeyboard”:”True”,”platformName”:”Android”,”deviceName”:null,”resetKeyboard”:”True”},”requiredCapabilities”:null}

> info: Client User-Agent string: Apache-HttpClient/4.5.2 (Java/1.8.0_151)
> warn: Converting cap noReset from string to boolean. This might cause unexpected behavior.
> warn: Converting cap noSign from string to boolean. This might cause unexpected behavior.
> warn: Converting cap unicodeKeyboard from string to boolean. This might cause unexpected behavior.
> warn: Converting cap resetKeyboard from string to boolean. This might cause unexpected behavior.
#缺少appActivity desired,从apk上解析
> info: [debug] No appActivity desired capability or server param. Parsing from apk.
> info: [debug] Using local app from desired caps: D:workspace3AppiumTestsrcappsniuguwang-68.apk
#和app之间建立session
> info: [debug] Creating new appium session ce2ba35f-414a-47c8-9a01-f4ad9201883e
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_151
#使用adb工具
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from D:Androidsdkplatform-toolsadb.exe
#解析app上的权限
> info: [debug] Parsing package and activity from app manifest
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from D:Androidsdkbuild-tools23.0.3aapt.exe
> info: [debug] Extracting package and launch activity from manifest.
> info: [debug] executing cmd: D:Androidsdkbuild-tools23.0.3aapt.exe dump badging D:workspace3AppiumTestsrcappsniuguwang-68.apk
> info: [debug] badging package: com.niuguwang.stock
> info: [debug] badging act: com.niuguwang.stock.Splash
> info: [debug] Parsed package and activity are: com.niuguwang.stock/com.niuguwang.stock.Splash
> info: [debug] Using fast resetfalse
> info: [debug] Preparing device for session
> info: [debug] Checking whether app is actually present
> info: Retrieving device
> info: [debug] Trying to find a connected android device
#和设备建立连接
> info: [debug] Getting connected devices…
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device a72f32747d03
> info: [debug] Setting device id to a72f32747d03
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 wait-for-device
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “echo ‘ready'”
获取设备的api权限
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “getprop ro.build.version.sdk”
> info: [debug] Device is at API Level 23
> info: Device API level is: 23
#提取语言字符串
> info: [debug] Extracting strings for language: default
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “getprop persist.sys.language”
> info: [debug] Current device persist.sys.language:
> info: [debug] java -jar “C:Program Files (x86)Appiumnode_modulesappiumnode_modulesappium-adbjarsappium_apk_tools.jar” “stringsFromApk” “D:workspace3AppiumTestsrcappsniuguwang-68.apk” “C:UsersADMINI~1AppDataLocalTempcom.niuguwang.stock”
> info: [debug] Reading strings from converted strings.json
> info: [debug] Setting language to default
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 push “C:\Users\ADMINI~1\AppData\Local\Temp\com.niuguwang.stock\strings.json” /data/local/tmp
> info: [debug] Checking whether aapt is present
#使用aapt工具
> info: [debug] Using aapt from D:Androidsdkbuild-tools23.0.3aapt.exe
> info: [debug] Retrieving process from manifest.
> info: [debug] executing cmd: D:Androidsdkbuild-tools23.0.3aapt.exe dump xmltree D:workspace3AppiumTestsrcappsniuguwang-68.apk AndroidManifest.xml
> info: [debug] Set app process to: com.niuguwang.stock
#检查是否已经安装了app
> info: [debug] Not uninstalling app since server not started with –full-reset
> info: [debug] noSign capability set to true, skipping checking and signing of app
> info: [debug] MD5 for app is d69ebe48ac54a5b7f50dbe7048560e33
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “ls /data/local/tmp/d69ebe48ac54a5b7f50dbe7048560e33.apk”
> info: [debug] Getting install status for com.niuguwang.stock
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “getprop ro.build.version.sdk”
> info: [debug] Device is at API Level 23
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “pm list packages -3 com.niuguwang.stock”
> info: [debug] App is installed
#建立socket连接
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 forward tcp:4724 tcp:4724
#推送bootstrap到设备
> info: [debug] Pushing appium bootstrap to device…
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 push “C:\Program Files (x86)\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar” /data/local/tmp/
> info: [debug] Enabling Unicode keyboard support
> info: [debug] Pushing unicode ime to device…
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 install “C:Program Files (x86)Appiumnode_modulesappiumbuildunicode_ime_apkUnicodeIME-debug.apk”
#设置输入法
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “settings get secure default_input_method”
> info: [debug] Unsetting IME ‘com.sohu.inputmethod.sogou.xiaomi/.SogouIME’
> info: [debug] Setting IME to ‘io.appium.android.ime/.UnicodeIME’
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “ime enable io.appium.android.ime/.UnicodeIME”
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “ime set io.appium.android.ime/.UnicodeIME”
> info: [debug] Pushing settings apk to device…
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 install “C:Program Files (x86)Appiumnode_modulesappiumbuildsettings_apksettings_apk-debug.apk”
> info: [debug] Pushing unlock helper app to device…
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 install “C:Program Files (x86)Appiumnode_modulesappiumbuildunlock_apkunlock_apk-debug.apk”
#启动app
> info: Starting App
> info: [debug] Attempting to kill all ‘uiautomator’ processes
> info: [debug] Getting all processes with ‘uiautomator’
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “ps ‘uiautomator'”
> info: [debug] No matching processes found
#运行bootstrap
> info: [debug] Running bootstrap
> info: [debug] spawning: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.niuguwang.stock -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
#建立socket连接
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
> info: [debug] [BOOTSTRAP] [debug] Loading json…
> info: [debug] [BOOTSTRAP] [debug] json loading complete.
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] Waking up device if it’s not alive
> info: [debug] Pushing command to appium work queue: [“wake”,{}]
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “dumpsys window”
> 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: {“status”:0,”value”:true}
> info: [debug] Screen already unlocked, continuing.
> info: [debug] Pushing command to appium work queue: [“getDataDir”,{}]
> info: [debug] dataDir set to: /data/local/tmp
> info: [debug] Pushing command to appium work queue: [“compressedLayoutHierarchy”,{“compressLayout”:false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:”action”,”action”:”getDataDir”,”params”:{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
> info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,”value”:”/data/local/tmp”}
> 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] Getting device API level
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “getprop ro.build.version.sdk”
> info: [debug] [BOOTSTRAP] [debug] Returning result: {“status”:0,”value”:false}
> info: [debug] Device is at API Level 23
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.niuguwang.stock/com.niuguwang.stock.Splash”
> info: [debug] Waiting for pkg “com.niuguwang.stock” and activity “com.niuguwang.stock.Splash” to be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “dumpsys window windows”
> info: [debug] executing cmd: D:Androidsdkplatform-toolsadb.exe -s a72f32747d03 shell “getprop ro.build.version.release”
> info: [debug] Device is at release version 6.0.1
#启动完成
> info: [debug] Device launched! Ready for commands
#设置app端请求超时的时间
> info: [debug] Setting command timeout to the default of 60 secs
#建立session
> info: [debug] Appium session started with sessionId ce2ba35f-414a-47c8-9a01-f4ad9201883e
> info: > info: –> GET /wd/hub/session/ce2ba35f-414a-47c8-9a01-f4ad9201883e {}
> info: [debug] Responding to client with success: {“status”:0,”value”:{“platform”:”LINUX”,”browserName”:”Android”,”platformVersion”:”6.0.1″,”webStorageEnabled”:false,”takesScreenshot”:true,”javascriptEnabled”:true,”databaseEnabled”:false,”networkConnectionEnabled”:true,”locationContextEnabled”:false,”warnings”:{},”desired”:{“app”:”D:\workspace3\AppiumTest\src\apps\niuguwang-68.apk”,”appPackage”:”com.niuguwang.stock”,”noReset”:true,”noSign”:true,”platformVersion”:”5.1.1″,”unicodeKeyboard”:true,”platformName”:”Android”,”deviceName”:null,”resetKeyboard”:true},”app”:”D:\workspace3\AppiumTest\src\apps\niuguwang-68.apk”,”appPackage”:”com.niuguwang.stock”,”noReset”:true,”noSign”:true,”unicodeKeyboard”:true,”platformName”:”Android”,”deviceName”:”a72f32747d03″,”resetKeyboard”:true},”sessionId”:”ce2ba35f-414a-47c8-9a01-f4ad9201883e”}
> info: > info: –> POST /wd/hub/session/ce2ba35f-414a-47c8-9a01-f4ad9201883e/timeouts {“type”:”implicit”,”ms”:3000}
#设置隐式等待时间
> info: [debug] Set Android implicit wait to 3000ms
> info: [debug] Responding to client with success: {“status”:0,”value”:null,”sessionId”:”ce2ba35f-414a-47c8-9a01-f4ad9201883e”}
> info: > info: –> GET /wd/hub/session/ce2ba35f-414a-47c8-9a01-f4ad9201883e/source {}
> info: [debug] Pushing command to appium work queue: [“source”,{}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:”action”,”action”:”source”,”params”:{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: source
> info: [debug] [UIAUTOMATOR STDOUT] [APPIUM-UIAUTO] [debug] Returning result: {“status”:0,”value”:”来源:1920]”” resource-id=”””” instance=””0″”>

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年4月26日
下一篇 2018年4月26日

相关推荐