通过反馈发现目前市面上比如 vivo、oppo、小米、锤子等机型存在每次安装软件都需要用户手动确认是否需要安装的提示,这样就导致了 macaca 在每次安装的时候都需要人工确认后才能继续执行自动化流程。
macaca android 驱动升级为最新版 1.1.20
本次更新主要优化点为:输入法及解锁 unlock 不必每次都重新进行安装。
npm install macaca-android -g
解决思路相对简单
1.首先检查 app 是否安装,如果没有安装,则直接进行安装
2.如果已经安装,则获取待安装 app 的版本信息及已经安装的 app 的版本信息进行比较,版本较新则进行安装
macaca-android.js
Android.prototype.unlock = function *() {
if (!_.isExistedFile(UnlockApk.apkPath)) {
logger.warn(`unlock apk not found in: ${UnlockApk.apkPath}`);
return;
}
const isInstalled = yield this.adb.isInstalled(UnlockApk.package);
if (isInstalled) {
this.checkApkVersion(UnlockApk.apkPath,UnlockApk.package);
} else {
yield this.adb.install(UnlockApk.apkPath);
}
var isScreenLocked = yield this.adb.isScreenLocked();
if (isScreenLocked) {
yield this.adb.startApp(UnlockApk);
yield _.sleep(5000);
yield this.unlock();
}
};
Android.prototype.checkApkVersion = function *(app , pkg) {
var newVersion = yield ADB.getApkVersion(app);
var oldVersion = yield this.adb.getInstalledApkVersion(pkg);
if (newVersion > oldVersion) {
yield this.adb.install(app);
}
};
Android.prototype.setIME = function *() {
const isInstalled = yield this.adb.isInstalled(UnicodeInput.package);
if (isInstalled) {
this.checkApkVersion(UnicodeInput.apkPath,UnicodeInput.package);
} else {
yield this.adb.install(UnicodeInput.apkPath);
}
yield this.adb.setIME(`${UnicodeInput.package}/${UnicodeInput.activity}`);
};
Android.prototype.unsetIME = function *() {
yield this.adb.disableIME(`${UnicodeInput.package}/${UnicodeInput.activity}`);
};
Android.prototype.stopDevice = function *() {
yield this.unsetIME();
this.chromedriver && this.chromedriver.stop();
if (this.isVirtual && this.args.reuse === reuseStatus.noReuse) {
return ADB
.emuKill()
.catch(e => {
logger.warn(e);
});
}
return Promise.resolve();
};
https://github.com/macacajs/macaca-android/blob/master/lib/macaca-android.js
https://github.com/alibaba/macaca/issues/271
https://testerhome.com/topics/7522
欢迎有兴趣的童鞋试用并反馈问题