UiAutomator quit before it successfully launched

启动模拟器跑自动化用例时遇到了模拟器起来后又崩掉的情况,日志报错如图所示。

有一种可能是模拟器的存储空间太小导致安装包安不上,此时去模拟器里面删掉多余的没用的文件即可。

还有一种可能是adb.js过于老旧导致的。找到adb.js,然后增加相关内容即可。找到 adb.js 文件,我的路径是./data1/Downloads/node-v0.12.7-linux-x64/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js,具体方法如下:

1. 打开它,将下图中的 “var execCmd = 'shell ' + cmd; ”替换成 “ var execCmd = 'shell ' + cmd + '| grep ' + grep;”。

adb.js 替换前


adb.js 替换后

2. 将 ADB.prototype.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, []);

}

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);

    });

};

你可能感兴趣的:(UiAutomator quit before it successfully launched)