appium踩坑合集

appium类似于一个代理容器,方便用于APP自动化测试中,但在使用过程中的坑相对比较多,现将一些坑列举如下,持续完善中:

1、adb: failed to install D:\Program Files (x86)\Appium\node_modules\appium\build\unicode_ime_apk\UnicodeIME-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.android.ime without first uninstalling.]

使用appium在执行app自动化测试时,是会在手机上安装2个应用程序的。分别是:AppiumSettings和Unlock 

当不是第一次执行时就会报错,我们需要将其手动删除,直接在页面上删除的话实际上会漏删掉一个包,我们可以用adb命令(adb shell pm list package -3)检查下现在安装了多少个相关的包然后用adb命令(adb uninstall io.appium.unlock)将其一一卸载

当然这种每次的操作不是我们的目的,因此我们修改下appium的js文件,让其在执行时不安装上面的包。

找到appium的android.js注释掉这三行再重启appium。

 

2、Error: Command failed: C:\windows\system32\cmd.exe /s /c "D:\Android\android-sdk\platform-tools\adb.exe -s 127.0.0.1:62001 shell "ps 'uiautomator'""

在网上找到的解决方法,来自于另一大神:https://blog.csdn.net/qq_35531549/article/details/89161593

找到appium的安装目录下的adb.js文件,目录为:D:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib

找到方法ADB.prototype.shell = function (cmd, cb)如下代码:

ADB.prototype.shell = function (cmd, cb) {
  if (cmd.indexOf('"') === -1) {
    cmd = '"' + cmd + '"';
  }
  var execCmd = 'shell ' + cmd;
  this.exec(execCmd, cb);
};
在这段后面添加如下新方法代码:

ADB.prototype.shell_grep = function (cmd, grep, cb) {
  if (cmd.indexOf('"') === -1) {
    cmd = '"' + cmd + '"';
  }
  var execCmd = 'shell ' + cmd + '| grep ' + grep;
  this.exec(execCmd, cb);
};
再找到方法ADB.prototype.getPIDsByName = function (name, cb)如下代码:

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("\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, []);
    }
    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);
  });
};
将该方法注释,替换为新的方法:

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);
  });
};
重启appium后解决报错。

 

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值