gpt4 book ai didi

java - Appium 解锁在某些设备上不起作用 [Android]

转载 作者:太空宇宙 更新时间:2023-11-04 12:33:11 25 4
gpt4 key购买 nike

我在 Android 上遇到 Appium 解锁问题。它适用于 50% 的设备。它尝试解锁但未成功。

我的能力:

  DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(APP, APP_PATH_LOCAL); //TODO LOCAL
// capabilities.setCapability(APP, APP_PATH_REMOTE); //TODO REMOTE
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, F_APP_PACKAGE);
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, F_APP_ACTIVITY);
capabilities.setCapability(DEVICE_NAME, deviceName);
capabilities.setCapability(UDID, id);
capabilities.setCapability(NEW_COMMAND_TIMEOUT, 20);
capabilities.setCapability(PLATFORM_NAME, "ANDROID");
androidDriver = new AndroidDriver(new URL(LOCAL), capabilities); //TODO LOCAL
// androidDriver = new AndroidDriver(new URL(REMOTE), capabilities); //TODO REMOTE

TestNG 日志:

org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。原始错误:屏幕未成功解锁,正在重试(警告:服务器未提供任何堆栈跟踪信息)

Appium 日志:

[AndroidDriver] Starting Android session
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","wait-for-device"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","echo","ping"]
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","install","/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/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 /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","install","/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/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 /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","getprop","ro.build.version.release"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[AndroidDriver] Unlocking screen
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","getprop","ro.build.version.sdk"]
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Screen is locked, trying to unlock
[debug] [ADB] Device API level: 21
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","am","start","-n","io.appium.unlock/.Unlock","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running /home/igor/Android/Sdk/platform-tools/adb with args: ["-P",5037,"-s","4d009d021274404b","shell","dumpsys","window"]
[debug] [AndroidDriver] Shutting down Android driver
[AndroidDriver] Cannot shut down Android driver; it has already shut down
[MJSONWP] Encountered internal error running command: Error: Screen did not unlock successfully, retrying
at Object.callee$1$0$ (lib/android-helpers.js:348:13)
at tryCatch (/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at run (/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)
at /home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:115:28
at flush (/home/igor/Node/node-v4.4.3-linux-x64/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
[HTTP] <-- POST /wd/hub/session 500 43019 ms - 181

我尝试使用以下方法从 adb 以编程方式解锁设备:

public void unlockDevice() throws Exception {
Runtime.getRuntime().exec("adb shell input keyevent 26");
}

但是什么也没做

也许可以在设置功能之前使用 androidDriver 按下电源按钮?androidDriver.pressKeyCode(26);或者可以使用 Java 从代码运行 adb 命令吗?或者还有其他东西可以解锁设备?

最佳答案

您需要开始 Activity :

adb shell am start -n io.appium.unlock/.Unlock

关于java - Appium 解锁在某些设备上不起作用 [Android],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37611058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com