Appium 修改 Appium 启动源码以修正在安装 appium settings 和 unlock 应用时不能自动点击弹窗的问题

bauul · 2017年03月06日 · 最后由 蓝蓝 回复于 2018年01月04日 · 2459 次阅读

缘由

最近在做 Appium 升级(从 1.4.13 到 1.6.3),升级完成后,发现在启动应用时,是先安装 AppiumSettings 和 Unlock 应用,再启动 AppiumBootstrap,
这就导致在部分机器上安装前面两个应用时,无法自动点击 “安装” 的 button。
日志如下:

[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","install","E:\\up\\autodependency\\mobile\\appium\\node_modules\\appium-android-driver\\node_modules\\io.appium.settings\\bin\\settings_apk-debug.apk"]
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","install","E:\\up\\autodependency\\mobile\\appium\\node_modules\\appium-android-driver\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk"]
[ADB] Getting device platform version
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","shell","getprop","ro.build.version.release"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[AndroidDriver] Remote apk path is /data/local/tmp/9024285e01047110b9f18f73cacee078.apk
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
......
[debug] [ADB] Forwarding system: 4724 to device: 4724
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","forward","tcp:4724","tcp:4724"]
[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","push","E:\\up\\autodependency\\mobile\\appium\\node_modules\\appium-android-driver\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar","/data/local/tmp/"]
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","562beeee","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.XXX","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]

WebStorm 修改 Appium 源码

  1. 打开以下两个文件并修改:
//更新 appium\node_modules\appium-android-driver\build\lib\android-helpers.js
case 11:
context$1$0.next = 13;
//注释下面这句,并添加return
//return _regeneratorRuntime.awrap(helpers.pushSettingsApp(adb));
return;

case 13:
context$1$0.next = 15;
//注释下面这句,并添加return
// return _regeneratorRuntime.awrap(helpers.pushUnlock(adb));
return;
 //更新 appium\node_modules\appium-android-driver\build\lib\driver.js
 case 11:
  if (!this.opts.autoLaunch) {
    context$2$0.next = 14;
    break;
  }

  context$2$0.next = 14;
  // start UiAutomator
  this.bootstrap = new _androidHelpers2['default'].bootstrap(this.adb, this.bootstrapPort, this.opts.websocket);
  return _regeneratorRuntime.awrap(this.bootstrap.start(this.opts.appPackage, this.opts.disableAndroidWatchers));

case 14:
  context$2$0.next = 15;
  return _regeneratorRuntime.awrap(this.initAUT());

case 15:
  context$2$0.next = 16;
  return _regeneratorRuntime.awrap(_androidHelpers2['default'].pushSettingsApp(this.adb));

case 16:
  context$2$0.next = 17;
  return _regeneratorRuntime.awrap(_androidHelpers2['default'].pushUnlock(this.adb));

case 17:

注意点

  1. 记得测试一下在锁屏状态下,创建 driver 并启动应用是否会自动解锁

测试检查

[debug] [UiAutomator] Starting UiAutomator
[debug] [UiAutomator] Moving to state 'starting'
[debug] [UiAutomator] Parsing uiautomator jar
[debug] [UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","push","E:\\up\\autodependency\\mobile\\appium\\node_modules\\appium-android-driver\\node_modules\\appium-android-bootstrap\\bootstrap\\bin\\AppiumBootstrap.jar","/data/local/tmp/"]
[debug] [ADB] Attempting to kill all uiautomator processes
[debug] [ADB] Getting all processes with uiautomator
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[debug] [UiAutomator] Starting UIAutomator
[debug] [ADB] Creating ADB subprocess with args: ["-P",5037,"-s","562beeee","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.suning.snmessenger","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[debug] [UiAutomator] Moving to state 'online'
[AndroidBootstrap] Android bootstrap socket is now connected
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","install","E:\\up\\autodependency\\mobile\\appium\\node_modules\\appium-android-driver\\node_modules\\io.appium.settings\\bin\\settings_apk-debug.apk"]
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Running 'E:\DevTool\Android\SDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","562beeee","install","E:\\up\\autodependency\\mobile\\appium\\node_modules\\appium-android-driver\\node_modules\\appium-unlock\\bin\\unlock_apk-debug.apk"]

感慨一下

因为没有看过 appium 的源码,这里纯粹是为了解决某个问题,强撸了代码,从开始一步一步的 debug 过来的,TMD 按 F7 按的手都麻了,才找到这个要修改的地方。
这里修改的其实是 build 后的源码,没 build 之前的,我也不知道怎么弄,望求知道的兄弟指点。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 7 条回复 时间 点赞

Appium Setting 和 Unlock 都是干嘛的, Unlock 是自动解锁的, Setting 是干嘛的呢

garylin 回复

我也不是太清楚噢,猜测是和 unlock 配合使用,解锁用的
因为我找了下,没能找到它的源代码

我这里貌似没有这两个文件。

华玺 回复

appium 都有

已解决。感谢。

driver.js 改了什么??没有看出来

记录下 appium1.7 屏蔽 appiumsetting.apk 和 unlock.apk 安装
C:\Users\admin\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-driver\build\lib 下
搜索 android-helper.js 底下两句
Pushing settings apk to device...
Pushing unlock helper app to device...
将返回的地方,直接改为 return;

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册