【初级教程】Appium 启动应用 log 日志分析

刚开始学习 appium 时,老师给我布置了 appium 启动应用 log 分析的作业。由于工作比较忙,再者自己想先动手用 appium 写个公司的 app 的 UI 测试(目前简单的框架基本完成,在不断完善用例管理中)。写这篇文章是为了完成课堂作业,也为了让自己理清楚 appium 的运行原理。

启动 REST http 服务器,默认监听本地 4723 端口

这里可通过 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

脚本将 desiredCapabilities 参数 通过 post 请求发送到 Appium 服务器

[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.

创建一个 session id

Android Sesision 用于跟客户端通信

[BaseDriver] Session created with session id: e400eb0c-4b20-4ddf-ac87-cdab8a3e9fa6

获取 Java 版本

[AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_161

检查 adb 是否存在

通过配置的环境变量 ANDROID_HOME 去固定路径下查找

[ADB] Checking whether adb is present
[ADB] Using adb.exe from C:\Users\PigHead\AppData\Local\Android\Sdk\platform-tools\adb.exe

查找当前连接的设备,通过【adb devices】命令

[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...

查询到一个设备连接,使用这个设备并设置 udid(唯一标识符)

[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '6.0'
[ADB] Setting device id to 192.168.96.101:5555

获取设备的 Android 系统版本

[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

没有给出 APP 文件路径,将会运行软件包,先检查这个软件包是否存在,存在则继续

[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 命令

通过【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

在设备上安装 io.appium.settings,并检查是否安装

[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)

获取 Android 系统 API 版本号

[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

查看 io.appium.setting 的系统信息和 dump 信息,并授予 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] 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"]

安装 io.appium.unlock,辅助设备解锁

[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)

获取设备的 Android 系统版本、屏幕尺寸,API 版本和屏幕分别率、生产商

[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"]

建立 Appium Server 到设备上的 4724 端口转发,并开启设备上的基于 appiumbootstrap 的 socket 服务

[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"]

创建新的 AndroidDriver Session

[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

设置 Appium Driver 运行时的上下文

[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"]

获取当前的 WebView

[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 226

下面是配套学习资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!

软件测试面试小程序

被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!

涵盖以下这些面试题板块:

1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux

6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础

资料获取方式 :

你可能感兴趣的:(经验分享,自动化测试,软件测试,appium,测试工具,自动化测试,软件测试,性能测试)