手机自动化测试:Appium代码之Logger
手机自动化测试: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
手机自动化测试:Appium代码之Logger的更多相关文章
- 手机自动化测试:Appium源码分析之跟踪代码分析九
手机自动化测试:Appium源码分析之跟踪代码分析九 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家 ...
- 手机自动化测试:Appium源码分析之跟踪代码分析八
手机自动化测试:Appium源码分析之跟踪代码分析八 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家 ...
- 手机自动化测试:Appium源码分析之跟踪代码分析六
手机自动化测试:Appium源码分析之跟踪代码分析六 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest推出手机自 ...
- 手机自动化测试:Appium源码分析之跟踪代码分析五
手机自动化测试:Appium源码分析之跟踪代码分析五 手机自动化测试是未来很重要的测试技术,作为一名测试人员应该熟练掌握,POPTEST举行手机自动化测试的课程,希望可以训练出优秀的手机测试开发工 ...
- 手机自动化测试:Appium源码分析之跟踪代码分析七
手机自动化测试:Appium源码分析之跟踪代码分析七 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest推出手机自 ...
- 手机自动化测试:appium源码分析之bootstrap三
手机自动化测试:appium源码分析之bootstrap三 研究bootstrap源码,我们可以通过代码的结构,可以看出来appium的扩展思路和实现方式,从中可以添加我们自己要的功能,针对app ...
- 手机自动化测试:appium源码分析之bootstrap一
手机自动化测试:appium源码分析之bootstrap一 前言: poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.popte ...
- 手机自动化测试:appium源码分析之bootstrap十六
手机自动化测试:appium源码分析之bootstrap十六 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
- 手机自动化测试:appium源码分析之bootstrap十
手机自动化测试:appium源码分析之bootstrap十 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣, ...
随机推荐
- 浅谈sql优化
问题的发现: 菜鸟D在工作的时候发现项目的sql语句很怪,例如 : select a.L_ZTBH, a.D_RQ, a.VC_BKDM, (select t.vc_name from tb ...
- [Selenium With C#学习笔记] Lesson-02 Web元素定位
使用Selenium来做自动化测试,一般的流程是:查找定位元素--->操作元素--->断言,那么第一步我们需要能够完成查找并定位元素,Selenium目前提供了8种基本定位方法,可根据实际 ...
- Mac上写C++
用惯Windows的同学可能刚开始用Mac的时候并不知道如何写C++,我刚开始在Mac上写C++的时候也遇到过这个困扰,Mac上并没有Windows上自己用习惯的Visual C++,下面我分享一下个 ...
- 关于echarts的一些基本使用demo
最近发现一个很好用的一个前端控件echarts,效果非常不错,兼容ie8+以上等主流浏览器.可以使用它制作报表,地图示意图等,可用其实现一系列强大的功能. 其基于html5 Canvas,是一个纯Ja ...
- Spring IoC介绍与Bean的使用
1. 介绍 IoC IoC-Inversion of Control,即"控制反转",它不是什么技术,而是一种设计思想.在 Java 开发中, IoC意味着将设计好的对象交给容 ...
- EFDB 基本规范&知识
public abstract class AccountRole //这是继承类型 { [Key] public int ID { get; set; } public bool isDisable ...
- 了解 : angular $filter stateful
{{ abc | myFilter }} angular.module('myStatefulFilterApp', []) .filter('decorate', ['decoration', fu ...
- c#基础语句——循环语句(for、while、foreach)
循环类型:for.while.foreach 循环四要素:初始条件-->循环条件-->循环体-->状态改变 1.for 格式: for(初始条件:循环条件:状态改变) {循环体(br ...
- 搭建windows环境下(nginx+mysql+php)开发环境
搭建windows环境下(nginx+mysql+php)开发环境 1. 所需准备应用程序包 1.1 nginx 程序包nginx-1.0.4.zip或其他版本(下载地址: http ...
- 《深入理解Java虚拟机》学习笔记之工具
善于利用工具,不仅可以加快我们分析数据,还可以快速定位和解决问题.现在我们就来看看虚拟机性能监控和故障处理工具. 在JDK的bin目录可以看到sun免费送给了我们很多小工具,这些工具虽然小巧但功能强大 ...