Macaca ADB install 支持显示进度的实现

达峰的夏天 · 2016年05月28日 · 最后由 rickyzhan 回复于 2016年05月30日 · 2227 次阅读

前几天看见有同学发帖,ADB install 显示进度条,感觉挺有意思,顺便贴一个 Node.js 的实现。

自己试试

macaca-adb 是 Macaca 测试工具中 Android 驱动部分的核心模块。当然,一个 Node.js 模块不仅可以当做依赖模块,稍加配置就可以当做独立的工具使用,也就是说你可以单独使用 macaca-adb

# install
$ cnpm i macaca-adb -g
# print help
$ macaca-adb -h
# install test
$ macaca-adb install path/to/your/apk

效果

贴代码

const apkPath = path.resolve(args[1]);
const baseName = path.basename(apkPath);
const fullSize = fs.statSync(apkPath).size;

ADB.getDevices()
  .then(devices => {
    return devices[0];
  })
  .then(device => {
    adb.setDeviceId(device.udid);

    const timer = setInterval(() => {
      adb
        .shell(`ls -l /data/local/tmp/${baseName}`)
        .then(d => {
          d = d.match(/\s+\d+\s+/)[0].trim();
          const rate = parseInt((parseInt(d, 10) / fullSize) * 100, 10);
          print(`file trans process: ${rate}%`);

          if (rate === 100) {
            clearInterval(timer);
            print('file installing...');
          }
        });
    }, 100);

    return adb.install(apkPath);
  })
  .then(out => {
    print(`${out}${EOL}`);
  });

最后

这里简单写个 sample 说明 Node.js 开发体验上便捷,感谢 TesterHome 提供思路,欢迎使用 macaca-adb 模块或者其他 Macaca 的模块做二次开发,会有很多有意思并且提效的火花。

欢迎讨论,互相学习。

微博: http://weibo.com/xudafeng
Github: https://github.com/xudafeng

共收到 7 条回复 时间 点赞

多好的 demo .. 竟然没人回复

#1 楼 @lylyliuyu 双休日大家都不在的

这位难道就是 macaca 的作者?

支持 Macaca 越来越好```

这个貌似是 Push 的进度,Install 的进度没法弄

确实不错,赞!

8楼 已删除
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册