zoukankan      html  css  js  c++  java
  • 解决appium 连接真机Android 9启动报错.....shell "ps 'uiautomator'

    好久没有使用Appium了,感觉要从头开始了,正好换个电脑要重新装环境,装环境就不描述了,照着网上的资料就可以了,问题就出现在连接真机,手机是Android9,vivoZ5x,启动APP时候始终报错,提示....shell "ps 'uiautomator'。

    网上搜了很多,但是如下的解决版本亲测有效。

    在appium的安装目录,找到该目录下C:softAppium ode_modulesappium ode_modulesappium-adblib的 adb.js 文件

    1.找到这段代码:

    ADB.prototype.shell = function (cmd, cb) {
      if (cmd.indexOf('"') === -1) {
        cmd = '"' + cmd + '"';
      }
      var execCmd = 'shell ' + cmd;
      this.exec(execCmd, cb);
    };

    2.在这段代码后面加上如下:

    ADB.prototype.shell_grep = function (cmd, grep, cb) {
      if (cmd.indexOf('"') === -1) {
        cmd = '"' + cmd + '"';
      }
      var execCmd = 'shell ' + cmd + '| grep ' + grep;
      this.exec(execCmd, cb);
    };

    3.注释如下代码:

    ADB.prototype.getPIDsByName = function (name, cb) {
      logger.debug("Getting all processes with '" + name + "'");
      this.shell("ps '" + name + "'", function (err, stdout) {
        if (err) return cb(err);
        stdout = stdout.trim();
        var procs = [];
        var outlines = stdout.split(" ");
        outlines.shift();
        _.each(outlines, function (outline) {
          if (outline.indexOf(name) !== -1) {
            procs.push(outline);
          }
        });
        if (procs.length < 1) {
          logger.debug("No matching processes found");
          return cb(null, []);
        }
        var pids = [];
        _.each(procs, function (proc) {
          var match = /[^ ]+[ ]+([0-9]+)/.exec(proc);
          if (match) {
            pids.push(parseInt(match[1], 10));
          }
        });
        if (pids.length !== procs.length) {
          var msg = "Could not extract PIDs from ps output. PIDS: " +
                    JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
          return cb(new Error(msg));
        }
        cb(null, pids);
      });
    };

    4.增加下列代码:

    ADB.prototype.getPIDsByName = function (name, cb) {
      logger.debug("Getting all processes with '" + name + "'");
      this.shell_grep("ps", name, function (err, stdout) {
        if (err) {
          logger.debug("No matching processes found");
          return cb(null, []);
        }
        var pids = [];
        _.each(procs, function (proc) {
        var match = /[^ ]+[ ]+([0-9]+)/.exec(proc);
        if (match) {
        pids.push(parseInt(match[1], 10));
        }
        });
        if (pids.length !== procs.length) {
          var msg = "Could not extract PIDs from ps output. PIDS: " +
          JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs);
          return cb(new Error(msg));
        }
        cb(null, pids);
      });
    };

    5.重启APPIUM即可,Android9就可以运行了

  • 相关阅读:
    nginx 阻止ip访问
    mysql sql语句性能分析
    SWFUpload demo
    XSHELL win7 和 linux 系统之间文件互传
    基于HTTP协议的轻量级开源简单队列服务:HTTPSQS
    The following packages have been kept back
    php 错误日志记录
    TWIG 分页宏(基于 bootstrap)
    gitconfig 全局配置文件。
    简单的图片异步上传代码
  • 原文地址:https://www.cnblogs.com/zynzyf/p/12218360.html
Copyright © 2011-2022 走看看