Appium启动session报procs is not defined

在使用Appium 1.4.13版本时,遇到在Mac 10.13环境下启动session时的ReferenceError:procs is not defined错误。问题出现在android 8及更低版本,尝试了网上提供的解决方案无效。通过检查adb.js文件发现getPIDsByName函数缺失proc的获取代码。为解决此问题,参考相关文章,将adb.js中getPIDsByName函数补充完整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境配置

python3.6
Mac 10.13
Appium 1.4.13
之前跑android 8的时候报错,按网上的方法把appium里的adb.js里的getPIDsByName替换了,但跑低版本的时候报错找不到procs

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 = /[^\t ]+[\t ]+([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);
  });
};

/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js

error: Unhandled error: ReferenceError: procs is not defined

error: Unhandled error: ReferenceError: procs is not defined
    at /Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:1050:12
    at [object Object].<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-adb/lib/adb.js:180:9)
    at ChildProcess.exithandler (child_process.js:742:7)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5) context: [POST /wd/hub/session {"capabilities":{"firstMatch":[{"platformName":"Android","appium:platformVersion":"6.0","appium:deviceName":"dddddd","appium:appPackage":"com.xxx.xxxx","appium:appActivity":"com.xxx.xxxx.Wel]

再对比原函数,少了proc的获取代码,于是把adb.js的getPIDsByName补回该段代码

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, []);
    }
    // add by salted fish start
    var procs = [];
    var outlines = stdout.split("\n");
    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, []);
    }
    //add by salted fish end
    var pids = [];
    _.each(procs, function (proc) {
    var match = /[^\t ]+[\t ]+([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);
  });
};

参考文章:
https://blog.youkuaiyun.com/aa790775800/article/details/101924242

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值