Appium使用过程中遇到的问题

Appium——Error while obtaining UI hierarchy XML file:com.android.ddmlib.SyncException:

使用uiautomatorviewer查看页面元素时报这个错误,解决办法

cmd: adb root

sdk路径path中不能有空格否则appium报错,所以不能放在program files里面

urllib2.URLError:<urlopen error [Errno 10061] >

是因为ie局域网 设置了代理

输入中文:

'unicodeKeyboard':True,

'resetKeyboard':True

要注意的是True不是字符串,不能够加上引号

恢复本来的输入法:设定里面有语言与输入

元素定位

uiautomatorviewer 打开ui测试界面工具→→点击Device Screenshot 按钮获取当前屏幕界面信息

点击右侧上方的黄三角按钮(Toggle NAF Nodes)来查看不能被uiautomator测试工具访问到的控件。

Xpath定位:

content_3=driver.find_element_by_xpath("//android.widget.ListView/android.widget.LinearLayout[3]/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.TextView").text

从元素所在上级定位,不要使用绝对路径,编号从1开始

关于等待时间:

appium运行特别慢,不需要设定等待时间

Adb uninstall ...失败卸载软件:

adb root
adb shell
pm list packages
pm uninstall com.android.chrome

USB设备的识别

C:\Users\intern\.android目录下adb_usb.ini

Stepsfor Windows 7/8:

  1. Go to C:\Users\<user name>\.android
  2. Create a file.
  3. Rename to adb_usb.ini
  4. Paste the following lines:
    # add your vendor IDs, one per line
    0x1949
    0x18D1

内置光盘,计算机管理-设备管理器-其他设备,ADBInterface右键更新程序选择内置光盘的路径

或者从计算机的设备驱动程序列表中选择(sdk 中google usb已经更新)

E:\Tools\485串口驱动\driver\...

也可以手机官网上下载

从本地获取软件

path当软件在电脑上的时候,使用path安装

PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)

对应:desired_caps['app'] = PATH('C:\Users\intern\Desktop\截图\AWS\AirAssistant.apk'

或者 adb install绝对路径地址

横划与竖划

driver.swip(x1,y,x2,y,100) # 横划

driver.swip(x,y1,x,y2,100) # 竖划

driver.swip(x起始,y起始,x截止,y截止,duration)

可以用相同的(x,y,x,y)模拟一次点击

driver.tap也可以达到这个目的

driver.tap(([(x1,y1),(x2,y2)]),(x3,y3)) 用法不是很确定

最后一个参数很重要


电脑连接多个设备

通过设置ANDROID_SERIAL环境变量来指定要点分析的设备

adb devices

Windows: set ANDROID_SERIAL = 

Unix: export ANDROID_SERIAL =

替换命令管道后的过滤条件:adb shell "cat/system/build.prop | grep vm"

闪退原因:

内部逻辑错误:算法,网络,未处理的异常

IndexOutOfBoundsException 索引越界异常

ArrayIndexOutOfBoundsException 数组索引越界异常

RuntimeException: Unable to start activity ComponentInfo 运行时错误:无法启动活动组件信息

Inflate Exception: Binary XML file line 膨胀错误:二进制XML超限

OutOfMemoryError 内存溢出错误

NullPointerException 空指针

WebDriverException: Message: u"A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)"?

程序的'appPackage'和‘appActivity’不正确,反编译app查找里面的appactivity

The connection to adb is down, and a severe error has occured.

方法1.cmd中adb kill-server,然后adb -startserver

方法2.方法1不管用,那么在任务管理器中杀死adb.exe,然后重启Eclipse。

方法3.方法1和2都不管用,那么查看最后一句报错中:platform-tools中是否有adb.exe(我的错误就是在相关路径下面没有platform-tools文件夹

,所以我选择新建一个文件夹,并且把tools中的文件全部复制到platform-tools中)

3.前面的方法试了还是不行的话,建议重新装一个系统,最好换个系统。有些大牛也说过:MS存在一些小问题[size=large][/size]

android adb shell:unknown host serviceadb server is out of datecannot connect to daemon

豌豆荚之类的软件占用了端口,将相关进程杀掉
 

部分手机用Swipe滑动引导图片无效

调整swipe最后一个参数durationdriver.swipe(xStart, yStart, xEnd, yEnd, 100);
 

Appium提示Could not make a String

相关错误解决方法:由于AndroidManifest.xml 损坏引导导致(突然断电可能造成该文件损坏),更换正常的apk文件即可。

http://www.android.gs/download-samsung-usb-drivers-for-android/

或者:

AndroidManifest.xml,在主activity和intent入口处添加:android:exported="true"

Appium启动出现异常,断开/关闭重开,启动监听功能,有时会报错:

解决方法:在任务管理器中找到node.exe*32进程,杀掉后重新启动appium,若进程中无node.exe*32进程,则找到adb.exe*32,杀掉后重启即可。

多台机器的时候

adb -s 序列号 install。。操作

运行时Appium中报错 error: Unhandled error: Error: connect ECONNREFUSED

解决办法:mysql和node.js使用的同一个端口,换一个端口号就行

grep不是内部命令

adb shell "dumpsys meminfo|grep mCurrent"

其中的双引号忘记加了

# coding=utf-8
# author:

from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'emulator-5554'
desired_caps['appPackage'] = 'com.android.calculator2'		 # 应用包名
desired_caps['appActivity'] = '.Calculator'		# 进入应用登录的Activity名称
driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)	#	启动应用

#	定位元素:	uiautomatorviewer  tool获取
driver.find_element_by_name('1').click()
driver.find_element_by_id('com.subject.zhongchou:id/loginnumber_phones').click()
driver.find_element_by_id('com.subject.zhongchou:id/loginnumber_phones').send_keys("18610669397")
driver.quit()
import time
time.sleep(5)		# 强制等待时间
driver.swip(x1,y x2,y)	#	横划
driver.swip(x,y1 x,y2)	#	竖划

path当软件在电脑上的时候,使用path安装
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)
对应:desired_caps['app'] = PATH('C:\Users\intern\Desktop\截图\AWS\AirAssistant.apk') 

猜你喜欢

转载自blog.csdn.net/dubinglin/article/details/65444119