51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1761|回复: 0
打印 上一主题 下一主题

python-uiautomator2-atx 踩坑记录 (关于 python 与 uiautomator2 版本兼容)

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-4-10 16:20:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
背景

最近组内在推atx+uiautomator2+python的app ui 自动化测试框架,照着组内技术大佬的readme和社区相关帖子搭环境,总是在初始化uiautomator2时报错,报错都来uiautomator2内部方法,折腾了1天,没找到原因(也在社区相关帖提问),最后在大佬协助下发现踩了两个坑,发帖分享一下,避免后面的伙伴一起入坑。


python部分

最开始使用的python3.7,执行

python -m uiautomator2 init

报错 adbutils.Adb().devices 这个模块不存在,点进去看devices这个方法已经被注解了,
把devices的注解去掉,再执行,adbutils.Adb().shell()又报了一个NoneType错误!

adbutils是uiautomator2自带的方法。为什么会返回None? 一层一层追下去....

D:\Python37\Lib\site-packages\adb\command\__init__.py

方法就是返的None,惊不惊喜?意不意外?

python3.7 shell()的源码

def shell(self, cmd, handler=None, timeout=None):
    conn = self.create_connection(timeout=timeout)
    cmd = "shell:{}".format(cmd)
    conn.send(cmd)

python3.7 shell()里调用的create_connection()源码

from adb.connection import Connection

class Command:
    def create_connection(self, *args, **kwargs):
        return None

解决方案:把Python3.7降到python3.5,问题解决,devices()没被注释,shell()引用的
execute()方法也没报错(嗯,换成3.5就不是应用什么create_connection()了)。

python3.5 shell()的相关源码

def shell(self, *args, **kwargs):
    args = ['shell'] + list(args)
    return self.execute(*args, **kwargs)

结论:uiautormator2 目前暂时不兼容python3.7,请用python3.5入坑



uiautomator2部分

刚开始用pip install --pre uiautomator2 安装的是uiautomator2 v0.2.0版本。
还是执行python -m uiautomator2 init 。报的错更离奇,说adbutils里的Adb类不存在,w t f !
这下是真懵了,找大佬把他本地的adbutils.py拷给我Adb类就是正常的。

解决方案:安装uiautormator2时指定0.1.9版本,不会有这个问题。

推测原因:去github上看了下,v0.2.0 把原来adbutils里的Adb类改了(包括名字),
但main.py里Installer类还是继承的adbutils.Adb,估计是作者发版本太匆忙修改有遗漏吧。


总结

相比appium,uiautomator2的维护人数较少,多少存在些鬼畜坑,网上能查阅的资料偏少。
但它体量比appium小,响应速度也比appium快,根据项目自身情况,结合atx后作为app ui
自动化框架也是个不错的选择。目前组内大佬还在试验它对ios是否足够友好?




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-19 18:58 , Processed in 0.059904 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表