【python-appium】Appium的一些坑问题错误解决 与 技巧集锦
问题
1. error: Failed to start an Appium session, err was: Error: Requested a new session but one was in progress
之前的会话没有关闭,然后你又运行了测试实例,也没有设置覆盖.
解决:
1. 重新停止appium服务,开启Appium服务
2. 在Genarel Setting那里设置覆盖Session,重启Appium
测试结束在AfterClass加driver.quit()
2.
error: Failed to start an Appium session, err was: Error: Command
failed: C:\Windows\system32\cmd.exe /s /c
“D:\android-sdk-windows\platform-tools\adb.exe -s adb server version
(32) doesn’t match this client (36); killing…
wait-for-device”
error: could not install smartsocket listener: cannot bind to 127.0.0.1:5037:
没有链接上手机或者模拟器,请确认已经连接成功,重新链接
3.
error: Android devices must be of API level 17 or higher. Please change
your device to Selendroid or upgrade Android on your device.
手机系统低于4.2,appium不支持4.2.2以下的系统,请换一个手机或者模拟器来测试。
4. Error: Permission to start activity denied.
**activity在清单文件里面没添加android:exported=”true”的话,你不能直接打开对应的activity,需要从启动页activity打开。
exported属性就是设置是否允许activity被其它程序调用**
5.
error: Failed to start an Appium session, err was: Error: Activity used
to start app doesn’t exist or cannot ve launched! Make usre it exists
and is launchable activity
要打开的activity不存在,activity路径错误,改为完整正确的activity路径
6.
error: Failed to start an Appium session, err was: Error: ‘java -
version’ failed. Error: Command failed: C:\Windows\system32\cmd.exe /s
/c “java -version”
Java版本错误,请安装最新的版本。
7.>
info: [debug] Error: Command failed: C:\Windows\system32\cmd.exe /s /c
“D:\android-sdk-windows\platform-tools\adb.exe -s 8806a0b0 shell “echo
‘ready‘“error: unknown host service
链接手机失败,重新链接手机即可,我就是重新拔插了一下usb
Error: Command failed: C:\Windows\system32\cmd.exe /s /c
“D:\android-sdk-windows\platform-tools\adb.exe -s 8806a0b0 shell “echo
‘ping’”“
error: unknown host service
adb被突然占用导致,例如你在运行用例的时候运行了模拟器。
7. UIAutomatorViewer提示: Unable to connect to adb. Check if adb is installed correctly
解决,sdk升级到了25产生的问题。
解决方法:
- 将adb.exe 复制一份到uiautomatorviewer.bat 目录下
- 修改uiautomatorviewer.bat文件最后一行(改binddir=%prog_dir%为自己的platform-tools本地路径)

技巧
1. 每次测试都重新安装app
为capabilities色设置noReset为true
capabilities.setCapability(“noReset”, true);
2. 中文乱码
这都是编码问题:
1.方法1:
Android Studio修改文件编码的方法,最底部的UTf-8,点击选GBK就可以了,reload文件。(ps: 先把文件内容全选复制一下再转换编码,再粘贴,不然文件内容就变乱码了)
2.方法2:
用的是原来的UTF-8编码,然后在测试module的build.gradle里面添加三行代码
tasks.withType(JavaCompile){
options.encoding = 'UTF-8'
}
- 1
- 2
- 3
3. 清除编辑框EditText内容
这个问题好像是看手机系统的,我之前的手机就会出现sendKeys的时候没有全选去掉本来的内容,现在都会自动全选覆盖了,这个也不算问题了。
/**
* 逐字删除编辑框中的文字
* @param element 文本框架控件
*/
public void clearText(AndroidElement element){
String className = element.getClass().getSimpleName();
if (className.equals("EditText")){
String text = element.getText();
//跳到最后
driver.pressKeyCode(KEYCODE_MOVE_END);
for (int i = 0; i < text.length(); i ++){
//循环后退删除
driver.pressKeyCode(BACKSPACE);
}
}else {
print("不是文本输入框架,无法删除文字");
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
4. 点击输入法键盘的回车搜索
方法1: 切换输入法
利用adb命令先切换为自己的输入法,按了搜索再切换为appium的输入法
查看当前手机的输入法
cmd执行下面的的代码
adb shell ime list -s
可以看到类似下面的结果,
C:\Users\LITP>adb shell ime list -s
com.baidu.input_mi/.ImeService
com.sohu.inputmethod.sogou.xiaomi/.SogouIME
io.appium.android.ime/.UnicodeIME
C:\Users\LITP>
- 1
- 2
- 3
- 4
- 5
- 6
执行adb命令
先写好一个执行cmd的方法
/**
* 执行adb命令
* @param s 要执行的命令
*/
private void excuteAdbShell(String s) {
Runtime runtime=Runtime.getRuntime();
try{
runtime.exec(s);
}catch(Exception e){
print("执行命令:"+s+"出错");
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
在需要搜索的时候执行下面的代码,切换的输入法用自己查看列表的输入法内容,我这里是搜狗输入法
//使用adb shell 切换输入法-更改为搜狗拼音,这个看你本来用的什么输入法
excuteAdbShell("adb shell ime set com.sohu.inputmethod.sogou.xiaomi/.SogouIME");
//再次点击输入框,调取键盘,软键盘被成功调出
clickView(page.getSearch());
//点击右下角的搜索,即ENTER键
pressKeyCode(AndroidKeyCode.ENTER);
//再次切回 输入法键盘为Appium unicodeKeyboard
excuteAdbShell("adb shell ime set io.appium.android.ime/.UnicodeIME");
转自:http://blog.csdn.net/niubitianping/article/details/52624417
【python-appium】Appium的一些坑问题错误解决 与 技巧集锦的更多相关文章
- [Android测试] Appium的一些坑问题错误解决 与 技巧集锦
转:https://blog.csdn.net/niubitianping/article/details/52624417 1. error: Failed to start an Appium s ...
- RuntimeError: Python is not installed as a framework 错误解决办法
因为我是macbook,mac是自带的python 2.7,但是我开发需要使用到的是python3,所以先使用pip3 install matplotlib 然后在交互页面键入import matpl ...
- 【python】logging日志模块写入中文编码错误解决办法
一.问题: 使用python的logging模块记录日志,有时会遇到中文编码问题错误. 二.解决办法: 在logging.FileHandler(path) 中添加指定编码方式 encoding='u ...
- 关于python安装一些包时出现的错误解决方法
1.关于wordcloud的安装 --win10,py3.6环境下安装总是出现安装错误,解决方法,下载wordcloud的wheel文件,进行安装. 详情参考:https://github.com/a ...
- Python出现"Non-ASCII character '\xe6' in file"错误解决方法
就没有问题,所以我猜测应该是编码的问题,在网上查了下答案,在第一行加上这样一句话: # encoding: utf-8 将编码格式改变为utf-8问题就解决了!
- Python + Robotframework + Appium 之APP自动化测试小试牛刀(Android)
Robotframework如何好?这里先不说了~ Python更不用说了~ Appium前面的文章有介绍~ 今天直接来Python+Robotframework+Appium 三者结合起来,对And ...
- Appium使用Python运行appium测试的实例
Appium使用Python运行appium测试的实例 一. Appium之介绍 https://testerhome.com/topics/8038 详情参考--https://testerhom ...
- 基于Python的Appium环境搭建合集
自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...
- 转载:appium踩过的坑
原文地址:http://blog.csdn.net/wirelessqa/article/details/29188665 自己的操作:由于在window上安装appium时,报各种错误:所以选择在u ...
随机推荐
- 使用Hbuilder手机debug
① 真机连接上数据线. ②选择要调试的页面 ③
- docker for ubuntu 18 安装
官网地址: https://docs.docker.com/install/linux/docker-ce/ubuntu/ docker的作用:解决不同机器之间的环境差异问题,方便迁移. 0. 卸载旧 ...
- Linux nfs使用krb5的方式安全挂载
配置安全的网络nfs文件共享服务 由于本人是使用的rhce模拟考试环境来做的本题目,所以文中说到的实验脚本和评分脚本,以及krb5.keytab文件只有我本套环境独有,如果自己做练习可以不去使用实验脚 ...
- Ubuntu iso下载地址(14、16、18)
Ubuntu镜像,快速下载 ubuntu 14.04: http://mirrors.aliyun.com/ubuntu-releases/14.04/ubuntu 16.04: http://mir ...
- PRD是什么
产品需求文档(Product Requirement Document,PRD)的英文简称.是将商业需求文档(BRD)和市场需求文档(MRD)用更加专业的语言进行描述
- MacbookPro下载word文件显示dms怎么办
方法:直接改扩展名!!!!!!!!!! 如果你下载的是word的话,把最后的扩展名.dms改成.doc就可以了. 同理,如果你下载的是rar的话,改成rar就好了.
- jdk1.7/1.8 HashMap、ConcurrentHashMap详解
摘要: 本文主要参考网上Blog(详见Reference)总结ConcurrentHashMap的各方面知识,方便复习 转自:https://my.oschina.net/hosee/blog/675 ...
- 两个Integer比较
两个Integer类型比较不能使用==,要使用equals, == 在-127~128是可以用的,超出这个范围就不行 public static void main(String[] args) ...
- redhat 7 dns 配置
dns 配置(安装环境是neokylin7.4) #后为需要在root权限下执行的命令 一.安装 修改配置文件1.需要安装的包 bind . bind-chroot .bind-utils #yum ...
- log4j 配置日志输出(log4j.properties)
轉: https://blog.csdn.net/qq_29166327/article/details/80467593 一.入门log4j实例 1.1 下载解压log4j.jar(地址:http: ...