[605]appium操作多台手机及常见问题汇总

如何区分多台手机

  • 每次启动能不不清除缓存,我每次都要重新登陆账号好麻烦?
  • 中文输入为什么是乱码?
  • 如果电脑连接了多台设备,但我只想控制指定一台,怎么区分?
  • swip()方法滑动太慢了,有没有更快速的方法滑动?

针对前三个问题,在desired_caps中增加以下四个配置即可解决,此配置同样适用于Appium桌面版的配置.

desired_caps = {
            "platformName": "Android",
            "platformVersion": "6.0.1",
            "deviceName": "sansan",#
            "appPackage": "com.immomo.momo",
            "appActivity": ".android.activity.WelcomeActivity",
            'unicodeKeyboard': True,  # 使用unicodeKeyboard,即Appiuum自带键盘
            'resetKeyboard': True,  # 重新设置系统键盘为Appium自带键盘
            'noReset': True, # 每次启动不重置APP,即不执行清空APP数据操作
            'udid': 'be7c2d7f'# 区分多台手机
}

另外再详细说一下最后一项配置,即:

'udid': 'be7c2d7f' 

打个比方:

你的电脑上边了连接了三台手机,那么你执行adb devices 会出现三台手机,

那么你的脚本就必须要指定udid 来说明你要控制具体哪一台手机,

如果不指定,也不会同时控制三台,只会默认控制第一台。

udid的value:你输入adb devices 后终端出现的那段字符串如下:

be7c2d7f  devcie
a38f89f9  devcie
c3sji4lw  devcie

直接粘贴就好,要控制哪一台就粘贴哪一条。

针对最后一个问题
Appium自带方法中有一个flick()方法

driver.swipe(495, 1530, 495, 433) # 页面只滑动一下
driver.flick(495, 1530, 495, 433) # 页面作匀减速直线运动

swip()方法:按住坐标(495,1530)手指不松,移动到(495,433),然后松开手指。页面在你手指松开时,就立即静止。类似于你开车到目标点后急刹车…

flick()方法:按住坐标(495,1530)手指慢慢松开,甩到(495,433),页面在你手指离开后,作匀减速直线运动继续滑动。似于你开车到目标点后挂空挡慢慢溜…

appium导致微信聊天记录被清空

用自己的手机测试appium,一启动微信程序后,微信聊天记录全被清除了!

原因:用appium启动微信时,没有设置“不重置应用”,正确做法是增加appium配置"noReset" : True。

清除的记录是找不回来的了,因为已从存储器中删除。

解决方案:

{
  "platformName": "Android",
  "deviceName": "MI_5",
  "appPackage": "com.tencent.mm",
  "appActivity": ".ui.LauncherUI",
  "noReset" : True
}

常见问题汇总

问题1

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up

解决方案:添加:

desired_caps['newCommandTimeout'] =6000

self.driver.implicitly_wait(15)

问题2

Try to increase the 90000ms adb execution timeout represented by ‘adbExecTimeout’ capability

解决方案:添加:desired_caps['adbExecTimeout'] =200000

问题3

error: The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.

解决方案:

需要用命令卸载Appium Settings

adb uninstall io.appium.uiautomator2.server.test

然后在重新执行就可以了。

问题4

Adb connection Error:远程主机强迫关闭了一个现有的连接。Connection attempts: 1

解决方法:原因是DDMS 调用 adb 引发的。经过一番搜索,发现这是 Windows 环境下,adb 的一个限制,也可以说是 bug。当手机上同时运行的进程数大于 64 时, 就会引发 adb 奔溃。更深层次的原因,就是 Windows API 的 WaitForMultipleObjects 所支持的最大句柄数是 MAXIMUM_WAIT_OBJECTS,即 64。需要换一个支持进程数更大的adb,百度网盘下载地址:https://pan.baidu.com/s/1uBXl8h4VTFho3fyUlnai_Q,下载后替换\sdk\platform-tools的三个文件重启appium即可。

问题5

(Original error: Remote install failed: Failure [INSTALL_FAILED_USER_RESTRICTED: Install canceled by user])

解决方法:问题是安装被用户取消,使用adb连接手机,手机需要在开发者选项中打开允许USB安装(具体手机可以百度怎么打开这个选项)

问题6

Original error: Could not extract PIDs from ps output. PIDS: [], Procs: [“ps: uiautomator”]

解决办法:因为appium服务用的是1.4.x版本,使用的是 uiatumator1.0在android7.0得不到支持,所以获取PIDS得到空。找到Appium安装目录下node_modules\appium\node_modules\appium-adb\lib\adb.js文件,修改在var outlines = stdout.split("\n");这行代码下方增加outlines.shift();,注意有分号,然后重启appium即可。

问题7

A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c “E:\Rocheng\ADT-bundle\sdk\platform-tools\adb.exe -s 5b30ee87 shell “ps ‘uiautomator’””) (WARNING: The server did not provide any stacktrace information)

解决办法:参考:https://blog.csdn.net/pjl6523853/article/details/72886048

问题8

Appium连接手机时报权限错误 requires:android.permission.WRITE_SECURE_SETTINGS

我所遇到的问题:

Encountered internal error running command: Error executing adbExec. Original error: ‘Command ‘‘D:\Program Files\Android\android-sdk\platform-tools\adb.exe’ -P 5037 -s 6992c44f install -g ‘C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\io.appium.settings\apks\settings_apk-debug.apk’’ exited with code 1’; Stderr: ‘adb: failed to install C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\io.appium.settings\apks\settings_apk-debug.apk: Failure [INSTALL_FAILED_USER_RESTRICTED: Install canceled by user]’; Code: ‘1’
[W3C] Error: Command '‘D:\Program Files\Android\android-sdk\platform-tools\adb.exe’ -P 5037 -s 6992c44f install -g 'C:\Program

简单理解就是安装不了settings_apk-debug.apk,要开启允许usb安装应用的权限,在开发者那开启

问题9

Appium 进行自动化几分钟后就出现 Could not proxy command to remote server.ADB

目前的解决办法:以华为手机为例,打开设置,找到启动管理(有的在应用和通知中,有的在电池中)把io.appium.uiautomator2.server 和io.appium.uiautomator2.server.test 等与appium相关的程序,自动管理改成手动管理

如果运行一段时间再出现问题,就看一下电池配置,位置在 设置 -> 电池 -> 后台高耗电, 把 appium 相关的app都加上,允许其在后台高耗电时继续运行,然后再运行appium 自动化测试

问题10

问题: 环境使用Python执行appium自动化脚本运行夜神模拟器上的app的时候报错,具体错误信息如下:

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.
Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: The instrumentation process cannot be initialized. Make sure the application under test does not crash and investigate the logcat output.
    at getResponseForW3CError (D:\Program Files\nodejs\node_global\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
    at asyncHandler (D:\Program Files\nodejs\node_global\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:392:37)

原因:因为google服务的问题把夜神模拟器删除了以后重新装了,结果Appium服务运行的核心文件Appium Settings就被之前代码里desired_caps中的这一行"skipServerInstallation": "true"执行后跳过 Appium 服务器的安装,所以没有这个文件脚本运行的时候appium日志就会报错导致脚本运行也报错执行失败。


desired_caps = {
    "deviceName": "127.0.0.1:62001",
    "app": r"D:\Program Files\PycharmProjects\app_pytest_framework\app\xxxx.apk",
    "appPackage": "xxxx",
    "appActivity": "xxxx",
    "platformName": "Android",
    "noSign": "true",
    "noReset": "true",
    "resetKeyboard": "true",
    "unicodeKeyboard": "true",
    "connectHardwareKeyboard": "true",
    "ensureWebviewsHavePages": "true",
    "nativeWebScreenshot": "true",
    "skipDeviceInitialization": "true",
    "skipServerInstallation": "true", #跳过 Appium 服务器的安装,ture为是false为否
    "platformVersion": "7.1.2",
    "newCommandTimeout": 240,
    "automationName": "UiAutomator2"
}
# 打开配置字典中指定的 app
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

解决:废话不多说,直接看解决方案,将true改为false,或者直接将这行代码删除,再次运行脚本就成功解决了!

"skipServerInstallation": "false"

问题11

Appium 启动时报错:Encountered internal error running command: Error: Cannot verify the signature of

Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot verify the signature of ‘/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.21.1.apk’. Original error: Error: A JNI error has occurred, please check your installation and try again
Exception in thread “main” java.lang.UnsupportedClassVersionError: com/android/apksigner/ApkSignerTool has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0

解决:30版本开始build-tools配合jdk1.8会报错,所以需要手动降级到29版本,把bulid-tools里面大于30的版本删掉,即可解决。

参考:https://blog.csdn.net/it1988888/article/details/102265204
https://blog.csdn.net/weixin_28863779/article/details/112507753

问题参考:https://www.jianshu.com/p/adc685d0ce15
https://blog.csdn.net/ouyanggengcheng/article/details/85165553
https://blog.csdn.net/weixin_43845191/article/details/108436848
https://blog.csdn.net/xl_lx/article/details/78717898
https://www.jianshu.com/p/55b1af12c075
https://blog.csdn.net/weixin_43288473/article/details/131565884
https://blog.csdn.net/weixin_45508657/article/details/131531906

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周小董

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值