zoukankan      html  css  js  c++  java
  • 使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式

    appium1.4,运行自动化脚本时提示

    org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: "D:\Program Files\android-sdk-windows\platform-tools\adb.exe" -s GSL0217302005195 shell "ps 'uiautomator'"
    ps: uiautomator

    解决办法:

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

    1、找到这段代码:

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

    在该代码下边加上:

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

    2、找到第二段代码,注释掉该方法:

    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");
    _.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);
    });
    };

    3、保存adb.js,重启appium,可以解决

  • 相关阅读:
    linux利用yum下载rpm离线包
    Struts Spring Plugin注意点
    Spring 对没有实现接口的类使用aspect的时候,可以使用CGLIB
    Spring HibernateTemplate
    Spring 声明式事务管理
    Spring 配置dataSource和sessionFactory
    Spring 配置中的 ${}
    Srping AOP xml方式
    Spring AOP 面向切面编程相关注解
    Spring 常用注入注解(annotation)和其对应xml标签
  • 原文地址:https://www.cnblogs.com/cainiaotest/p/10271187.html
Copyright © 2011-2022 走看看