Appium 在执行 appium 时,发现程序一直卡在 adb /proc/net/unix, 一直待到 adb 超时才结束

Forkey · 2020年10月29日 · 最后由 Thirty-Thirty 回复于 2020年11月02日 · 2761 次阅读

相关信息:

npm 版本: 3.9.0,
appium server 版本: 1.14.0
手机: 华为 nova7 Pro 5G
app 架构: 原生外壳 + H5

appium 参数配置信息:

desired_caps = {
    'platformName': self.platform_name,
    'platformVerion': self.device_info['platform_version'],
    'udid': self.device_info["udid"],
    "deviceName": self.device_info["udid"],
    'noReset': True,
    'appPackage': self.app_package,
    'appActivity': self.app_activity,
    "unicodeKeyboard": True,
    "reset_keyboard": True,
    'automationName': UiAutomator2,
    'chromedriverExecutable': self.chrome_driver_path,
    'chromeOptions': {'androidProcess': self.app_package},
    "systemPort": int(self.device_info["systemPort"]),
    "autoWebview": True,
    'adbExecTimeout': 200000
}

执行 pytest

def main(device_info):
    pytest.main(
        ["--device_info={}".format(device_info),
         "cases/xxxxx.py",
         "--alluredir", "./result", "-vs"])
     os.system('allure generate result/ -o report/ --clean')


if __name__ == "__main__":
    for num in range(20):
        with Pool(len(device_infos)) as pool:
            pool.map(main, device_infos)
            pool.close()
            pool.join()

APPIUM 相关日志:

[debug] [35m[ADB][39m Running 'E:\android-sdk\platform-tools\adb.exe -P 5037 -s UJKDU20611008827 shell cat /proc/net/unix'
[35m[HTTP][39m [37m<-- GET /wd/hub/session/b511eb04-9972-4a2d-b4b3-7600841a1cb8/contexts [39m[32m-[39m [90m- ms - -[39m
[35m[HTTP][39m [90m[39m
[35m[HTTP][39m [37m-->[39m [37mGET[39m [37m/wd/hub/session/b511eb04-9972-4a2d-b4b3-7600841a1cb8/contexts[39m
[35m[HTTP][39m [90m{}[39m
[debug] [35m[W3C (b511eb04)][39m Calling AppiumDriver.getContexts() with args: ["b511eb04-9972-4a2d-b4b3-7600841a1cb8"]
[debug] [35m[AndroidDriver][39m Getting a list of available webviews
[debug] [35m[ADB][39m Running 'E:\android-sdk\platform-tools\adb.exe -P 5037 -s UJKDU20611008827 shell cat /proc/net/unix'
 [debug] [35m[W3C (b511eb04)][39m Encountered internal error running command: Error executing adbExec. Original error: 'Command 'E\:\\android-sdk\\platform- 
tools\\adb.exe -P 5037 -s UJKDU20611008827 shell cat /proc/net/unix' timed out after 200000ms'. Try to increase the 200000ms adb execution timeout represented by 
 'adbExecTimeout' capability
 [debug] [35m[W3C (b511eb04)][39m Error: Command 'E\:\\android-sdk\\platform-tools\\adb.exe -P 5037 -s UJKDU20611008827 shell cat /proc/net/unix' timed out after 200000ms
[debug] [35m[W3C (b511eb04)][39m     at Timeout._onTimeout (C:\Users\zhangfuqiang\AppData\Roaming\npm\node_modules\appium\node_modules\teen_process\lib\exec.js:112:19)
[debug] [35m[W3C (b511eb04)][39m     at listOnTimeout (internal/timers.js:531:17)
[debug] [35m[W3C (b511eb04)][39m     at processTimers (internal/timers.js:475:7)
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 12 条回复 时间 点赞

有没有知道的小伙伴,麻烦解答下, 目前就提供这些信息,如若还要需要其它的麻烦说下

Forkey 回复

必现吗?手动在命令行中执行这个命令试试正常不

cmlanche 回复
  1. 不是每一次都会出现, 但是出现概率非常之高,我是并行执行测试(Pool),
  2. 手动执行( adb -P 5037 -s UJKDU20611008827 shell cat /proc/net/unix),是正常的,返回空数据

并行多少台设备?有试过换台电脑或者换台手机么?

陈恒捷 回复
  1. 之前并行 2 台设备都没问题,后面突然间出现问题,不知道是否改了什么东西
  2. 现在只有 1 台设备在跑,也会出现这个问题。 (1)有时候执行 “/proc/net/unix” 这个命令时,等了 20 秒左右会执行下去,有时候就直接报上面的错误。
  3. 换过一台 mac 跟 win 电脑没问题,如果是当前这台电脑的话,不管换什么手机都有问题。
  4. 记得在每次切换 webview 时候出现该问题。 是否跟我的 chromedriver 配置有关系呢?
  5. 个人猜想是:android sdk 的问题,但是 sdk 重新安装了好几次都不行,而且都下了最新版本的 sdk.

今天执行后,又发现出现 adb 执行超时:

[debug] [35m[W3C][39m Encountered internal error running command: Error executing adbExec. Original error: 'Command 'E\:\\android-sdk\\platform-tools\\adb.exe -P 5037 -s 186eef2a shell settings put global hidden_api_policy_pre_p_apps 1' timed out after 200000ms'. Try to increase the 200000ms adb execution timeout represented by 'adbExecTimeout' capability
[debug] [35m[W3C][39m Error: Command 'E\:\\android-sdk\\platform-tools\\adb.exe -P 5037 -s 186eef2a shell settings put global hidden_api_policy_pre_p_apps 1' timed out after 200000ms
[debug] [35m[W3C][39m     at Timeout._onTimeout (C:\Users\zhangfuqiang\AppData\Roaming\npm\node_modules\appium\node_modules\teen_process\lib\exec.js:112:19)
[debug] [35m[W3C][39m     at listOnTimeout (internal/timers.js:531:17)
[debug] [35m[W3C][39m     at processTimers (internal/timers.js:475:7)
[35m[HTTP][39m [37m<-- POST /wd/hub/session [39m[31m500[39m [90m201835 ms - 1171[39m
Forkey 回复

如果从解决方案角度,换台电脑是最简单便捷的。

如果要寻根究底,从你上面的替换法可以看出非手机端问题,应该是电脑端 adb 问题。建议基于 adb server 日志探究吧。怎么拉日志,可参考:https://www.jianshu.com/p/7fe3e3e286ba

陈恒捷 回复

很感谢,我看看

陈恒捷 回复

您好,我用 adb logcat 发现问题了。

10-30 09:10:55.069  9948  9969 E AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected!
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at android.app.UiAutomation.disconnect(UiAutomation.java:294)
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at android.app.Instrumentation.finish(Instrumentation.java:249)
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at androidx.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:358)
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at androidx.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:408)
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:397)
10-30 09:10:55.069  9948  9969 E AndroidRuntime:    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2209)
10-30 09:14:05.892 11879 11901 E AndroidRuntime: FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunner
10-30 09:14:05.892 11879 11901 E AndroidRuntime: Process: io.appium.uiautomator2.server, PID: 11879
10-30 09:14:05.892 11879 11901 E AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected!
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at android.app.UiAutomation.disconnect(UiAutomation.java:294)
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at android.app.Instrumentation.finish(Instrumentation.java:249)
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at androidx.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:358)
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at androidx.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:408)
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:397)
10-30 09:14:05.892 11879 11901 E AndroidRuntime:    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2209)

针对上面的问题,网上有两种解决方式:

  1. 每次执行都需要做:adb kill-server/start-server -- 这种方式只会降低失误,不能解决问题
  2. 重启手机, 这个也试过了,还是无法解决
Forkey 回复

建议先用方法 1 试试,看是否降低到了可以接受的水平?要彻底解决,估计得改造 adb 了。

还记得云测刚兴起时,各个大厂出来分享,都在各种吐槽 adb 稳定性差,需要各种重试或者改造。

PS:比较好奇,为啥连其他电脑没问题?Logcat 是获取手机端日志的,这么看问题在手机端,那不应该换了电脑就没问题呀。

Forkey #11 · 2020年11月02日 Author
陈恒捷 回复
  1. 可能换了别的电脑时,有重启手机跟 kill-server 过。
  2. 换了不同电脑,每次都要重新安装 UiAutomation server 跟 UiAutomation server test

我先用别的电脑吧,后面有解决方案了再回来评论下。

Forkey 回复

等你的解决方案,希望你成功,点赞你这种发帖有始有终的精神。👍

需要 登录 後方可回應,如果你還沒有帳號按這裡 注册