> 本文節(jié)選自霍格沃茲測(cè)試學(xué)院內(nèi)部教材
使用 Appium 進(jìn)行測(cè)試時(shí),會(huì)產(chǎn)生大量日志扰肌,一旦運(yùn)行過(guò)程中遇到報(bào)錯(cuò)构挤,可以通過(guò) Appium 服務(wù)端的日志以及客戶端的日志分析排查問(wèn)題。
Appium Server日志-開啟服務(wù)??
通過(guò)命令行的方式啟動(dòng) Appium Server榕暇,下面來(lái)分析一下啟動(dòng)日志见剩,日志第一行顯示了 Appium 版本信息和服務(wù)在本地的運(yùn)行地址杀糯。
? *? ?*? ?*? ?*? ?*?
? ? $ appium -g appium.log[Appium] Welcome to Appium v1.8.0-beta3 (REV \? 40e40975ebd3593d08c3f83de2546258f7ddf11d)[Appium] Appium REST http interface listener started \? on 0.0.0.0:4723
如果啟動(dòng) Appium 服務(wù)時(shí)添加了參數(shù),會(huì)在啟動(dòng)日志中展示苍苞,比如添加了 defaultCapabilities固翰,啟動(dòng)日志也會(huì)顯示出來(lái)狼纬。
? *? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*?
? ? Hogwarts $ appium --log-timestamp --log-no-colors --no-reset? ? ?2021-04-29 10:11:58:545 - [Appium] Welcome to Appium v1.17.02021-04-29 10:11:58:547 - [Appium] Non-default server args:2021-04-29 10:11:58:547 - [Appium]? ?logTimestamp: true2021-04-29 10:11:58:547 - [Appium]? ?logNoColors: true2021-04-29 10:11:58:547 - [Appium]? ?noReset: true2021-04-29 10:11:58:548 - [Appium] Deprecated server args:2021-04-29 10:11:58:548 - [Appium]? ?--no-reset => --default-capabilities '{"noReset":true}'2021-04-29 10:11:58:548 - [Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities:2021-04-29 10:11:58:548 - [Appium]? ?noReset: true2021-04-29 10:11:58:567 - [Appium] Appium REST http interface listener started on 0.0.0.0:4723
? * Appium 參數(shù):http://appium.io/docs/en/writing-running-appium/server-args/
? * defaultCapabilities 詳見:http://appium.io/docs/en/writing-running-appium/default-capabilities-arg/
運(yùn)行時(shí)的Session日志??
###??
###??
自動(dòng)化測(cè)試運(yùn)行起來(lái)之后,Appium Server 的日志提供了一些基本的 Session 信息骂际,特別是 desired capabilities
的配置信息疗琉。應(yīng)該時(shí)刻注意 Appium 服務(wù)是否正確接收了請(qǐng)求內(nèi)容。
###??
? *? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*?
? ? ...[debug] [BaseDriver] Creating session with W3C capabilities: {[debug] [BaseDriver]? ?"alwaysMatch": {[debug] [BaseDriver]? ? ?"platformName": "android",[debug] [BaseDriver]? ? ?"appium:appActivity": ".view.WelcomeActivityAlias",[debug] [BaseDriver]? ? ?"appium:appPackage": "com.xueqiu.android",[debug] [BaseDriver]? ? ?"appium:automationName": "UiAutomator2",[debug] [BaseDriver]? ? ?"appium:deviceName": "emulator-5554",[debug] [BaseDriver]? ? ?"appium:noReset": "true",[debug] [BaseDriver]? ? ?"appium:udid": "emulator-5554"[debug] [BaseDriver]? ?},...?
上面的日志創(chuàng)建了一個(gè) Session歉铝,設(shè)置了 Capabilities 參數(shù)盈简,以 JSON 格式告訴 AppiumServer 被測(cè)試設(shè)備的一些重要信息。
Appium GET 請(qǐng)求的日志??
###??
###??
Appium 是一個(gè) REST 服務(wù)太示,接收 HTTP 請(qǐng)求柠贤,返回結(jié)果。Appium 服務(wù)端日志用 `[HTTP] -->` 和 `[HTTP]
<--`展示了請(qǐng)求和返回的信息先匪。
? *? ?*? ?*? ?*? ?*?
? ? [HTTP] --> GET /wd/hub/status {}[debug] [MJSONWP] Calling AppiumDriver.getStatus() with args: [][debug] [MJSONWP] Responding to client with driver.getStatus()\ result: {"build":{"version":"1.8.0-beta3","revision":"30e7b45bdc5668124af33c41492aa5195fcdf64d"}}[HTTP] <-- GET /wd/hub/status 200 121 ms - 126
“-->”代表發(fā)出 HTTP 請(qǐng)求种吸,“<\--”代表響應(yīng)弃衍,中間是指令細(xì)節(jié)呀非。`[MJSONWP]` 指使用 MJSONWP(Mobile JSON Wire
Protocol 協(xié)議),調(diào)用 AppiumDriver.getStatus( )這個(gè)方法(無(wú)參)镜盯,返回給客戶端 `result` 信息岸裙,整個(gè)過(guò)程耗時(shí)
121 毫秒,傳輸了 126 個(gè)字節(jié)速缆。
通過(guò)日志進(jìn)行錯(cuò)誤排查??
###??
###??
利用日志可以非常容易的排查和定位問(wèn)題降允,問(wèn)題通常發(fā)生在 automation Session 之后,如果 Session 持續(xù)存在艺糜,錯(cuò)誤也可能發(fā)生剧董。
? *? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*? ?*?
? ? [HTTP] --> POST /wd/hub/session...[debug] [ADB] 1 device(s) connected[debug] [ADB] Running '/home/user/Android/Sdk/platform-tools//adb' \with args: ["-P",5037,"-s","ec8c4df","shell","am","force-stop",\"io.appium.unlock"][debug] [AndroidDriver] Not cleaning generated files. Add \`clearSystemFiles` capability if wanted.[MJSONWP] Encountered internal error running command: Error: \Cannot stop and clear com.company.app. Original error: Error \executing adbExec. Original error: 'Command '/home/user/Android\/Sdk/platform-tools//adb -P 5037 -s ec8c4df shell pm clear com.\company.app' exited with code 1'; Stderr: 'Error: java.lang.SecurityException:\ PID 22126 does not have permission android.permission.CLEAR_APP_USER_DATA to \ clear data of package com.company.app'; Code: '1'at Object.wrappedLogger.errorAndThrow (../../lib/logging.js:63:13)at ADB.callee$0$0$ (../../../lib/tools/adb-commands.js:334:9)at tryCatch (/home/linuxbrew/.linuxbrew/lib/node_modules/appium/node_modules\/babel-runtime/regenerator/runtime.js:67:40)at GeneratorFunctionPrototype.invoke [as _invoke] (/home/linuxbrew/.\linuxbrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator\/runtime.js:315:22)....[HTTP] <-- POST /wd/hub/session 500 40811 ms - 557
Appium Driver 啟動(dòng) Session ,清理 `com.company.app` 時(shí)發(fā)生錯(cuò)誤破停。這個(gè)錯(cuò)誤讓我們知道兩件事:“Appium
正在嘗試做什么”翅楼,“哪里出錯(cuò)了”。
在這個(gè)例子中真慢,Appium 嘗試運(yùn)行 adb 命令(adb shell am force-stop)毅臊,adb 參數(shù)在錯(cuò)誤信息中也有顯示。發(fā)生了
Android 系統(tǒng)權(quán)限錯(cuò)誤黑界。此時(shí)管嬉,可以手動(dòng)運(yùn)行這個(gè) adb 命令,查看錯(cuò)誤是否可以重現(xiàn)朗鸠。如果錯(cuò)誤重現(xiàn)蚯撩,可以通過(guò)錯(cuò)誤類型定位問(wèn)題。
這個(gè)例子只是眾多錯(cuò)誤中的一個(gè)烛占,但它說(shuō)明至關(guān)重要的一點(diǎn)胎挎,當(dāng)錯(cuò)誤發(fā)生時(shí),日志可以提供更多的信息,如果沒(méi)有完整的日志信息呀癣,對(duì) Appium 排錯(cuò)難上加難美浦。
改變?nèi)罩据敵龅膮?shù)??
###??
###??
下面的參數(shù)可以改變 Appium 服務(wù)端的日志行為:
\--log-level:改變 Appium 日志顯示級(jí)別。Appium 默認(rèn)展示所有日志??
项栏,它有以下一些選項(xiàng):'info', 'info:debug', 'info:info', 'info:warn', 'info:error', ...
\--log-no-colors:關(guān)閉顏色浦辨,如果日志是彩色的,可能會(huì)出現(xiàn)奇怪的字符沼沈,比如"TODO: find the
color"流酬,你可以用這個(gè)參數(shù)關(guān)閉顏色。
\--log-timestamp:在日志前添加時(shí)間戳
展示如下:
? *? ?*? ?*? ?*?
? ? 2018-03-15 13:17:58:663 - [Appium] Welcome to Appium v1.8.0-beta3 (REV 30e7b45bdc5668124af33c41492aa5195fcdf64d)2018-03-15 13:17:58:664 - [Appium] Non-default server args:2018-03-15 13:17:58:665 - [Appium] logTimestamp: true2018-03-15 13:17:58:732 - [Appium] Appium REST http interface listener started on 0.0.0.0:4723
### Appium 執(zhí)行測(cè)試時(shí)會(huì)遇到各種問(wèn)題列另,如果大家有其他的問(wèn)題需要定位的話芽腾,可以在下方留言給我哦!
?** _?
來(lái)霍格沃茲測(cè)試開發(fā)學(xué)社页衙,學(xué)習(xí)更多軟件測(cè)試與測(cè)試開發(fā)的進(jìn)階技術(shù)摊滔,知識(shí)點(diǎn)涵蓋web自動(dòng)化測(cè)試 app自動(dòng)化測(cè)試、接口自動(dòng)化測(cè)試店乐、測(cè)試框架艰躺、性能測(cè)試、安全測(cè)試眨八、持續(xù)集成/持續(xù)交付/DevOps腺兴,測(cè)試左移、測(cè)試右移廉侧、精準(zhǔn)測(cè)試页响、測(cè)試平臺(tái)開發(fā)、測(cè)試管理等內(nèi)容段誊,課程技術(shù)涵蓋bash闰蚕、pytest、junit枕扫、selenium陪腌、appium、postman烟瞧、requests诗鸭、httprunner、jmeter参滴、jenkins强岸、docker、k8s砾赔、elk蝌箍、sonarqube青灼、jacoco、jvm-sandbox等相關(guān)技術(shù)妓盲,全面提升測(cè)試開發(fā)工程師的技術(shù)實(shí)力
視頻資料領(lǐng)仍硬Α:https://qrcode.testing-studio.com/f?from=jianshu&url=https://ceshiren.com/t/topic/15844