刚开始学习 appium 时,思寒老师已经布置了 appium 启动应用 log 分析的作业。由于工作比较忙,再者自己想先动手用 appium 写个公司的 app 的 UI 测试(目前简单的框架基本完成,在不断完善用例管理中)。写这篇文章是为了完成课堂作业,也为了让自己理清楚 appium 的运行原理。
这里可通过 ip 配置 appium server 的地址) 用于接收客户端(Test Case+Selenium/Appium Driver) 发送的 JSON 格式的 POST 请求
[Appium] Welcome to Appium v1.7.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"appActivity":"com.****.MainActivity","appPackage":"com.****.d","deviceName":"192.168.96.101:5555 ","platformName":"Android","platformVersion":"6.0","newCommandTimeout":0,"connectHardwareKeyboard":true}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":"com.****.MainActivity","appPackage":"com.****.d","deviceName":"192.168.96.101:5555 ","platformName":"Android","platformVersion":"6.0","newCommandTimeout":0,"connectHardwareKeyboard":true},null,null]
[BaseDriver] Event 'newSessionRequested' logged at 1520258266730 (21:57:46 GMT+0800 (中国标准时间))
[Appium] Creating new AndroidDriver (v1.37.0) session
[Appium] Capabilities:
[Appium] appActivity: com.****.MainActivity
[Appium] appPackage: com.****.d
[Appium] deviceName: 192.168.96.101:5555
[Appium] platformName: Android
[Appium] platformVersion: 6.0
[Appium] newCommandTimeout: 0
[Appium] connectHardwareKeyboard: true
[BaseDriver] The following capabilities were provided, but are not recognized by appium: connectHardwareKeyboard.
Android Sesision 用于跟客户端通信
[BaseDriver] Session created with session id: e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6
[AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_161
通过配置的环境变量 ANDROID_HOME 去固定路径下查找
[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '6.0'
[ADB] Setting device id to 192.168.96.101:5555
[ADB] Getting device platform version
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","getprop","ro.build.version.release"]
[ADB] Current device property 'ro.build.version.release': 6.0
[AndroidDriver] App file was not listed, instead we're going to run com.****.d directly on the device
[AndroidDriver] Checking whether package is present on the device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","pm","list","packages","com.****.d"]
通过【adb shell echo ping】来检查,设备能够正常响应打印出"ping"则认为设备正常,这里响应有个超时时间(默认是 5 秒)
[AndroidDriver] Starting Android session
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","wait-for-device"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","echo","ping"]
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'undefined' and country: 'undefined'
[Logcat] Starting logcat capture
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","pm","list","packages","io.appium.settings"]
[ADB] App is installed
[ADB] Getting package info for io.appium.settings
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","dumpsys","package","io.appium.settings"]
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from C:\Users\PigHead\AppData\Local\Android\Sdk\build-tools\27.0.3\aapt.exe
[ADB] The installed 'io.appium.settings' package does not require upgrade (5 >= 5)
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","getprop","ro.build.version.sdk"]
[ADB] Current device property 'ro.build.version.sdk': 23
[ADB] Device API level: 23
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","dumpsys","package","io.appium.settings"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","pm","dump","io.appium.settings"]
[ADB] Got the following command chunks to execute: pm,grant,io.appium.settings,android.permission.CHANGE_NETWORK_STATE,;,pm,grant,io.appium.settings,android.permission.WRITE_SETTINGS,;,pm,grant,io.appium.settings,android.permission.ACCESS_MOCK_LOCATION,;
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","pm","grant","io.appium.settings","android.permission.CHANGE_NETWORK_STATE",";","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[AndroidDriver] Pushing unlock helper app to device...
[ADB] Getting install status for io.appium.unlock
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","pm","list","packages","io.appium.unlock"]
[ADB] App is installed
[ADB] Getting package info for io.appium.unlock
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","dumpsys","package","io.appium.unlock"]
[ADB] Checking whether aapt is present
[ADB] The installed 'io.appium.unlock' package does not require upgrade (2 >= 2)
[ADB] Getting device platform version
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","getprop","ro.build.version.release"]
[ADB] Current device property 'ro.build.version.release': 6.0
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","wm","size"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","getprop","ro.product.model"]
[ADB] Current device property 'ro.product.model': Custom Phone - 6.0.0 - API 23 - 768x1280
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","getprop","ro.product.manufacturer"]
[ADB] Current device property 'ro.product.manufacturer': Genymotion
[AndroidDriver] No app sent in, not parsing package/activity
[AndroidDriver] No app capability. Assuming it is already on the device
[AndroidDriver] Running fast reset (stop and clear)
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","am","force-stop","com.****.d"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","pm","clear","com.****.d"]
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","forward","tcp:4724","tcp:4724"]
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state 'starting'
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","push","C:\\Users\\PigHead\\AppData\\Local\\Programs\\appium-desktop\\resources\\app\\node_modules\\appium\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar","/data/local/tmp/"]
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","192.168.96.101:5555","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.****.d","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[UiAutomator] Moving to state 'online'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Getting connected devices...
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Device API level: 23
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","am","start","-W","-n","com.****.d/com.****.MainActivity","-S"]
[Appium] New AndroidDriver session created successfully, session e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6 added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1520258288513 (21:58:08 GMT+0800 (中国标准时间))
[MJSONWP] Responding to client with driver.createSession() result: {"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appActivity":"com.****.MainActivity","appPackage":"com.****.d","deviceName":"192.168.96.101:5555 ","platformName":"Android","platformVersion":"6.0","newCommandTimeout":0,"connectHardwareKeyboard":true},"appActivity":"com.****.MainActivity","appPackage":"com.****.d","deviceName":"192.168.96.101:5555","platformName":"Android","platformVersion":"6.0","newCommandTimeout":0,"connectHardwareKeyboard":true,"deviceUDID":"192.168.96.101:5555","deviceScreenSize":"768x1280","deviceModel":"Custom Phone - 6.0.0 - API 23 - 768x1280","deviceManufacturer":"Genymotion"}
[HTTP] <-- POST /wd/hub/session 200 21786 ms - 887
[HTTP] --> POST /wd/hub/session/e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6/context {"name":"NATIVE_APP"}
[MJSONWP] Calling AppiumDriver.setContext() with args: ["NATIVE_APP","e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6"]
[AndroidDriver] Getting a list of available webviews
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","192.168.96.101:5555","shell","cat","/proc/net/unix"]
[AndroidDriver] Found webviews: []
[AndroidDriver] Available contexts: ["NATIVE_APP"]
[MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6/context 200 775 ms - 76
appium 服务端接收 Get 请求,解析参数并将参数通过 4724 端口发送给 AndroidBootstrap,AndroidBootstrap 发送命令到 bootstrap,bootstrap 完成操作后,结果再逐层返回
[HTTP] --> GET /wd/hub/session/e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6/source {}
[MJSONWP] Calling AppiumDriver.getPageSource() with args: ["e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"source","params":{}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"source","params":{}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: source
[AndroidBootstrap] Received command result from bootstrap
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"<\/android.widget.LinearLayout><\/android.widget.LinearLayout><\/android.widget.LinearLayout><\/android.widget.ScrollView><\/android.widget.FrameLayout><\/android.widget.LinearLayout><\/android.widget.LinearLayout><\/android.widget.FrameLayout><\/android.widget.FrameLayout><\/android.widget.FrameLayout><\/hierarchy>"}
[MJSONWP] Responding to client with driver.getPageSource() result: "
[HTTP] <-- GET /wd/hub/session/e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6/source 200 804 ms - 5979
[HTTP] --> GET /wd/hub/session/e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6/screenshot {}
[MJSONWP] Calling AppiumDriver.getScreenshot() with args: ["e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6"]
[ADB] Device API level: 23
[MJSONWP] Responding to client with driver.getScreenshot() result: "iVBORw0KGgoAAAANSUhEUgAAAwAAAAUACAYAAADwUTW0AACAAElEQVR4AezBC7idZ0Hg+//7ft9a+5qd+z07TdMmpaFNiwUppIMM4SIKPopSvD0oHS3DVJQ51DPiUc9RB6aPd2EOczxTSz3jGX0KiAjCGaBVKVJogba09pKml7RJm/tlZ9/X+r73zN5xp02btHvvrLWT+P1/v7DuqmsTkiRJkiohIkmSJKkyIpIkSZIqIyJJkiSpMiKSJEmSKiMiSZIkqTIikiRJkiojIkmSJKkyIpIkSZIqI0eSJEn6Z3me0WwWtNof/Np72Lh+Naey85n9/OGffo6HH9uF2itHkiRJ0/bqyzeyaUM/mzasYc2KJfT1drFpQz/P9cAjTzEwOMLO3ft54JGdPPDIU3zznm2c7TZt6OeZvQc5dGSIVtu4fjUv39DPqfR2dTCvpxO1X44kSZJe1Juuuow3v+5y3vyvLqevt5uXsmlDP8dshLcyaWBwmC/dfg9f+uo9fPlr93K22bShn5XLFvLM3oPoX7aw7qprE5IkSTpBX283P/rW13DN1VtZs2IxrbRz9wFuuuVWPv3FOxgYHOZM27Shn5XLFjLhO/c/yqEjQ5yOP/i197Bx/Wqe6/z+ZXR3dnAqY+MNdu0+yMjYOFN2PrOff/u//V+otXIkSZJ0gl96z9u45uqt9PV20w5rVizmN37xaj5wzdv4o5s+zyc+eStnyqYN/axctpBW2rh+NS/f0M9MdNRrrF+7nOfq7epArZcjSZKkSVe+YiO/+6s/y5oVi5kLfb3d/MYvXs01V2/llz9yM9+4extzadOGflYuW4haY+WyhZy3eillmXhi5172HjjCTKxdtYT+lUsoypIndu5l977DtEOOJEmS+PX3X801V2/lTFizYjF/8dEP8kc3fY4//sTnmQubNvSzctlC/qVas2Ixn7/p15ipB7fv5Cd+8feZiXf/6L/mp3/4+7jwvBWEEJhQlCUPP7qLmz55K5/+4h28mF949w/wY299...
[HTTP] <-- GET /wd/hub/session/e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6/screenshot 200 2266 ms - 114990