Appium错误收集及解决
- 错误1:selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command.
- 错误2:同一段脚本比如超级计算器,通过appium-desktop启动的Server能正常执行,但是通过 appium 命令行启动的Server,执行脚本,超级计算器已经被脚本打开了,但是接着报下面的错误
selenium.common.exceptions.InvalidSessionIdException: Message: A session is either terminated or not started
关于错误1和错误2的原因:是因为之前通过 sudo cnpm install appium@1.14.0的版本的时候有下面截图的报错,没有解决,该错误是由于权限问题导致的。
解决:彻底卸载mac上的node软件和appium,然后通过brew install node,再通过npm install -g appium@1.15.1的版本后正常了,安装过程中也没有报错,参考我的关于Mac appium 环境配置博客
MIUI 11 关闭USB安装APP安装询问的提示弹窗
大多数手机关闭USB安装提示弹窗很简单,但是小米手机很麻烦,很多人不知道怎么关闭,关闭USB安装弹窗,其实执行以下几步即可: 1. 设置->开发者选项中 -> 启动MIUI优化 ->关闭
2. 设置 -> 授权管理 -> 右上角设置按钮 -> USB安装管理 ->关闭
因为关闭了MIUI优化,有些界面,图标很难看,所以在完成第二步设置后,可以把MIUI优化再打开错误3:appium-doctor --ios 检测环境报错 Error running xcrun simctl
解决:打开xcode-偏好设置-locations,下拉选上命令行工具
- 错误4: UnhandledPromiseRejectionWarning: Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/appium/node_modules/appium-selendroid-driver/2020325-4335-fa47af.9254'
-
解决:其实按照错误1或者错误2的解决方式,以普通模式安装,不会遇到这个错误。
如果不是以普通模式安装,即使你解决了这个错误,在后续的过程中还会遇到其他类似权限的问题。因此继续强烈建议以普通模式安装并配置环境
错误5:执行脚本的时候报An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Users/qiaoersun/Library/Android/sdk/platform-tools/adb -P 5037 -s 49c08cd4 shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:2050) at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1256) at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1239) at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:476) at android.content.ContentProvider.call(ContentProvider.java:2161) at android.content.ContentProvider\(Transport.call(ContentProvider.java:477) at com.android.providers.settings.SettingsService\)MyShellCommand.deleteForUser(SettingsService.java:399) at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:281) at android.os.ShellCommand.exec(ShellCommand.java:104) at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:49) at android.os.Binder.shellCommand(Binder.java:881) at android.os.Binder.onTransact(Binder.java:765) at android.os.Binder.execTransactInternal(Binder.java:1021) at android.os.Binder.execTransact(Binder.java:994)'; Code: '255'
原因: 首先是定位到权限问题,刚开始以为是电脑权限有问题了,网上一顿找,也有人报这个错,但是都没有解决方案。最后找了个其他安卓手机试了一下,是正常的,问题就定位到了可能是手机的某个设置问题,应该收手机的某个功能拦截了adb的执行。检查了开发者选项设置,开启开发者选项、USB调试、USB安装都是正常的
解决:各种搜索中,无意间看见“安全调试模式导致小米手机adb shell命令没反应”的帖子。https://jingyan.baidu.com/article/39810a23c7d0a1f737fda627.html。于是打开了 “USB调试(安全设置)",这个功能会允许通过USB调试修改权限或者模拟点击的功能。再次执行脚本正常了。
错误6:selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: A new session could not be created. Details: session not created: This version of ChromeDriver only supports Chrome version 76
Error: A new session could not be created. Details: session not created: This version of ChromeDriver only supports Chrome version 76
原因:运行过程中由于H5内核(微信里是x5内核)支持的ChromeDriver 的Version是66,而当前电脑环境里的ChromeDriver版本是76,两个驱动的版本不一致导致的.
解决:下载Chrome的66版本的Version,跟x5内核版本一致即可,然后按照下图的方式配置路径即可。
错误7:OS真机调试找不到设备:,执行ideviceinstaller -l 等等idevice 系列命令的时候,总之报类似
IERROR: Could not connect to lockdownd, error code -[x],
解决办法:
1. 给/private/var/db/lockdown授读写权限。先 cd /private/var/db 进入db目录(一定要先cd到该目录下,否则无法授权,踩过的坑)
进入目录后执行:sudo chmod -R 777 lockdown/ 命令进行授权
2. 依次执行下面的命令
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
踩坑
brew install --HEAD libimobiledevice
`安装的时候报了下面的错
'configure: error: libplist is not up-to-date; missing plist_string_val_compare() etc. functions - Please update libplist to build libimobiledevice'导致每次安装后,命令都不生效,继续报 'Could not connect to lockdownd, error code -3'
解决:
根据提示,应该是libplist不是最新的,缺少plist_string_val_compare()等 功能,导致不能编译libimobiledevice,所以重新安装libplist,然后再安装libimobiledevice就好了
brew install libplist --HEAD
brew install --HEAD libimobiledevice
错误8:
appium 通过‘adb shell dumpsys window | grep mCurrentFocus’获取到的activity在真机上启动失败,报下面的错,但是在Android模拟器上可以启动成功。
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.xueqiu.android' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command '/Users/qiaoersun/Library/Android/sdk/platform-tools/adb -P 5037 -s 49c08cd4 shell am start -W -n 'com.xueqiu.android/.common.MainActivity t3' -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000' exited with code 255'; Stderr: 'Security exception: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=t3 cmp=com.xueqiu.android/.common.MainActivity } from null (pid=15151, uid=2000) not exported from uid 10489
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=t3 cmp=com.xueqiu.android/.common.MainActivity } from null (pid=15151, uid=2000) not exported from uid 10489
at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1089)
at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:788)
at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:587)
at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1389)
at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:518)
at com.android.server.wm.ActivityTaskManagerService.startActivityAndWait(ActivityTaskManagerService.java:1262)
at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:3568)
at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:513)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:172)
at android.os.ShellCommand.exec(ShellCommand.java:104)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:10061)
at android.os.Binder.shellCommand(Binder.java:881)
at android.os.Binder.onTransact(Binder.java:765)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4663)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2790)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)'; Code: '255'
原因:
因为获取到的activity可能不是最先加载的,通过该命令获取到的并不是launchable-activity,所以启动失败,
解决:
(1) 进入命令行,输入adb logcat | grep START 点击待测应用,就可以获取到启动的activity, 手动是最稳定的方法,推荐。
(2)aapt dump badging apk所在路径,有的app也获取不到launchable-activity