手机自动化测试:Appium源码分析之跟踪代码分析五

 

手机自动化测试是未来很重要的测试技术,作为一名测试人员应该熟练掌握,POPTEST举行手机自动化测试的课程,希望可以训练出优秀的手机测试开发工程师。

queue

我们先了解一下事件的集中处理方式,参考文章。从这篇文章可以知道,nodejs提供了一个Async库,该库就是用来处理事件的。里面就有这一个queue。 
在上一篇文章我们讲到了initQueue,我们这次再来看看:

Android.prototype.initQueue = function () {

this.queue = async.queue(function (task, cb) {

var action = task.action,

params = task.params;

this.cbForCurrentCmd = cb;

if (this.adb && !this.shuttingDown) {

this.uiautomator.sendAction(action, params, function (response) {

this.cbForCurrentCmd = null;

if (typeof cb === 'function') {

this.respond(response, cb);

}

}.bind(this));

} else {

this.cbForCurrentCmd = null;

var msg = "Tried to send command to non-existent Android device, " +

"maybe it shut down?";

if (this.shuttingDown) {

msg = "We're in the middle of shutting down the Android device, " +

"so your request won't be executed. Sorry!";

}

this.respond({

status: status.codes.UnknownError.code

, value: msg

}, cb);

}

}.bind(this), 1);

};

Async库中queue的定义一般如下所示:

var q = async.queue(function(task, callback) {

log(‘worker is processing task: ‘, task.name);

task.run(callback);

}, 1);

上面定义了一个工作线程为1的队列。当队列正在处理事件时,其他事件就一直等待。所以当我们使用queue的push方法时,queue会自己唤起然后执行,如果正在执行,push添加进来的事件会等到下一次执行。

uiautomator.sendAction

上面的请求,最终调用的是devices/android/uiautomator的sendAction的方法:

UiAutomator.prototype.sendAction = function (action, params, cb) {

if (typeof params === "function") {

cb = params;

params = {};

}

var extra = {action: action, params: params};

this.sendCommand('action', extra, cb);

};

然后转向sendCommand方法

uiautomator.sendCommand

UiAutomator.prototype.sendCommand = function (type, extra, cb) {

if (this.cmdCb !== null) {

logger.warn("Trying to run a command when one is already in progress. " +

"Will spin a bit and try again");

var start = Date.now();

var timeoutMs = 10000;

var intMs = 200;

var waitForCmdCbNull = function () {

if (this.cmdCb === null) {

this.sendCommand(type, extra, cb);

} else if ((Date.now() - start) < timeoutMs) {

setTimeout(waitForCmdCbNull, intMs);

} else {

cb(new Error("Never became able to push strings since a command " +

"was in process"));

}

}.bind(this);

waitForCmdCbNull();

} else if (this.socketClient) {

this.resendLastCommand = function () {

this.sendCommand(type, extra, cb);

}.bind(this);

if (typeof extra === "undefined" || extra === null) {

extra = {};

}

var cmd = {cmd: type};

cmd = _.extend(cmd, extra);

var cmdJson = JSON.stringify(cmd) + "\n";

this.cmdCb = cb;

var logCmd = cmdJson.trim();

if (logCmd.length > 1000) {

logCmd = logCmd.substr(0, 1000) + "...";

}

this.debug("Sending command to android: " + logCmd);

this.socketClient.write(cmdJson);

} else {

cb({

status: status.codes.UnknownError.code

, value: "Tried to send command to non-existent Android socket, " +

"maybe it's shutting down?"

});

}

};

最终会向设备端的socket发送一条命令,关于设备端接受命令以及如何处理,请查看我之前写的关于appium中bootstrap源码分析相关文章

手机自动化测试:Appium源码分析之跟踪代码分析五的更多相关文章

  1. 手机自动化测试:Appium源码分析之跟踪代码分析九

    手机自动化测试:Appium源码分析之跟踪代码分析九   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家 ...

  2. 手机自动化测试:Appium源码分析之跟踪代码分析八

    手机自动化测试:Appium源码分析之跟踪代码分析八   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家 ...

  3. 手机自动化测试:Appium源码分析之跟踪代码分析七

    手机自动化测试:Appium源码分析之跟踪代码分析七   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest推出手机自 ...

  4. 手机自动化测试:Appium源码分析之跟踪代码分析六

    手机自动化测试:Appium源码分析之跟踪代码分析六   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest推出手机自 ...

  5. 手机自动化测试:appium源码分析之bootstrap三

    手机自动化测试:appium源码分析之bootstrap三   研究bootstrap源码,我们可以通过代码的结构,可以看出来appium的扩展思路和实现方式,从中可以添加我们自己要的功能,针对app ...

  6. 手机自动化测试:appium源码分析之bootstrap二

    手机自动化测试:appium源码分析之bootstrap二   在bootstrap项目中的io.appium.android.bootstrap.handler包中的类都是对应的指令类, priva ...

  7. 手机自动化测试:appium源码分析之bootstrap一

    手机自动化测试:appium源码分析之bootstrap一   前言: poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.popte ...

  8. 手机自动化测试:appium源码分析之bootstrap十七

    手机自动化测试:appium源码分析之bootstrap十七   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

  9. 手机自动化测试:appium源码分析之bootstrap十六

    手机自动化测试:appium源码分析之bootstrap十六   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

随机推荐

  1. ZwQueryVirtualMemory枚举进程模块

    ZwQueryVirtualMemory算是枚举进程方法中的黑科技吧,主要是该方法可以检测出隐藏的模块(类似IceSword). 代码VS2015测试通过 再次奉上源码链接:https://githu ...

  2. 【图像浏览】FastStone Image Viewer——快速、小巧、功能强大

    FastStone Image Viewer 是一款免费(非商业用途)且小巧的看图软件. 其在在appinn.com的我最喜爱的<图片/照片浏览查看工具>调查结果中排第6名(总提名 140 ...

  3. JavaScript 基本类型值-String类型

    ▓▓▓▓▓▓ 大致介绍 String类型用于表示由零或多个16位Unicode字符组成的字符序列,即字符串.在JavaScript中没有单个的字符型,都是字符串.字符型就相当于只包含一个字符的字符串. ...

  4. Android反编译工具

    1:先安装androidfby工具 2:安装jdk并设置环境变量 3:下载一个apk数据包 4:打开反编译工具页面,点击"浏览"找到所要测试的apk包 5:反编译成功之后,会生成相 ...

  5. Nginx rewrite(重读)

    Nginx Rewrite规则相关指令  Nginx Rewrite规则相关指令有if.rewrite.set.return.break等,其中rewrite是最关键的指令.一个简单的Nginx Re ...

  6. 禁止Linux系统被 ping

    echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf sysctl -p 生效 开启ping功能: 删除 ...

  7. AR入门系列-03-在unity中将调试好的Vuforia项目导出为APK

    先设置build settings 选中Android后点击Player Settings Product Name设置安装后的Android程序的名字 Bundle Identifier 设置apk ...

  8. 关于Storm Stream grouping

    在Storm中, 开发者可以为上游spout/bolt发射出的tuples指定下游bolt的哪个/哪些task(s)来处理该tuples.这种指定在storm中叫做对stream的分组,即stream ...

  9. Javaweb之Servlet入门

    1. 什么是Servlet? Java Servlet 是运行在 Web 服务器或应用服务器上的程序:他是浏览器(HTTP客户端)请求和HTTP服务器上资源(访问数据库)之间的中间层. 2. 什么是S ...

  10. PHP命名空间的概念与使用

    命名空间在其它编程语言中其名称不尽相同,但其核心慨念都是自定义一个存储空间.避免类名重复系统无法判断该执行哪一个类或是哪一个函数. 举例说明下.我先创建test这个文件夹在其当前目录下再创建一个ind ...