Macaca Version:
Macaca Doctor Logs:
Operate System:
Programming Language:
查看macaca-android源代码发现,有的操作是直接通过adb操作进行的,比如截图getScreenshot,而有的是通过uiautomator-bootstramp在手机上启动服务端发送指令来实现的,请问这两者使用的规则是什么呢?哪种操作会使用adb直连进行操作?哪种操作需要走uiautomator服务端进行操作
getScreenshot截图走adb
controllers.getScreenshot = function *() {
const swapFilePath = temp.path({
prefix: `${pkg.name}-screenshot`,
suffix: '.png'
});
const remoteFile = `${this.adb.getTmpDir()}/screenshot.png`;
const cmd = `/system/bin/rm ${remoteFile}; /system/bin/screencap -p ${remoteFile}`;
yield this.adb.shell(cmd);
yield this.adb.pull(remoteFile, swapFilePath);
var base64 = null;
try {
let data = fs.readFileSync(swapFilePath);
base64 = new Buffer(data).toString('base64');
} catch (e) {
throw new errors.NoSuchWindow();
}
_.rimraf(swapFilePath);
return base64;
};
getSource获取dump先走uiautomator后走adb
controllers.getSource = function *() {
yield this.send({
cmd: 'getSource',
args: {
}
});
var tmpDir = this.adb.getTmpDir();
var xml = yield this.adb.shell(`cat ${tmpDir}/macaca-dump.xml`);
var xml_hack = yield this.adb.shell(`cat ${tmpDir}/local/tmp/macaca-dump.xml`);
return xml.length > xml_hack.length ? xml : xml_hack;
};