手机自动化测试:Appium代码之Logger

 

poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。poptest推出手机自动化测试的课程,讲解appuim的实际应用,培训全程用商业项目,   大家可以加qq群进行交流:195983133

log形式

首先我们来看一段log输出:

info: Starting App

info: [debug] Attempting to kill all 'uiautomator' processes

info: [debug] Getting all processes with 'uiautomator'

info: [debug] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"

info: [debug] No matching processes found

info: [debug] Running bootstrap

info: [debug] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -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

info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724

info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready

我将上面的log分为4种(message为消息体) 
1. log等级:message 
2. log等级:[debug] message 
3. log等级:[debug] [BOOTSTRAP] [debug] message 
4. log等级:[debug] [UIAUTOMATOR STDOUT] message

1.log等级:message

这一类log就是简单的appium服务器的log,切log等级为非debug

2.log等级:[debug] message

这一类log和上面是一样的,都是appium服务器的log,区别在于该log等级为debug,在logger.js模块中我们可以看到如下代码,下面的代码将debug等级的log,更改为info等级,然后在后面跟上[debug]的标志。

if (levels[logger.transports.console.level] === levels.debug) {

logger.debug = function (msg) { logger.info('[debug] ' + msg); };

}

3.[debug] [BOOTSTRAP] [debug] message

这一类log为手机中的socket服务器包(放在android手机端的jar包称为bootstrap)返回的输出

4.log等级:[debug] [UIAUTOMATOR STDOUT] message

这一类log为执行case输出的log,我们可以理解为adb接受的log。我们一般执行uiautomator的case时候,控制台输出的就是这类带有uiautomator标识的log。

自定义log部分

log等级

第一步我们来修改log等级。比如我们想将info级别改为warn级别,只需要将logger.js的223行左右的如下代码

if (levels[logger.transports.console.level] === levels.debug) {

logger.debug = function (msg) { logger.info('[debug] ' + msg); };

}

修改为

这里就将debug等级的修改为了warn模式的,info模式还是info模式(我之前说过,你应该知道为什么改变的是debug而不是info等级吧?)。我们来看看输出:

info: Starting App

warn: [debug] Attempting to kill all 'uiautomator' processes

warn: [debug] Getting all processes with 'uiautomator'

warn: [debug] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"

warn: [debug] No matching processes found

warn: [debug] Running bootstrap

warn: [debug] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=

warn: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1

warn: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1

warn: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724

warn: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready

我们将info改变成了warn,但是还是存在info标志的,因为上面代码的改变是建立在你调用的logger.debug,因为我们之前说过了,appium会将debug等级改为info,然后在后面加一个[debug]标志,现在我们改为warn,那么之前debug会改为warn,然后加一个[debug]标志。所以凡是warn后面必然会跟一个[debug]。

debug标识

上面的debug,会在info/warn/error标识后面加一个[debug],是不是很丑,我是觉得很丑,我们将其改变一下改成[TesterHome],还是刚才的代码:

info: Starting App

warn: [TesterHome] Attempting to kill all 'uiautomator' processes

warn: [TesterHome] Getting all processes with 'uiautomator'

warn: [TesterHome] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"

warn: [TesterHome] No matching processes found

warn: [TesterHome] Running bootstrap

warn: [TesterHome] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=

warn: [TesterHome] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1

warn: [TesterHome] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1

warn: [TesterHome] [BOOTSTRAP] [debug] Socket opened on port 4724

warn: [TesterHome] [BOOTSTRAP] [debug] Appium Socket Server Ready

ok了。

觉得UIAUTOMATOR STDOUT和BOOTSTRAP不理解?

没关系,写成中文,在devices/android/uiautomator.js文件中,找到190和203行左右的语句,将上面两个标识符修改为中文: 
修改前:

修改后:

输出为:

info: Starting App

warn: [TesterHome] Attempting to kill all 'uiautomator' processes

warn: [TesterHome] Getting all processes with 'uiautomator'

warn: [TesterHome] executing cmd: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell "ps 'uiautomator'"

warn: [TesterHome] No matching processes found

warn: [TesterHome] Running bootstrap

warn: [TesterHome] spawning: /Users/wuxian/Documents/tools/sdk/platform-tools/adb -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.example.android.apis -e disableAndroidWatchers false

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: numtests=1

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: stream=

warn: [TesterHome] [脚本输出] io.appium.android.bootstrap.Bootstrap:

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: test=testRunServer

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: class="io".appium.android.bootstrap.Bootstrap

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS: current=1

warn: [TesterHome] [脚本输出] INSTRUMENTATION_STATUS_CODE: 1

warn: [TesterHome] [设备socket服务器输出] [debug] Socket opened on port 4724

warn: [TesterHome] [设备socket服务器输出] [debug] Appium Socket Server Ready

最新文章

  1. 将Excel数据导入数据库
  2. Azure China (11) 使用Azure China Storage Public Blob
  3. 使用JSLint提高JS代码质量
  4. Access 2003 中自定义菜单栏
  5. Graph | Eulerian path
  6. python--函数式编程--9
  7. Appium小试
  8. Info
  9. [MySQL CPU]线上飙升800%,load达到12的解决过程
  10. android网络交互之DNS优化知识整理
  11. JNI 详细解释
  12. MAC下pyenv和pyenv-virtualenv插件初探
  13. STM32 FSMC使用笔记
  14. 如何利用Git生成pitch和打pitch
  15. Alpha冲刺四
  16. eclipse运行spark程序时日志颜色为黑色的解决办法
  17. C#设计模式之十外观模式(Facade Pattern)【结构型】
  18. 一次电话Java面试的问题总结(JDK8新特性、哈希冲突、HashMap原理、线程安全、Linux查询命令、Hadoop节点)
  19. Partition算法以及其应用详解上(Golang实现)
  20. linux命令之间的分号,&&, ||

热门文章

  1. 智能打印SDK---官方博客
  2. 【CNMP系列】CentOS7.0下安装Nginx服务
  3. iOS 访问URL转码
  4. 阅读Facebook POP框架 笔记(一)
  5. 配置apache
  6. Spark集群搭建_Standalone
  7. javascript作用域和闭包之我见
  8. 最近新版本的pangolin出现了点问题,我把可用的旧版本上传到了github
  9. Java XML DOM解析(xPath)
  10. asp.net mvc源码分析-Route的GetRouteData